Tag Archive for 'emacs'

How to compile all files in directory with Emacs

1
C-u 0 M-x byte-recompile-directory

will compile all the .el files in the directory and in all subdirectories below.

The C-u 0 part is to make it not ask about every .el file that does not have a .elc counterpart.

Emacs PHP 数组缩进问题解决

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(add-hook 'php-mode-hook
          (lambda ()
            (c-set-style "bsd")
            (setq c-indent-level 4)
            (setq c-continued-statement-offset 4)
            (setq c-brace-offset -4)
            (setq c-argdecl-indent 0)
            (setq c-label-offset -4)
            (setq c-basic-offset 4)
            (setq tab-width 4)
            (setq indent-tabs-mode nil)
            (c-set-offset 'case-label '+)
            (c-set-offset 'arglist-close 'c-lineup-arglist-operators)
            (c-set-offset 'arglist-intro '+)
            (c-set-offset 'arglist-cont-nonempty 'c-lineup-math)))

Some commonly used Emacs commands

M-x = “meta x” = Esc, then x as described above (simultaneously codessing Alt + x, or “diamond” + x, works on some machines)
C-x = “control x” = Ctrl + x

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
C-shift-_                undo

M-shift->                end of buffer
M-shift-<                beginning of buffer

C-a                      beginning of line
C-e                      end of line
C-k                      delete from cursor to end of line

M-x shell                runs a shell inside emacs
M-p                      codevious command (in shell mode)
M-n                      next command (in shell mode)

C-space                  set mark
C-W                      cut all text between mark and cursor
M-W                      copy all text between mark and cursor
C-y                      paste

C-x b                    change buffer
C-x C-b                  change buffer w/list of available buffers
                         (move cursor over the name of the buffer
                          you want and hit f)

C-x 2                    split the current buffer into 2, with one over the other
C-x 1                    1 buffer/window
C-x 3                    split the current buffer into two, with one next to the other
C-x o                    switch buffer

Emacs Be Back To Me

http://code.google.com/p/jobz/source/browse/trunk/maesinfo-home/.emacs

Emacs skeleton-pair Funcionality

> I have enabled skeleton-pair funcionality with what I have found in here:
> http://littlechina.org/~cmarcelo/paren-experiment.el
> It works in most modes, but in C++ mode it only works for [ and not for (,{
> or “.

Try:

1
2
(define-key c-mode-base-map (kbd "(") #'skeleton-pair-insert-maybe)
;; same for the other keys here...

or

1
2
3
4
5
(add-hook 'c-mode-common-hook
#'(lambda ()
(local-set-key (kbd "(") #'skeleton-pair-insert-maybe)
;; same for the other keys here...
))

If you don’t like the way skeleton decides whether to insert a pair or
not but to insert a pair always use `insert-pair‘ instead of
`skeleton-pair-insert-maybe‘.

Some thing others.

使用Emacs作为Python开发环境

Emacs号称是编辑器之王,无所不能。可把他作为一个Python的集成开发环境

尽管Emacs那么的牛,但是从前用的多的还是简单的 vi。受不了吸引,决定开始使用Emacs进行Python的编程。

python.org上emacs的主页和对应wiki中,对python-mode竟然没有太多的介绍,反而在另外一个网站上找到了一些 emac 的资料,特别是 安装过程

安装过程总结一下:

  1. 使用最新的emacs:大于21.1的XEmacsen,或者大于20.7的Emacsen.
  2. 确保安装了prog-modes这个包,在debian中很简单:
    1
    #apt-get install prolog-el
  3. python-mode项目中,下载python-mode.el
  4. 字节编译,在emacs中输入命令(警告信息可忽略):
    1
    2
    C-x C-f /path/to/python-mode.el RET
    M-x byte-compile-file RET
  5. 确保python-mode.el在加载路径中,测试方法:
    1
    M-x locate-library RET python-mode RET

    如果没有,加入下行到自己的.emacs文件中:

    1
    (setq load-path (cons "/dir/of/python-mode/" load-path))
  6. 文件关联,自动将py后缀的文件和pyhton-mod关联,在自己的.emacs文件中添加:
    1
    2
    3
    4
    5
    (setq auto-mode-alist
    (cons '("\\.py$" . python-mode) auto-mode-alist))
    (setq intercodeter-mode-alis
    (cons '("python" . python-mode)
    intercodeter-mode-alist))
  7. 自动加载,将 python-mode 和文件 python-mode.elc关联,在自己的.emacs文件中添加:
    1
    (autoload 'python-mode "python-mode" "Python editing mode." t)
  8. 语法加亮,这个功能可不能少哟:) 同样在自己的.emacs文件中添加:
    1
    2
    3
    ;;; add these lines if you like color-based syntax highlighting
    (global-font-lock-mode t)
    (setq font-lock-maximum-decoration t)
  9. 支持中文,在.emacs中添加:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    (set-language-environment 'Chinese-GB)
    (set-keyboard-coding-system 'euc-cn)
    (set-clipboard-coding-system 'euc-cn)
    (set-terminal-coding-system 'euc-cn)
    (set-buffer-file-coding-system 'euc-cn)
    (set-selection-coding-system 'euc-cn)
    (modify-coding-system-alist 'process "*" 'euc-cn)
    (setq default-process-coding-system
    '(euc-cn . euc-cn))
    (setq-default pathname-coding-system 'euc-cn)
  10. 好了!进入emacs试验一下:

    1
    $ emacs abc.py

    可以看到emacs的底部显示:Using the CPython shell。可以试着输入一些代码,加亮显示没有问题,支持自动缩进,支持自动括号匹配提示…. 使用C-h m你可以看到python模式的详细帮助文件,功能果然很强大!