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.