一月 21, 2009

EasyPG

EasyPG把用gnupg加密解密的过程集成的Emacs里面,CVS版Emacs自带EasyPG,如果是Emacs 22的话,要自己到http://www.easypg.org/下载。

使用EasyPG很简单,只需在.emacs里添加如下语句:

(require 'epa)

如果是单独下载的EasyPG,还需要添加一条:

(require 'epa-setup)

这条语句的主要目的就是调用(epa-file-enable)使得Emacs遇到后缀名为gpg的文件会自动解密。

如果希望使用minibuffer输入passphrase,而不是弹出对话框的话,可以将环境变量GPG_AGENT_INFO清空。

(setenv "GPG_AGENT_INFO" nil)

然后我们就可以在Emacs里面直接使用加密文件了,比如使用加密过的bbdb文件数据库:

(require 'bbdb)
(setq bbdb-file "~/bbdb.gpg")

参考文章:

一月 19, 2009

Customization tips for emacs daemon

使用Emacs daemon使得配置变得更加复杂了,因为在启动daemon的时候,没有任何X Frame生成,某些对X Frame的定制代码可能出错,比如:

(setq x-select-enable-clipboard t)

这段代码一定要在X Frame生成之后运行,解决方法是把定制添加到after-make-frame-functions这个hook里面。

(add-hook 'after-make-frame-functions
          (lambda (frame)
            (with-selected-frame frame
              (when window-system
                (scroll-bar-mode -1)
                (setq x-select-enable-clipboard t)))))

一月 13, 2009

eval-after-load

当我使用wl-install-elisp-from-emacswiki更新anythinganything-config之后,发现我对它们做的定制不见了。

解决方法是使用eval-after-load,在每次加载一个文件的时候运行一段代码,如下:

(eval-after-load 'anything
  '(progn
     (setq anything-enable-digit-shortcuts t)
     (global-set-key (kbd "<f9>") 'anything)))

(eval-after-load 'anything-config
  '(add-to-list 'anything-sources anything-c-source-file-cache))

注意,第二个参数是个list,一定要quote,不然他们会立刻执行。

一月 09, 2009

Find elisp function definition

使用find-func,可以快速定位emacs lisp函数定义,配置如下:

(require 'find-func)
(find-function-setup-keys)

快捷键如下:

(defun find-function-setup-keys ()
  "Define some key bindings for the find-function family of functions."
  (define-key ctl-x-map "F" 'find-function)
  (define-key ctl-x-4-map "F" 'find-function-other-window)
  (define-key ctl-x-5-map "F" 'find-function-other-frame)
  (define-key ctl-x-map "K" 'find-function-on-key)
  (define-key ctl-x-map "V" 'find-variable)
  (define-key ctl-x-4-map "V" 'find-variable-other-window)
  (define-key ctl-x-5-map "V" 'find-variable-other-frame))

以前都是傻傻地使用C-h f,然后把光标移到*Help* buffer里面的相应链接上,最后按回车。有了find-func,无需移动光标了。摘一段注释

The funniest thing about this is that I can't imagine why a package so obviously useful as this hasn't been written before!!

一月 06, 2009

Install elisp from emacswiki in batch

EmacsWiki上有好多强大的工具可以下载,甚至有一个专门的工具用于下载elisp,这就是install-elisp.el。如果你还没有下载过,那么需要手工下载、编译、安装和加载,之后就可以利用它的强大功能完成自动化操作。具体配置参见该文件里面的注释。

如果你像我一样,曾经安装过多个elisp工具,那么批量更新就是个问题,又或者有了一台新机器,重新安装一遍也很麻烦。为了解决这个问题,我写了一段小程序,如下:

(defvar wl-emacswiki-utilities-list '(htmlize anything anything-config install-elisp browse-kill-ring))

(defun wl-install-elisp-from-emacswiki ()
  (interactive)
  (let ((install-elisp-confirm-flag nil))
    (dolist (m wl-emacswiki-utilities-list)
      (install-elisp-from-emacswiki (concat (symbol-name m) ".el")))
    (install-elisp "http://www.davep.org/emacs/boxquote.el")
    (install-elisp "http://code.jblevins.org/markdown-mode/markdown-mode.el")
    (install-elisp "http://mumble.net/~campbell/emacs/paredit.el")
    (install-elisp "http://homepage1.nifty.com/bmonkey/emacs/elisp/cldoc.el")))

当然,你也可以把列表直接写在dolist里面,那样更新列表更方便些。在批处理过程中不希望用户使用C-c C-c逐个确认,所以暂时把install-elisp-confirm-flag设为nil

一月 01, 2009

2009 new year resolution

2009年的主题是在线写作。

2009年的责任是当爸爸啦!

2009年,详细记录自己的发展,年终总结时使用几个图表,而不再是苍白的文字。

Incomplete summary for my 2008

2008发生了很多意想不到的事,所谓计划没有变化快。投资就不用说了,金融风暴之下,安有完卵。工作条件也受其影响,出现了严重的质量下降。值得庆幸的是,没有偏离年初制定的主题——Getting Things Done。

2008年有许多全新的体验:学了git,买了blackberry 8320,用上了双显示器,并且开始严肃地备份自己的数据。对于熟悉的工具,如GNU Emacs和Perl,也有长足的进步。工作上,几名共事多年的同事离职,而且随着金融环境的恶劣,出现了不少紧缩的迹象。

在2008年,大多数时间都在使用linux。随着使用Windows的时间越来越少,逐渐淡忘了使用MS软件的种种不爽之处。归于平静之后,便不再有对MS的出离愤怒,也不再过度推销linux。

这一年最大的收获就是——老婆怀孕啦!