2014-03-05

Blogger integration with Emacs

This blog post is published using my latest hack: Blogger integration in Emacs.

I can write my post in an emacs buffer, using Muse markup. I then run M-x bl/post, type the title and the post will be automatically published.

I will post the source code to it soon. I need to do some more testing first.

However, there are some problems for anyone wanting to use this. For some inexplicable reason, Google has a manual process where you have to apply to be allowed to use their API to Blogger. It applied at least twice, and it took days before I got any response. I'm not the only one, as the Blogger dev group is full of people asking how they get access to the API.

I will post the source on Github shortly.

2014-01-09

A first example of the GNU APL mode for Emacs

For the longest time, I have been interested in learning APL, but there have been a remarkable lack of free APL implementations that works on Linux. So one GNU APL was released recently I got very interested.

APL is a very interesting language, and one of its recognisable features is that it uses non-ASCII characters. In fact, most functions in the language is a single character which tends to make the programs very compact (and some would say, unreadable).

Once I had downloaded and installed GNU APL, I was a bit disappointed to see that there was no Emacs mode for running the APL interpreter. I found this to be a problem, since the special symbols require a special keymap and Emacs would be perfect for managing the input modes.

There were a few projects that never seems to have been finished, so in practice there was nothing available that I could use. So, I did was every self-proclaimed open source fan would do, I started writing my own Emacs mode specifically for GNU APL.

At this point I have gotten far enough that it's possible to show some of the highlights, so I decided to write this post to show a walkthrough how it works.

When first starting the GNU APL mode by typing M-x gnu-apl, the following is displayed:


The message at the bottom indicates that the native module that handles communication between the Emacs mode and the GNU APL interpreter has been started.


Here, we have assigned some variables and display an array. Then, I also moved the cursor to the rho symbol to show how the Eldoc support displays help about the function on the modeline.

There is also integrated support for more detailed documentation. If you move to a symbol and press C-c s, the help window will open.


The documentation that can be seen above are extracts from the IBM APL2 documentation. I have talked to IBM and received the appropriate license to include this text.

Next, let's take a look at function definitions.


When defining a function, a window will automatically open with the current definition, allowing you to edit the function outside of the interpreter itself. This provides a richer experience compared to the default line-based editor.


When editing APL files, you can simply move the cursor to a function and press C-c C-c to define it in the active interpreter.

Sometimes one might want to view and edit large matrixes. The Emacs mode integrates support for SES, the Emacs spreadsheet, shown in the below screenshot:


In order to use it, simply press C-c v, and type the name of the variable that holds the matrix. A separate SES buffer will be created where the content can be edited. There is currently no support for actually sending the data back to the APL interpreter, but that's the next feature that will be implemented.

It will also be possible to save the array as an APL function to a normal source file. The resulting code will be a function definition that when run returns the array data.

2013-11-11

Enabling the Elpa and Marmalade repositories

The default Emacs package repository is not very complete. One almost always want the Elpa and Marmalade repositories as well: This should go very early in the init.el file, so that the remainder of the file can use any packages that has been installed from these repositories.
(require 'package)
(add-to-list 'package-archives '("elpa" . "http://tromey.com/elpa/"))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)

2013-11-06

Getting the directory of the active buffer

Sometimes it's useful to get the current directory of the buffer that you are currently editing. For me, it's usually when I edit a file, and I want to go to that directory in a shell buffer. I solve this problem using the following function:

(defun em-copy-path-of-buffer ()
  (interactive)
  (kill-new default-directory)
  (message "Copied '%s'" default-directory))
By calling this function (either by using M-x em-copy-path-to-buffer or by binding it to a key) the path is copied to the kill ring, and I can paste it using C-y into the shell buffer.

2013-11-04

Improving scrolling in Erc

I use Erc to connect to IRC from Emacs. When looking at output that occasionally updates with a new line, the default behaviour of Emacs to scroll up half a page can be annoying. This can be changed by setting the variable scroll-conservatively to the value 101 or greater. However, I wanted to keep the default behaviour for other buffers, so I added the following to my .emacs.d/init.el:

(defun em-erc-channel-join ()
  (set (make-local-variable 'scroll-conservatively) 101))

(add-hook 'erc-join-hook 'em-erc-channel-join)

This will make sure that the value of this variable is only set for channel buffers.