Differences between revisions 6 and 20 (spanning 14 versions)
Revision 6 as of 2007-01-13 03:53:27
Size: 1123
Editor: nickcheng
Comment:
Revision 20 as of 2010-01-11 17:55:01
Size: 6273
Editor: flyinflash
Comment:
Deletions are marked like this. Additions are marked like this.
Line 8: Line 8:
::-- ["nickcheng"] [[[DateTime(2007-01-13T03:30:15Z)]]]
[[TableOfContents]]
::-- [[nickcheng]] [<<DateTime(2007-01-13T03:30:15Z)>>]
<<TableOfContents>>
Line 12: Line 12:
 * 据目前的了解, Emacs的主力都在应对Emacs22的最后的bug, 也许是RMS想现Release Emacs22, 然后再把主力放入Emacs23的开发. -- ["nickcheng"] [[[DateTime(2007-01-13T03:40:42Z)]]]  * 据目前的了解, Emacs的主力都在应对Emacs22的最后的bug, 也许是RMS想现Release Emacs22, 然后再把主力放入Emacs23的开发. -- [[nickcheng]] [<<DateTime(2007-01-13T03:40:42Z)>>]
Line 17: Line 17:
   * 这下面有编译好的22, 23版本的exe文件, 还有打包的源代码. -- ["nickcheng"]    * 这下面有编译好的22, 23版本的exe文件, 还有打包的源代码. -- [[nickcheng]]
Line 19: Line 19:
 * 期待您的添加  * Ubuntu 8.04
   * 在Application->Add/Remove...里搜索emacs, 直接安装Emacs Snapshot (GTK)。 此外还有Emacs22(GTK), Emacs22(X)多个版本。
Line 28: Line 29:

=== 用于Python开发的配置 ===
'' 在啄木鸟, 当然要说Python相关的话题了! ''
Line 33: Line 37:

=== 如何方便的加载配置 ===

一般的配置都是写在.emacs中的, 不过时间一长,emacs文件就会变得冗长, 可读性和可维护性很差.为了解决这个问题, 就有了下面的程序
{{{
(mapc '(lambda (file)
         (load (file-name-sans-extension file)))
      (directory-files "~/emacs.d/init.d/" t "\\.el$"))
}}}
这三行语句的作用就是加载指定目录中的所有扩展名为el的文件. 文中的目录我是放在了HOME(~/)下的"emacs.d/init.d". 所有配置就可以按照不同的功用, 拆成不同的.el文件,分别放于“emacs.d/init.d”下。

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



=== 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)
)
}}}

 * 配置完毕后, 可以在python模式下使用快捷键来操作Folding. 快捷键的使用可以参考: http://www.woodpecker.org.cn:9081/graspOnline/learn.tsinghua.edu.cn/homepage/2001315450/emacs_outline.html
  * 注意把文章中的C-o换成上面配置中的C-c
 * 方便起见, 列几个常用的快捷键:
||'''功能'''||'''快捷键'''||
||折叠所有(hide-sublevels)||C-c C-q||
||展开所有(show-all)||C-c C-a||
||折叠当前(hide-entry)||C-c C-c||
||展开当前(show-entry)||C-c C-e||

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

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

主要功能有:

 1. 在 tab 上按中键会关闭 buffer,按右键则弹出切换菜单,可以在当前 tabgroup 或其它 tabgroup 中切换。
 1. 加入移动 tab 功能。在原先 scroll 按钮的基础上加入鼠标中键和右键的处理,例如,在 ">" 上按右键,会将 tab 右移,按中键则移到最右处。
 1. 增加快捷键来切换 buffer。定义了 0~9, a~z 这些快捷键来快速地切换 buffer。
 1. 增加 M-x tabbar-goto-group,配合自动完成来快速切换到某 tab group。

==== 安装 ====
 * 下载tabbar.el: [[attachment:tabbar.el]]
 * 将文件放入Emacs可以加载的目录中. 我放在Emacs/site-lisp目录下

==== 配置 ====
在.emacs文件中增加如下代码:
{{{
(require 'tabbar)
(setq tabbar-speedkey-use t)
(setq tabbar-speedkey-prefix (kbd "<f1>"))
(tabbar-mode 1)
}}}
这里对应的上面的功能3中的快捷键为"F1"

=== Snippets like TextMate ===

= 交流反馈 =

修改 -- -- [[flyinflash]] [<<Date(2010-01-11T17:55:01Z)>>]

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

== 讨论 ==

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

::-- 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文件就会变得冗长, 可读性和可维护性很差.为了解决这个问题, 就有了下面的程序

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

这三行语句的作用就是加载指定目录中的所有扩展名为el的文件. 文中的目录我是放在了HOME(~/)下的"emacs.d/init.d". 所有配置就可以按照不同的功用, 拆成不同的.el文件,分别放于“emacs.d/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. 交流反馈

修改 -- -- flyinflash [2010-01-11]

2.1. 常见问题

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

2.2. 讨论

Emacs23 (last edited 2010-01-11 17:55:01 by flyinflash)