Emacs daemon

CVS Emacs增加了一个新的选项--daemon,使得emacs可以作为一个daemon启动而没有任何界面。使用的方式是emacsclient -c打开一个图形化的frame,或者emacsclient -t在终端内打开一个frame。退出当前frame使用C-x 5 0

用这种方式启动Emacs,就像使用Music Player Daemon一样,可以放心大胆地重新启动X Window,而不会受到任何影响。根据我个人的使用经验,Emacs daemon并没有load用户的.emacs文件,为了避免每次手工load,我写了一个bash脚本:

#!/bin/bash

emacs --daemon
sleep 30
emacsclient -c --no-wait -e '(load-file "~/.emacs")'

有一点需要注意的是,在自己编译之前一定要按照David Smith的patch做一点修改,否则会有segfault。

hippie-expand

直到前两天才通过Most useful Emacs features – Stack Overflow知道hippie-expand这么好用的东西,然后抄了一段Alex Schroeder的配置,也就是根据可能性重新排列一下补全的规则,如将补全文件名放到链表的后面。另外还从wiki页上抄了一段用tag做补全的配置。

虽然补全文件或路径很少用到,但是在添加load-path的时候就很方便了,感觉就像在mini-buffer里输入路径一样。当然用得最多的还是在写程序的时候了。下面是我的配置:

(global-set-key (kbd "M-/") 'hippie-expand)

(defun he-tag-beg ()
  (let ((p
         (save-excursion
           (backward-word 1)
           (point))))
    p))

(defun try-expand-tag (old)
  (unless  old
    (he-init-string (he-tag-beg) (point))
    (setq he-expand-list (sort
                          (all-completions he-search-string 'tags-complete-tag) 'string-lessp)))
  (while (and he-expand-list
              (he-string-member (car he-expand-list) he-tried-table))
              (setq he-expand-list (cdr he-expand-list)))
  (if (null he-expand-list)
      (progn
        (when old (he-reset-string))
        ())
    (he-substitute-string (car he-expand-list))
    (setq he-expand-list (cdr he-expand-list))
    t))

(setq hippie-expand-try-functions-list
      '(try-expand-all-abbrevs try-expand-dabbrev
 try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill
 try-complete-lisp-symbol-partially try-complete-lisp-symbol
 try-complete-file-name-partially try-complete-file-name try-expand-tag))