lundi 3 mai 2010

emacs zz

November 30
Emacs FAQ
* General

1. 怎样才能语法加亮
2. 在Windows版的Emacs下怎样使用ispell?
3. Windows版的Emacs为什么不能显示图片?
4. 设置打开文件的缺省路径
5. `.emacs' 在哪里?
6. 下载的el文件怎么用?
7. 怎么进行矩形区域操作?(类似UltraEdit的列模式) 怎么在每一行前插入相同文字?
8. 总有个带小尾巴~的文件出现(自动备份文件),怎么办?
9. 我想把一个命令绑定到某个按键组合上,怎么表示组合键?
10. 怎么转换文件格式?(DOS <--> UNIX)
11. 查找和替换的时候怎么输入回车之类的特殊字符?
12. M-x shell进入shell-mode出现乱码?怎么修改颜色和字体?
13. windows下插入、浏览图片时emacs崩溃
14. 如何跳到某一行?
15. 如何插入当前时间?
16. 修改 .emacs 后即时生效(不重启)?

* Chinese Related

1. Emacs与其他程序间为什么不能拷贝、粘贴
2. Emacs中新开buffer不使用默认字体怎么办
3. XEmacs怎样保存中文
4. 怎样使Emacs支持GBK

* TeX

1. Windows下不能使用LaTeX-preview
2. Emacs能象vimsuite那样加载类似CJK的模板么?

* Programming

1. 怎样把C/C++文件重新排版
2. 语法加亮
3. c/c++, java 自动补全功能?

* Gnus, Mail, Web

1. mew怎样使用SMTP验证?
2. 怎样使mew在pop取信时将信件保留在服务器上?
3. gnus怎样使用通讯录?

* Resources

1. 推荐Emacs入门书籍
2. 推荐Emacs Lisp入门书籍
3. 下载最新版本的GNU Emacs
4. ftp. tsinghua. edu. cn的Emacs专区
5. Emacs资源哪里最多?
6. 一个收集大量Emacs配置文件的网站

推荐下载FTP: ftp://ftp.tsinghua.edu.cn/Software/Editor/Emacs/
精华区下载 : ftp://ftp.smth.org/smth/announce

------------------------------------------------------------------------------
-

In details:

* General
=========

1.怎样才能语法加亮
将以下写到.emacs文件:(global-font-lock-mode t)

2.在Windows版的Emacs下怎样使用ispell?
Win32有一个native的ispell v4,但很不好用,建议装一个cygwin的ispell-3.2.06

3.Windows版的Emacs为什么不能显示图片?
使用cvs版的ntemacs,在.emacs中加入:(auto-image-file-mode t)

4.设置打开文件的缺省路径
(setq default-directory "~")

5.`.emacs' 在哪里?
Unix/Linux:

~/.emacs 如果没有,自己创建一个。`touch .emacs'.

Windows:

在根目录下创建一个名为".emacs"的文件
如果创建不了的话也可以用"_emacs"作为文件名
根目录由windows的环境变量HOME指定,如果没有设定HOME环境变量,一般为C:\

6.下载的el文件怎么用?
把文件放到load-path中去,然后按照文件头上的注释说明做。
~/site-lisp一般默认在load-path中
增加load-path例:(add-to-list 'load-path "/path/to/yours")

7.怎么进行矩形区域操作?(类似UltraEdit的列模式) 怎么在每一行前插入相同文字?
x-5-8

8.总有个带小尾巴~的文件出现(自动备份文件),怎么办?
小尾巴文件是备份,可以干掉它或者按文件名分类放到指定目录中去。
详细见x-5-2-4

9.我想把一个命令绑定到某个按键组合上,怎么表示组合键?
x-5-2-3

10.怎么转换文件格式?(DOS <--> UNIX)
C-x f (函数 set-buffer-file-coding-system)

11.查找和替换的时候怎么输入回车之类的特殊字符?
C-q之后输入
^M是C-q C-m,回车是C-q C-j,TAB是C-q TAB

12.M-x shell进入shell-mode出现乱码?怎么修改颜色和字体?
在.emacs中加入:(setq ansi-color-for-comint-mode t)
更多选项请:M-x customize-group ansi-colors

13.windows下插入、浏览图片时emacs崩溃
windows版本的emacs的图片支持dll是用mingw编译的,因此如果你的emacs是用VC编译
的,则可能出现意想不到的问题。建议选择用mingw编译的emacs(http://nqmacs.sf.net

14.如何跳到某一行 ?
`M-x goto-line', 推荐绑定在 `M-g' 键上.

15.如何插入当前时间?
一个例子:

(defun my-insert-date ()
(interactive)
(insert (format-time-string "%Y/%m/%d %H:%M:%S" (current-time))))

