standino 发表于 2013-1-27 04:40:31

走进Emacs殿堂

安装

使用cygwin在windows上安装

在安装emacs之前需要先安装cygwin。这里是安装方法。需要特别说明的是,在选择安装包的时候,请选上python。


http://www.agoit.com/upload/attachment/52643/a95d2500-dc15-3f59-96d3-fed251d58b8b.png


安装完cygwin以后我们就可以使用脚本进行以下的安装。把下面的一段代码存到名为myapt的文件中,把myapt文件存放到
C:\cygwin\home\[您的用户名]\bin目录下。

#!/bin/bashfunction do_apt(){    mkdir -p ~/bin    cd ~/bin    wget http://download.linuxaudio.org/lilypond/binaries/cygwin/cyg-apt    chmod a+rx cyg-apt    cyg-apt -m http://www.cygwin.cn/pub setup    cyg-apt -m http://www.cygwin.cn/pub update    cd -}function do_editor(){    do_cyg_install install xinit xorg-server font-adobe-dpi100 font-adobe-dpi75    do_cyg_install install twm xclock font-isas-misc    do_cyg_install install emacs emacs-X11 emacs-el}function do_cyg_install(){   cyg-apt -m http://www.cygwin.cn/pub $@}cmd=$1case $cmd in    init)      do_apt      ;;    emacs)      do_editor      ;;esac

点击桌面的 cygwin 快捷方式启动 cygwin 控制台。
在控制台中输入:

chmod +x bin/myapt #---赋予 myapt 执行权限。myapt init         #---初始化myapt emacs      #---安装emacs

现在,emacs在windows下的基本安装就完成了。 我们可以在 cygwin 控制台中输入命令 starx 启动 xterm, 然后在 xterm 中输入命令 emacs-X11
来启动 emacs 程序。


在 ubuntu 上安装

我们同时使用脚本方式安装。把下面的代码拷贝到myapt文件中,把myapt存到${HOME}/bin目录下。

#!/bin/bashfunction do_emacs(){    sudo aptitude installemacs emacs-extra emacs-goodies-el emacs-intl-fonts    sudo aptitude installw3m-el muse-el aspell remember-el}cmd=$1case $cmd in    emacs)      do_editor      ;;esac

打开Terminal 输入:

chmod +x bin/myapt #---赋予myapt执行权限。myapt emacs      #---安装emacs

现在,emacs 在 ubuntu 下的基本安装就完成了。



Emacs 简介

打开的 emacs 如下图所示。在 emacs 中编辑的不是文本本身,emacs 会把文件的内容拷贝到 buffer 中。

http://www.agoit.com/upload/attachment/53274/deaa2c39-5c01-3368-ac0f-e0db670f1731.png


从图中我们可以看到,emacs 由“菜单”、“工具条”、“主 buffer”、“状态显示条”和“次 buffer” 组成。

在 emacs 中很多操作都有快捷键,使用快捷键是一种
高效的编辑 buffer 的方式。但是如果我们忘记了某个操作的快捷键,我们可以通过选择“菜单”或者点击“工具条”上的按钮来执行相应的操作。

“主 buffer” 是我们编辑文件的主要区域,看起来和记事本没有太多区别,不过当您熟悉了它的功能以后,您就知道它远非那么简单了。

在 emacs 中还有一个模式(mode)的概念,例如我们编辑一个 SQL 文件,那么它就会使用 sql-mod。所有 SQL 相关的语法显亮,连接数据库,执行
SQL 查询等功能都会与 sql-mod 关联。在一个 buffer 中可以使用多个模式。这些信息会显示在“状态显示条”上。

“次 buffer” 是我们和 emacs 交互的一个窗口。通过“次 buffer”,我们可以向 emacs 发送命令。emacs 中的所有操作都可以通过命令来执行。


基本的文本编辑


C-x C-c : Exit and close EmacsC-x C-z : Exit and hang on EmacsC-x C-f : Open file or folderC-x i   : Insert fileC-x C-r : Open a file with read only modeC-x u Or C-/   : UndoC-x C-s : SaveC-x s   : Save all unsaved filesC-x C-w : Save as...C-l   : Refresh the bufferC-g   : Stop current commandC-a   : Go to headC-e   : Go to tailC-n   : Next lineC-p   : Pre lineC-f   : forward one characterC-b   : backward one character


如何获得帮助信息

Ctrl + h


[*]acommand-apropos.Type a list of words or a regexp; it shows a list of commands whose names match.See also theaproposcommand.
[*]bdescribe-bindings.Display a table of all key bindings.
[*]cdescribe-key-briefly.Type a key sequence;it displays the command name run by that key sequence.
[*]dapropos-documentation.Type a pattern (a list of words or a regexp),and shows a list of functions, variables, and other items whosedocumentation matches that pattern.See also the apropos command.
[*]pfinder-by-keyword. Find packages matching a given topic keyword.rinfo-emacs-manual.Display the Emacs manual in Info mode.



Lisp 语言介绍

Function


01(defun my-switch-buffer ()
02    "Like switch-buffer but in the opposite direction"
03    (interactive "")
04    (other-window -1)
05)


Customize Emacs


(require 'color-theme)
(color-theme-initialize)
(color-theme-billw)


安装插件

Emacs的插件一般是由 Lisp 编写的,你只需要把插件的 Lisp 文件放到 Emacs 的查询路径下就可以了。这里我介绍另一个安装插件的工具 ELAP
http://tromey.com/elpa/install.html。


(let ((buffer (url-retrieve-synchronously       "http://tromey.com/elpa/package-install.el")))(save-excursion    (set-buffer buffer)    (goto-char (point-min))    (re-search-forward "^$" nil 'move)    (eval-region (point) (point-max))    (kill-buffer (current-buffer))))



在Emacs中编程


[*]Tabbar
[*]Spell Check
[*]SQL
[*]Template
[*]Auto-completionVersion Control


执行更多的文本编写

PlanningOrg

Org-mode is a mode for keeping notes, maintaining TODO lists, and doing project planning with a fast and effective plain-text system.

Taking notesmuse

Emacs Muse is an authoring and publishing environment for Emacs. It simplifies the process of writings documents and publishing them to various output formats. Muse uses a very simple Wiki-like format as input.

Muse consists of two main parts: an enhanced text-mode for authoring documents and navigating within Muse projects, and a set of
publishing styles for generating different kinds of output.


扩展Emacs

Get the last version automatically

(add-hook 'find-file-hooks 'my-vc-update)(defun my-vc-update()(condition-case nil      (if (vc-registered (buffer-file-name))         (vc-update))    (error nil)))

Run SQLunit Test

(defun sqlunit-run-file ()   "Run sqlunit on current buffer"   (interactive )   (shell-command      (format "ant -f %s../build.xml-Dscript.name=%s &" (buffer-dir)(buffer-name))))

Developerworks article publishing
页: [1]
查看完整版本: 走进Emacs殿堂