2008年12月8日星期一

emacs macro

emacs 宏,专干脏活累活 重复性的劳动

C-x ( (start-kbd-macro) to tell Emacs to start recording your macro.
C-x ) (end-kbd-macro) to tell Emacs to stop recording the macro.
C-x e (call-last-kbd-macro).
1. 记录宏开始用 c-x ( 记录结束用 c-x ) . 执行用c-x e ,执行一遍 c-u 10 c-x e 执行10遍.
2. 在一个范围内应用宏用 M-x sams-apply-macro-on-region .
3. 为宏起名 用 M-x name-last-kbd-macro
4. 将宏插入到一个地方用 M-x insert-kbd-macro. 通常可以专门建立一个 macros.el 专门存放 宏. 在.emacs中 (load "macros") 就成了

sams-apply-macro-on-region 在 sams-lib.el 中

可以绑定在适合自己的快捷上
(global-set-key [(shift f9)] 'sams-apply-macro-on-region)
(global-set-key [(shift f1)] 'call-last-kbd-macro)
(global-set-key [(shift f2)] 'name-last-kbd-macro)
(global-set-key [(control f2)] 'insert-kbd-macro)

进阶:
C-x q (kbd-macro-query) 使macro暂停,在当前位置提示确认是否继续
C-u C-x q. 直接中断macro ,如要继续按 C-M-c.... 录制完宏后 使用时也是这般...

M-x edit-kbd-macro 编辑特定的宏
1. c-x e 编辑最近设定的宏
2. M-x 按照为宏所设置的名称查找, 并编辑
3. C-h-l This lets you use the latest 100 keystrokes as the macro. When you save your editing, it is saved as the macro available through C-x e. (按照字面理解没有啥意思 未深究)

没有评论: