Tuesday, 29 July 2008

Emacs org-mode bindings

As I have continued to play with org-mode for emacs, I cannot seem to get over the rebinding of meta-right, meta-left, and so forth. As such I remap them to super-right, super-left and so on. Changing the "s" right after concat to an "H" should remap to use the hyper key. No word on coke bottle bindings yet.

(add-hook 'org-mode-hook
	  '(lambda nil
	     (if (lookup-key (current-local-map) (kbd "M-<down>"))
		 (let ((annoying-bindings '("M-S-<down>" "M-S-<left>" "M-S-<return>" "M-S-<right>" "M-S-<up>" "M-<down>" "M-<left>" "M-<return>" "M-<right>" "M-<tab>" "M-<up>")))
		   (mapc (lambda (binding)
			   (let* ((original-binding (eval `(kbd ,binding)))
				  (new-binding (eval `(kbd ,(concat "s" (substring binding 1)))))
				  (bound-function (lookup-key (current-local-map) original-binding)))
			     (message (format "rebinding %s to %s for %s" original-binding new-binding bound-function))
			     (local-unset-key original-binding)
			     (local-set-key new-binding bound-function)
			     ))
			 annoying-bindings)
	       
		   (message "setting other keys")
		   (local-set-key  (kbd "s-o")
				   '(lambda ()
				      (interactive)
				      (org-open-at-point)
				      (delete-other-windows)))
		   (local-set-key (kbd "s-t") 'org-todo-list)))))
Posted by james at 7:23 PM in emacs

Monday, 21 July 2008

org-mode for emacs

Recently while news grazing, I happened across org-mode for emacs by way of a google tech talk. It is a mode for planning, keeping todo lists, and project planning. It is really nice.

Posted by james at 10:48 PM in emacs

Tuesday, 27 March 2007

Emacs-magic-mode-alist

I learned about a new feature in emacs today by hunting down a behavior that has been annoying me since upgrading to version 23.0.0.1. My problem was that emacs insisted on putting my .xml files in the default xml-mode rather than my greatly preferred nxml-mode (which supports RELAXNG).

It turns out there is a new additional mechanism of setting the buffer type based on the buffers content rather than the filename. This feature is accessed via the magic-mode-alist variable (cf. auto-mode-alist). Thus to override the default behavior one needs to remove xml-mode from two alists:


;; override emacs defaults
(defun remove-unwanted-alist-entry (unwanted-mode an-alist) 
  (delete-if
   (lambda (x)
     (and (listp x) (equalp (cdr x) unwanted-mode)))
   an-alist))

(remove-unwanted-alist-entry 'xml-mode auto-mode-alist)
(if (boundp 'magic-mode-alist)
    (let () 
      (remove-unwanted-alist-entry 'xml-mode magic-mode-alist)
      (remove-unwanted-alist-entry 'html-mode magic-mode-alist)))

After which loading nxml-mode behaves as expected.

Posted by james at 3:27 PM in emacs

Wednesday, 14 February 2007

Templates for emacs

After having typed in the skeleton for an xslt transformation far too many times, I wrote a bit of elisp to allow templates in emacs.
(add-hook
 'find-file-not-found-hooks
 '(lambda ()
    (let ((template-file-name
	   (concat "~/.emacs.d/templates/template."
		   (file-name-extension (buffer-name)))))
      (if (file-exists-p template-file-name)
	  (let ()
	    (insert-file template-file-name)
	    (set-buffer-modified-p nil))))))

If you select a file which does not (yet) exist, this causes emacs to look in ~/.emacs.d/templates/ for a template with the same ending (and automatically populates the new file with the template). For example,
$ cat ~/.emacs.d/template.html
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<h1></h1>
<hr/>
<address></address>
<!-- hhmts start -->
<!-- hhmts end -->
</body> </html>
$ 
Posted by james at 4:04 PM in emacs
« January »
SunMonTueWedThuFriSat
    123
45678910
11121314151617
18192021222324
25262728293031