Archive for April, 2009

I’ve written the third post in the comint series. Database Mode is a more traditional use of comint mode to interact with an external interpreter. Part 1 described basic use of comint with a cut-down shell mode and Part 2 was about a stock price subscriber.

There is a great tip from emacs-fu on using a custom menu to store all the tips you’ve been reading on blogs like my own.

Ben Atkin mentions a couple of things of things that I really like about emacs. First of all, he talks about the ability to see different parts of the same buffer in two frames. I use this all the time when all my constants (or whatever) are at the top of the file. Admittedly, a trick I’ve linked to before with C-x C-x to return to where you were also works nicely in this case.

And the other thing was the scratch buffer. The great thing about emacs is you can easily create another buffer with C-x b and store whatever you like in there.

There is a nice example of Kit OConnell asking the internet for help with an emacs issue. In the end it looks like it was solved in the real world by someone spotting some "smart quotes" in the .emacs. Perhaps emacs should warn about that at start-up.

There have been a few posts on whitespace recently. Matt Harrison mentions a whitespace mode that can be useful for the pythonistas that have the most trouble with inconsistent whitespace. RĂ©mi Vanicat isn’t the first person to talk about removing trailing whitespace (I linked to an even better solution in an earlier link roundup). It is nice that emacs has such a nice way of dealing with it.


Read Full Post »

As most emacsers probably know, emacs 23 allows you to use anti-aliased fonts, in effect making emacs beautiful and even more of a pleasure and a joy to use. Dagobart recently wrote a post, explaining how to set this up on Linux.

I’ve seen a few posts like this before, ever since version 23 was in alpha so I thought it would be a good opportunity to do a quick roundup.

Way back at the start of 2007, Alexandre Vassalotti packaged up an early version of emacs23. Later on he updated it.

Oscar Bonilla wrote posts on how to prettify emacs for OS X and later on for Windows. The rather excellent EmacsW32 package is now based on a build of Emacs 23.

Dagobart’s post references these Linux setup instructions at sevenever.

And I should note that if you are a fan of muse + htmlize then you need the patched version of htmlize as vanilla 1.34 does not work with emacs 23.

Read Full Post »

I briefly mentioned dabbrev expand in one of my interesting links posts when I noted a post that was covering auto-complete.el. Dabbrev expand is a great little feature of emacs. With one keychord, you can expand text using any match from any buffer that you have opened. Until now, I haven’t particularly wanted more.

However, now it is time to move to auto-complete. It’s nice to get feedback about potential completions. In the linked post, it states that auto-complete is just a framework and it needs quite a bit of tweaking to get the behaviour I want.

The primary thing I want to fix is that by default it only uses completions from the current buffer. I like completion to use all open buffers as dabbrev does by default. I thought that it would be easy to add this by setting ac-sources to ac-source-words-in-all-buffer.

(setq-default ac-sources '(ac-source-words-in-all-buffer))

Unfortunately, that isn’t come close to what I want. There is also an extension called ac-dabbrev.el but that doesn’t work for me either. Fortunately, it is fairly easy to fix myself.

We can use functions from dabbrev to get all of the possible dabbrev expansions.

(require 'cl)
(require 'dabbrev)
(require 'auto-complete)

(defun ac-source-dabbrev (abbrev)
  (let ((dabbrev-check-all-buffers t))
    (sort (dabbrev--find-all-expansions abbrev t) #'string<)))

auto-complete allows you to list multiple sources for completions in ac-sources. Here we just want one but I could see that it might be nice to add language keywords or something like that.

(defvar ac-source-dabbrev-words
     . (lambda () (all-completions ac-target
                                   (ac-source-dabbrev ac-target)))))
  "Get all the completions using dabbrev")

(setq-default ac-sources '(ac-source-dabbrev-words))

I prefer to manually start completion rather than have it trigger automatically.

(setq ac-auto-start nil)
(global-set-key (kbd "M-/") 'ac-start)

There is a keymap you can add your own keys to. By default, C-g doesn’t cancel the completion window which feels really strange to me. In emacs C-g is pervasive for cancelling options. Fortunately, it is pretty easy to fix that.

(define-key ac-complete-mode-map (kbd "M-x") 'execute-extended-command)
(define-key ac-complete-mode-map (kbd "C-n") 'ac-next)
(define-key ac-complete-mode-map (kbd "C-p") 'ac-previous)
(define-key ac-complete-mode-map (kbd "C-g") 'ac-stop)

I like both RETURN and TAB for completion.

(define-key ac-complete-mode-map "\t" 'ac-complete)
(define-key ac-complete-mode-map "\r" 'ac-complete)

I want completions to update as you type. Did you know that by adding a vector to a keymap, you can capture all ascii keypresses?

(defun ac-self-insert ()
  (self-insert-command 1)

;; (define-key ac-complete-mode-map [t] 'ac-self-insert)

However, [t] also absorbs other ASCII keypresses you’ve defined such as TAB and RETURN. Therefore, we have to define them all individually.

(defun ac-fix-keymap ()
  (let ((i 32))
    (while (<= i ?z)
      (define-key ac-complete-mode-map
        (make-string 1 i) 'ac-self-insert)
      (incf i))))


I also want DELETE to trigger a new completion update.

(define-key ac-complete-mode-map (kbd "DEL")
  (lambda ()
    (backward-delete-char-untabify 1)

(provide 'auto-complete-config)

Read Full Post »

I’ve finally published the next installment of my mini-series on Emacs Comint. I’ve decided to publish it as a Squidoo lens. In it, I demonstrate how to create a slick, emacs-based interface to a stock price publisher. Part 1 in the series can be found here.

The first version extracts the ticker and price and displays them nicely in a seperate buffer. The later version highlights the updated line by flashing a magenta background for half a second after any update.

The lens covers the following emacs features: comint, process filters, overlays and timers. Let me know any comments or suggestions you have either here or on the lens itself. Please visit my emacs comint lens.

Read Full Post »


One reason, why I blog about emacs is that I’m often learning new things from people who leave a comment on my blog. My latest cool toy, thanks to a mention from foo is ibuffer. I had heard of it already (and had a vague idea of what it does), but had not investigated it any depth.

So, what does ibuffer do and why is it cool? It is a powerful substitute for list-buffers which by default is bound to C-x C-b. You can get started by typing M-x ibuffer <RETURN> h (for help).

The main features provided are:

  • sorting (with a s prefix)
  • filtering (with a / prefix)
  • marking (with * or % prefixes) and
  • processing (which covers a multitude of sins)

I like to sort the buffers lexicographically before I begin with s a. If it turns out I always do this, I’ll customize ibuffer-default-sorting-mode.

I’ve come up with a few simple recipes so far:

  • * s (mark star buffers) D (delete all marked buffers)
  • * r k (remove read-only buffers from ibuffer)
  • % n (mark buffers by regex) U (regex replace)

One thing that ibuffer doesn’t have is a function that compares two marked buffers. However, its easy enough to add one.

(defun ibuffer-ediff-marked-buffers ()
  (let* ((marked-buffers (ibuffer-get-marked-buffers))
         (len (length marked-buffers)))
    (unless (= 2 len)
      (error (format "%s buffer%s been marked (needs to be 2)"
                     len (if (= len 1) " has" "s have"))))
    (ediff-buffers (car marked-buffers) (cadr marked-buffers))))

(define-key ibuffer-mode-map "e" 'ibuffer-ediff-marked-buffers)

We might as well replace the default binding for C-x C-b.

(global-set-key (kbd "C-x C-b") 'ibuffer)

Read Full Post »

« Newer Posts