emacs 使用积累6 Some useful Emacs modes

本文介绍了一系列提升Emacs使用效率的方法,包括SVN版本控制、语法检查、快速文件切换、计算器使用、矩形操作等功能,并提供了实用的宏定义及自定义快捷键建议。

 

Some useful Emacs modes

PSVN Very useful mode for handling svn directory trees. (load-file "~hallon/elisp/stuff.el")

Use M-x svn-status to see the status of the current directory. Press C-h m to see available functions. The diff mode (activated by =) has the useful key C-c C-a that can be used to revert a single diff chunk.

Flymake

Do syntax checking while coding. Included in recent Emacsen, enable with M-x flymake-mode. Suggested key bindings to jump to next error and to display error message:

(global-set-key [?\C-<] 'flymake-goto-next-error)(global-set-key [?\C->] 'flymake-display-err-menu-for-current-line)

To start automatically when C/C++ mode is activated:

(add-hook 'c-mode-common-hook 'flymake-mode)

If you program python and want to run some useful tools (like pep8 and pyflakes) add this to your .emacs

(when (load "flymake" t) (defun flymake-pycheck-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "pycheck.py" (list local-file)))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pycheck-init)))(add-hook 'find-file-hook 'flymake-find-file-hook)and then create an executable python (pycheck.py) script in your path like this#!/usr/bin/pythonimport subprocessimport syssubprocess.call(['pep8', '-r', sys.argv[1]])subprocess.call(['pyflakes', sys.argv[1]])You need to have pep8 and pyflakes installed otherwise it wont work...

Ido Fast buffer and file switching. Add (ido-mode t) to .emacs.

Calc Very powerful calculator.

(load-file "~hallon/elisp/stuff.el")

Start with M-x calc.

A more simple but easier calculator is also available with M-x calculator.

Findotherfile Find matching file (eg file.cpp and file.h). Suggested key binding:

(global-set-key "\C-xf" 'ff-find-other-file)

Rectangle Delete and insert rectangles of text. Use C-x r prefix. Most useful C-x r k to kill rectangle and C-x r t to insert string.

Auto-completion If you feel that the standard dynamic abbreviation expand is not good enough you could try the auto-complete extension. Besides being a bit more clever than dabbrev-expand it also features a nice and useful pop-up menu. Together with clang it can perform semantic completions instead of simple syntax analysis. See  this  page for more information.  Cppcheck

If you want static code analysis in your emacs install cppcheck (fedora package) and add the following to your .emacs:

(defun cpp-check () (interactive) "Run cpp-check on current file the buffer is visiting." (shell-command (concat "/usr/bin/cppcheck --quiet --template '{file}:{line}: {severity}: {message}' " (buffer-file-name)) "*compilation*") (pop-to-buffer "*compilation*") (compilation-mode))

Start with M-x cpp-check or bind a key.

Macros

Much useful for repetitive tasks.

Start defining a macro with C-x ( , then do things you want your macro to do. Stop defining with C-x ) . Execute your macro with C-x e and keep pressing e to repeat macro.

General stuff

Make use of the help key ( C-h or F1):

  • You can always use C-h after a key prefix to see which buttons are available, for example C-x r C-h will list all functions in rectangle module. C-h C-h will list all help functions.
  • C-h m will display help for all modes active in the current buffer.
  • C-h k will show what function is bound to a specific key.
Most functions can be customized with the customize mode, this is also a good source to find new functions that you did not know about.

  • M-x customize browse the available customization groups
  • M-x customize-group browse a specific group, tab completion works as usual. 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值