含有章节索引的中文 文章模板

::-- nickcheng [2007-01-13 03:30:15]

1. Emacs23 (Unicode branch)

Emacs23是Emacs在CVS中的一个分支: emacs-unicode-2 branch, 这个分支的内部编码改为了Unicode. 这样一来, 在Emacs21和Emacs22中困扰咱们的中文问题就直接迎刃而解了! 再也不用配置那么一大堆CJK的东东了!

  • 据目前的了解, Emacs的主力都在应对Emacs22的最后的bug, 也许是RMS想现Release Emacs22, 然后再把主力放入Emacs23的开发. -- nickcheng [2007-01-13 03:40:42]

1.1. 下载

1.1.1. Win32平台

1.1.2. Linux平台

  • Ubuntu 8.04
    • 在Application->Add/Remove...里搜索emacs, 直接安装Emacs Snapshot (GTK)。 此外还有Emacs22(GTK), Emacs22(X)多个版本。

1.1.3. 其他平台

1.1.3.1. MacOS

  • 期待您的添加

1.1.3.2. Any others?

  • 期待您的添加

1.2. 配置

1.2.1. 用于Python开发的配置

在啄木鸟, 当然要说Python相关的话题了!

  • 期待您的添加

1.3. 技巧

1.3.1. .emacs文件的位置

1.3.2. 如何方便的加载配置

一般的配置都是写在.emacs文件中的, 不过随着自己的Emacs配置的越来越强大, 这个.emacs文件不仅也随之变得冗长起来, 而且可读性和可维护性都差了好多.

于是乎, 为了解决这个问题, 就有了下面的程序

(mapc '(lambda (file)
         (load (file-name-sans-extension file)))
      (directory-files "~/init.d/" t "\\.el$"))

目前我的.emacs文件中就只有这么三行语句. 这三行语句的作用就是加载指定目录中的所有扩展名为el的文件. 文中的目录我是放在了HOME(~/)下的"init.d". 这样一来, 我的所有配置就可以按照不同的功用, 拆成不同的.el文件, 然后一股脑的放进"init.d"目录下. 而且以后维护起来也方便的很呢! 方便的不是一点半点哦!

需要注意的一点是, 默认是按照文件名的字母顺序来加载.el文件的, 所以如果你的.el文件之间有依赖的话, 就需要在文件名前缀数字来避免加载的失败:)

1.3.3. Folding

参考: http://groups.google.ca/group/comp.lang.python/browse_thread/thread/43a4d75404cc64fe/956f1c2d37f93995?&hl=en#956f1c2d37f93995

python-mode不带folding功能. 我们只能使用Emacs内建的outline-minor-mode, 来为python设置不同的outline-regexp和outline-level. 参考下面的代码:

;; setup python mode
(setq auto-mode-alist ; trigger python mode automatically
      (cons '("\\.py$" . python-mode) auto-mode-alist))
(setq interpreter-mode-alist
      (cons '("python" . python-mode)
            interpreter-mode-alist))
(autoload 'python-mode "python-mode" "Python editing mode." t)
; add my customization
(add-hook 'python-mode-hook 'my-python-hook)
; this gets called by outline to deteremine the level. Just use the length of the whitespace
(defun py-outline-level ()
  (let (buffer-invisibility-spec)
    (save-excursion
      (skip-chars-forward "\t ")
      (current-column))))
; this get called after python mode is enabled
(defun my-python-hook ()
  ; outline uses this regexp to find headers. I match lines with no indent and indented "class"
  ; and "def" lines.
  (setq outline-regexp "[^ \t]\\|[ \t]*\\(def\\|class\\) ")
  ; enable our level computation
  (setq outline-level 'py-outline-level)
  ; do not use their \C-c@ prefix, too hard to type. Note this overides some python mode bindings
  (setq outline-minor-mode-prefix "\C-c")
  ; turn on outline mode
  (outline-minor-mode t)
  ; initially hide all but the headers
  (hide-body)
  ; I use CUA mode on the PC so I rebind these to make the more accessible
  (local-set-key [?\C-\t] 'py-shift-region-right)
  (local-set-key [?\C-\S-\t] 'py-shift-region-left)
  ; make paren matches visible
  (show-paren-mode 1)
) 

功能

快捷键

折叠所有(hide-sublevels)

C-c C-q

展开所有(show-all)

C-c C-a

折叠当前(hide-entry)

C-c C-c

展开当前(show-entry)

C-c C-e

1.3.4. Tab Bar

在smth.org的Emacs版上看到zslevin (Levin Du)发表的他改的比较顺手的Tabbar, 自己试了以下, 感觉还不错.

原地址: http://www.newsmth.net/bbstcon.php?board=Emacs&gid=49730

主要功能有:

  1. 在 tab 上按中键会关闭 buffer,按右键则弹出切换菜单,可以在当前 tabgroup 或其它 tabgroup 中切换。
  2. 加入移动 tab 功能。在原先 scroll 按钮的基础上加入鼠标中键和右键的处理,例如,在 ">" 上按右键,会将 tab 右移,按中键则移到最右处。

  3. 增加快捷键来切换 buffer。定义了 0~9, a~z 这些快捷键来快速地切换 buffer。
  4. 增加 M-x tabbar-goto-group,配合自动完成来快速切换到某 tab group。

1.3.4.1. 安装

  • 下载tabbar.el: tabbar.el

  • 将文件放入Emacs可以加载的目录中. 我放在Emacs/site-lisp目录下

1.3.4.2. 配置

在.emacs文件中增加如下代码:

(require 'tabbar)
(setq tabbar-speedkey-use t)
(setq tabbar-speedkey-prefix (kbd "<f1>"))
(tabbar-mode 1)

这里对应的上面的功能3中的快捷键为"F1"

1.3.5. Snippets like TextMate

2. 交流反馈

2.1. 常见问题

  • 初学者看完Emacs的帮助文档后该怎么继续学?感觉就是知道了几个热键,可其他很多东西: 都不知道,不知是否还有什么教程或者学习方法?大家能否提点建议,谢谢!
    • 建议学会查找帮助的方式,比如命令补全,C-h i , C-h k, C-h f, C-h a, C-h v 和 M-x apropos 之类的,然后就可以慢慢开始用了,有不知道的地方在使用的时候再去查帮助,否则看文档记住了不用的东西过一段时间还是会忘记的。

2.2. 讨论