(global-set-key (kbd "C-c m d") 'my-insert-date)

16 修改 .emacs 后即时生效(不重启) ?
有几种方法:
1) M-x eval-last-sexp(or C-x C-e)
2) M-x eval-region
3) M-x eval-buffer


* Chinese Related
=================

1.Emacs与其他程序间为什么不能拷贝、粘贴
在~/.emacs加入这句话“(set-selection-coding-system 'cn-gb-2312)”

2.Emacs中新开buffer不使用默认字体怎么办
(add-to-list 'default-frame-alist '(font . "-*-SimSun-medium-r-normal-*-
12-*"))

3.XEmacs怎样保存中文
(prefer-coding-system 'gb2312)

4.怎样使Emacs支持GBK
去http://mule-gbk.sourceforge.net下载那个支持文件,按照里面的README
进行安装。
或者访问本版精华区x-5-3-3,有README贴文和elisp包附件。

* TeX
=====

1.Windows下不能使用LaTeX-preview
使用CVS的GNU Emacs或XEmacs就可以了

2.Emacs能象vimsuite那样加载类似CJK的模板么?
可以,使用template扩展可以加载任何格式的模板

* Programming
=============

1.怎样把C/C++文件重新排版
选择文本块,ESC C-\,M-X c-set-style,可以设置不同的缩进风格

2.语法加亮
(global-font-lock-mode t)

3. c/c++, java 自动补全功能?
c/c++ - ecb
java - jde

Both kind of *SLOW*, though.

* Gnus, Mail, Web
=================

1.mew怎样使用SMTP验证?
(setq mew-smtp-auth-list (quote ("CRAM-MD5" "LOGIN" "PLAIN")))

2.怎样使mew在pop取信时将信件保留在服务器上?
(setq mew-pop-delete nil)

3.gnus怎样使用通讯录?
可以用 bbdb

*Emacs Fill 详解
Emacs 具有非常智能的文本编辑能力。它可以自动对文字断行,并且在断开的行首都加入一些 prefix(前缀)。

你编辑 C 程序多行注释的时候,你想要编辑器能够自动缩进到合适的位置并且插入一个 "*",就像这样?

/* seed the random number generator
* first try the random file /dev/random
* if there isn't such a file in the system
* use current time to seed the RNG.
*/
在你写新闻组的文章的时候,你又想让编辑器使你的文档出现这样漂亮的缩进:

1. I seed the random number generator first try the random file
/dev/random if there isn't such a file in the system use current
time to seed the RNG.

2. I need more powerful randomized binary search tree algorithm to
store my wavefront elements.
这些 * 和 行首留出的空白就叫做 prefix。每当使用 fill-paragraph 等操作或者启动了 auto-fill-mode 的时候,文字在断行时,Emacs 可能会在断开的每行前面加入 prefix(前缀)。这大大方便了编辑类似程序注释这一类文字。

设置 fill-column
fill-column就是说到多少列的时候断行。你可以使用

C-u 70 C-x f
这样的命令把 fill-column 设置为 70. 也可以把光标移动到你想要断行的位置,然后按
C-u C-x f
断开的行可能会被自动加上一个前缀(prefix)。设置prefix的方式主要有两种,手动设置和 adaptive prefix 自动设置。

手动设置 prefix
如果把光标放在段落首后面一个位置,使用

C-x . (set-fill-prefix)
就可以把段落头到光标处的那段字符作为 prefix.
Adaptive Filling
但是没有手动设置 prefix 的时候,Emacs 也可以自动识别段落首的一些字符作为 prefix。这就叫做 Adaptive Filling。

提取候选前缀
Emacs 使用变量 adaptive-fill-regexp 来提取前缀。这个变量是一个正则表达式。它会把fill区域开头的能够匹配的部分作为候选的前缀。很多 major mode 会自动帮你设置好这个变量,所以你通常不用操心。

但是某些时候,你可能希望能够自己操纵这一切。我们下面就来看一个具体的例子。假设如果你要达到这种效果,在同一个文本文件里:

有一些段落每行由3个 * 开头,这可以被作为一小节的标题以及简短的说明。比如:
*** Section "Files". The location
of the RGB database. Note, this
is the name of the file minus
the extension (like ".txt" or
".db").
有一些段落每行由一个 * 号开头,这叫做“强调”。像这样:
* There is normally no need to
* change the default. Multiple
* FontPath entries are allowed
* (they are concatenated together)
* By default, Red Hat 6.0 and later
* now use a font server independent
* of the X server to render fonts.
有一些段落由数字编号 1. 2. 3. 开头,以后的每一行要求缩进到标号之后。所有的数字后面的点号要对齐。
1. I seed the random number generator first try the random file
/dev/random if there isn't such a file in the system use current
time to seed the RNG.

2. I need more powerful randomized binary search tree algorithm to
store my wavefront elements.
这些 "*** ", "* ", "1. ", "2. ", " " 就叫做前缀。为了识别这些前缀,我们把 adaptive-fill-regexp 设置为:

(setq adaptive-fill-regexp "[ \t]+\\|[ \t]*\\([0-9]+\\.\\|\\*+\\)[ \t]*")
这表示前缀可以全是空白字符。或者开头可以有一些空白,接着数字加点或者一个以上的 *,接着一些空白。那么 Emacs 发现开头有这样的字样时,就会把这个字符串作为一个“候选前缀”。

候选前缀的选择
我们已经轻松提取了可能作为前缀的部分,但是一个候选前缀是否被使用,还有很多因素。Emacs 的策略是非常聪明的。我们下面来看看 Emacs 是怎样为用户着想的。

多行文字的前缀 — 使用第二行的前缀
首先,我们经常有这样一种想法:如果我两行开头都有符合候选前缀条件的符号,编辑器应该把第二行的那个候选作为前缀。如果我们输入一些文字:

1. I seed the random number generator
first try the random file
/dev/random if there isn't such a file in the system use current time to seed the RNG.
我们第一行输入了一个前缀 "1. ",第二行我们故意退了几格,使得 "1. " 这种数字标号突出在段落之外。但是其它的文字我们可以先不用管。那么第一行找到的候选前缀就是 "1. "(1,一个点,一个空格),第二行的候选前缀是" "(3个空格)。
写完一段时,我们按 M-q,这段话就自动采用了第二行的前缀(3个空格)作为 prefix。变成这个样子:

1. I seed the random number generator first try the random file
/dev/random if there isn't such a file in the system use current
time to seed the RNG.
如果我们后来不满意。想把第二行开始的那些行多缩进一些,而且把 fill-column 减小一些。我们可以设置 fill-column,然后在第二行开头再加一些空格,按 M-q。就成了这样:
1. I seed the random number generator
first try the random file
/dev/random if there isn't such
a file in the system use
current time to seed the RNG.
想一下你如果不用 Emacs,如何把上面那段文字变成现在这样!
单行文字的前缀选择
那么如果我们只输入了一行字就要求把这行的前缀作为所有断开的行的前缀呢?比如,我们输入一行,开头以 * 开始。我们希望它在fill的时候断开的行都以 * 开头。

这是通过设置 adaptive-fill-first-line-regexp 这个变量实现的。这个变量是一个正则表达式。如果它能够匹配我们用 adaptive-fill-regexp 提取出来的前缀,那么这个前缀就被采用。

(setq adaptive-fill-first-line-regexp "^\\* *$")
注意我们没有使用简单的 "\\* *",而是使用了行首和行尾的匹配符号,因为我们只希望 "* " 这样的符号作为单行重复前缀,出现在每行的开头,而不希望 "***" 成为每行的开头。 adaptive-fill-regexp 提取出来的候选前缀被作为了 adaptive-fill-first-line-regexp 的输入行,它有行首和行尾。

我们这是在告诉 Emacs,单行文字如果由一个 * 开头,那么断行后每一行都以 * 作为 prefix。

如果我们输入一行(麻烦你拖动一下:P) :

* There is normally no need to change the default. Multiple FontPath entries are allowed (they are concatenated together) By default, Red Hat 6.0 and later now use a font server independent of the X server to render fonts.
按 M-q,它就变成了:
* There is normally no need to change the default. Multiple FontPath
* entries are allowed (they are concatenated together) By default, Red
* Hat 6.0 and later now use a font server independent of the X server
* to render fonts.
如果adaptive-fill-first-line-regexp 不能匹配从单行取出的前缀,Emacs 会把这个前缀转成同样长度的空格作为前缀,这正是我们想要的结果。比如我们输入:

*** Section "Files". The location of the RGB database. Note, this is the name of the file minus the extension (like ".txt" or ".db").
由于 "^\\* *$" 不能匹配提取出来的候选前缀 "*** ",所以 Emacs 把跟它同样长度的4个空格作为了前缀。这样 fill 之后变成了:
*** Section "Files". The location of the RGB database. Note, this is
the name of the file minus the extension (like ".txt" or ".db").
这正是我们希望的样子。
*启动 Outline
M-x outline-minor-mode 就可以启动 Outline。还有一个 outline-mode 是一个 major mode,一般都不用它。
全局隐藏操作
光标在任何位置,只要执行这些操作,文档的显示就会变化成需要的样子。
hide-sublevels(C-o C-q)
这个操作如果不带参数,隐藏所有文档子结构,只剩最上层。
M-4 hide-sublevels(M-4 C-o C-q)
这是参数为4的操作,显示至文档第4层子结构。
hide-body(C-o C-t)
文档的所有 Entry 都被隐藏。只显示主干。
对一个子树(Chapter 1)的隐藏操作
hide-subtree(C-o C-d)
所有文档部分展开时,光标移动到 Chapter 1,执行 hide-subtree。整个 Chapter 1 的子树被折叠起来。
hide-other(C-o C-o)
所有文档部分展开时,光标移动到 Chapter 1,执行 hide-other。除了 Chapter 1,其它子树全部被折叠起来。这个操作正好与 hide-subtree 互补。
hide-leaves(C-o C-l)
所有文档部分展开时,光标移动到 Chapter 1,执行 hide-leaves。所有 Chapter 1 子树下的所有级别的 entry 被隐藏。也就是说,Chapter 1 下,只显示 branch.
hide-entry(C-o C-c)
所有文档部分展开时,光标移动到 Chapter 1,执行 hide-entry。Chapter 1 的 Entry 被隐藏,但是所有子树都不动。
全局显示操作
show-all(C-o C-a)
显示所有文档。结果就是原文档。
对一个子树的显示操作
为了演示,我们从全部隐藏的情况开始:
show-children(C-o C-i)
show-children 只显示直接的下一代子树,而不显示间接的下一代。这里, \begin{document} 的直接的下一代就是 \chapter{...}。
show-entry(C-o C-e)
把光标移动到 Chapter 1,执行 show-entry。Chapter 1 的 Entry 被显示,但是所有子结构还是保持隐藏。
show-branches(C-o C-k)
把光标移动到 Chapter 1,执行 show-branches。Chapter 1 这棵子树之下的各级“树干”被显示,但是各级 entry 还是保持隐藏。Chapter 1 自己的 entry,由于我们上一步已经显示,所以保持不变。
show-subtree(C-o C-s)
把光标移动到 Chapter 1,执行 show-subtree。Chapter 1 及其所有子结构全部被扩展。
Outline mode 下的移动操作
在 outline 模式下,有几种特殊方便的移动方式。
C-o C-n (outline-next-visible-heading) 移动到下一个可见标题。
C-o C-p (outline-previous-visible-heading) 移动到上一个可见标题。
C-o C-f (outline-forward-same-level) 移动到下一个同级可见标题。
C-o C-b (outline-backward-same-level) 移动到上一个同级可见标题。
C-o C-u (outline-up-heading) 到上一级标题。
* Resources
===========

1.推荐Emacs入门书籍
a.Sams Teach Yourself Emacs in 24 Hours
可以从http://learn.tsinghua.edu.cn/homepage/2001315450/emacs_doc.html
在线阅读。在ftp.tsinghua.edu.cn中可以下载全文、光盘中的内容以及官方网站
上的一些东西。不要被书名所迷惑,你不可能在24小时内学会的。
b.《学习GNU Emacs》
O'Reilly和机械工业出版社出版的,定价很高,¥68.00。清华的图书馆有藏书,
索书号: TP391.12_K073,借的人很多,需要提前预约。

2.推荐Emacs Lisp入门书籍
a.GNU Emacs Lisp编程入门
涵盖了入门需要的几乎所有知识,写给没用过Emacs,没学过lisp;但是用过编辑器
会写程序的人看的入门书。这本书最好用info看,一边看一边就可以试。在info里面
显示为Emacs Lisp Intro。
b.GNU Emacs Manual
速查手册,info里面显示为Elisp。

3.下载最新版本的GNU Emacs
可以使用cvs方式:
*nix下: cvs -z3 -d:ext:anoncvs@savannah.gnu.org:/cvsroot/emacs co emacs
windows下: 可以用cygnus下的cvs(推荐), 也可以装一个WinCVS
http://nqmacs.sourceforge.net 这里可以下载NTemacs的最新CVS版
4.ftp.tsinghua.edu.cn的Emacs专区
有三种访问方式
http://ftp.tsinghua.edu.cn/pub/Software/Emacs/
ftp://ftp.tsinghua.edu.cn/Software/Emacs/
rsync://ftp.tsinghua.edu.cn/pub/Software/Emacs/

5.Emacs资源哪里最多?
[Emacs Wiki] http://www.emacswiki.org
[Emacs Wiki Elisp List] 很全的elisp list
http://www.emacswiki.org/cgi-bin/wiki/WikifiedEmacsLispList

6.一个收集大量Emacs配置文件的网站
http://www.dotemacs.de/

Aucun commentaire:

Enregistrer un commentaire