documents :: blog :: news

Mon March 21, 2005 • 00:36computers

.emacs tips (date and buffers)

Those of you who live in GNU Emacs might be interested by these two tips. Those who don't understand what I'm talking about can happily skip this news, as it will hardly make any sense to them. What I describe here is not advanced or special, it is simply very convenient.

First, have you ever wanted to quickly insert a date, in a custom format? Well that's what format-time-string is for, and coupled with a custom format string (see function reference for the syntax) and a shortcut, it lets you print the current date the way you want it:

(defvar tl_std-format-string "%Y-%m-%-dT%H:%M:%S%z") ; 2005-03-21T00:36:29+0100 (defun insert-standard-date () "Insert the date and time into the current buffer at the current location. See the documentation for tl_dts-format-string to change the format of the date-time stamp." (interactive) (insert (format-time-string tl_std-format-string (current-time)))) (global-set-key "\C-c\C-s" 'insert-standard-date)

Second, what is your favorite way to switch between buffers? C-x b ENTER to switch to the previous buffer maybe? And C-x C-b to list the buffer? Well although it did the job for me for the past few years, I have found very convenient to map two emacs functions (electric-buffer-list and bury-buffer) to two easily accessible shortcuts (C-$ and C-ENTER). The first displays a focused version of the buffer list, that you can hide by pressing ENTER or which you can use to choose the buffer you want to switch to. The second simply lets you loop between your buffers. Try them (append to your ~/.emacs, or C-x C-e them in a GNU Emacs buffer to evaluate their code):

(global-set-key [(control $)] 'electric-buffer-list) (global-set-key [(control return)] 'bury-buffer)

That's all for now. More elisp fun when I will get round to actually diving in the documentation more deeply.


Valid XHTML 1.0!
Valid CSS2!
Document under Attribution-ShareAlike 2.0 License