天天看点

Emacs language mode

如果你定义的文件后缀类型不存在的话,你可以通过下面方式设置

  1:在附录B中查最右边一列,找到它对应的需要调用的方法。

  2:通过.emacs文件来告诉Emacs当遇到这种后缀文件时,自动加载相应的程序包。

  你需要邪写入两行进行定制,首先用autoload方法,告诉Emacs去哪找那些它现在还不知道的命令,因为这个命令相当与把方法跟相应的包关联起来了。所以当我们输入这个方法以后相应的包就会加载进来,现在我们想实现的是建立一个调用语言模式的方法,跟实现相应模式的包的关联

(autoload 'function "filename" "description" t)
           

  比如你想加载php mode的话,首先去下载最新的mode包http://sourceforge.net/projects/php-mode/然后在.emacs文件中输入下面一句话

(autoload 'php-mode "php-mode" "PHP editing mode." t) 它告诉emacs当我们执行php-mode的时候去加载PHP package
           

  第二步就是建立一个后缀跟相应的语言模式的关联,然后你就可以在调用这个后缀开始的文件时,自动调用相应模式,我们是通过全局变量auto-mode-alist进行控制。它时一个列表,用于实现根据源文件后缀关联相应的模式

(setq auto-mode-alist (cons '("\\.php$" . php-mode) auto-mode-alist))
           

  比方说你现在有个文件test.php,它会在auto-mode-alist中找到这个后缀,并且试图去调用相应的方法php-mode,但是实际上没有这个php-mode,但是有一个autoload把php-mode关联到了php 的包,然后开始加载这个包,然后在包中找到了php-mode方法。最后你就进入了php mode.

For some interpreted languages like Perl and Python, you will also want to update the interpreter-mode-alist global variable:

(setq interpreter-mode-alist
      (cons '("python" . python-mode)
            interpreter-mode-alist))
           

  如果你得脚本中用#!开头,Emacs可以通过检查这一行来决定到底使用哪种语言,这对与没有文件后缀的文件来说很重要。

Syntax

   尽管不同的模式之间有区别,但是他们都包含一些共同基本语法,比方说字符,标点,分割符,注释等等是如何在语言中设定的。Emacs把这些信息保存到内部的syntax table中,Emacs拥有适用于所有buffer的全局变量,同样它包含一个局部table来设置当前的buffer,它随着所在模式的变化而不同。你可义通过C-h s (describe-syntax)来查看

   语法同样还包括一些对标点(punctuation)的操作,比如括号,你输入一个(right parenthesis),然后在对应的左括号闪几下,然后再回来原来位置(flash the matching left parenthesis by moving the cursor there)

       blink-mathing-paren-distance 决定它具体可以向后搜索匹配左括号的界限(character),默认是25600

   blink-matching-delay 在左端匹配的字符闪烁的时间,默认值1

Comment

所有的编程语言都拥有注释

M-; indent-for-comment universal comment command for all language mode.

M-j indent-new-comment-line 当这一行注释不够时,你可以输入这个命令另起一行,同时如果你是在一行注释中见输入这个命令,他会把注释截成两行。

M-x comment-region 用于注释一段代码

M-x kill-comment   去掉光标所在行的注释

Indenting Code(格式缩进)

These features implement standards of indentation, commenting, and other aspects of programming style, thus ensuring consistency and readability,

left-margin 变量控制着缩进,他的值等于所要缩进的那个列。

Tab indent any line properly anywhere the cursor stay.

下面是一些缩进的命令

C-M-\  indent-region 它会对所选的范围进行缩进排版

M-m    back-to-indentation 移动到该行的第一个非空格字符

M-^    delete-indentation  删除缩进格式,把当前语句跟前一个语句合并

Etags

Another general feature of Emacs that applies to programmers is the etags facility.If you work on large, multifile projects, you will find etags to be an enormous help.

Fonts and Font-lock mode

M-x font-lock-mode     用于设置颜色显示

M-x list-faces-display a list of named faces Emacs,including colors and style

M-x modify             a simple prompted "wizard" approach

M-x customize-face     a big fancy interactive approach