`
Zhongwei_leg
  • 浏览: 548564 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

Emacs 在开发项目中的实际应用(一)

阅读更多

我使用的是 Mac OS 上的 Aquamacs。

 

 

以项目目录为开发阵地

由于使用的是 GUI 版,我需要进入 Python 的项目目录,以方便我每次打开文件时,不需要每次都输入长长的路径前缀。

方法是:

以打开文件的方式,打开目录

Ctrl-x Ctrl-f <目标目录>

 

当前 Tab 的显示内容就变成了 ls -la 的输入内容。

再次 Ctrl-x Ctrl-f ,下面的提示信息显示,已自动加上了路径前缀。

 

 

关闭一个 Tab 页

先用手动点击小叉叉好了,目前还没到 block 我操作的地步 :)

 

 

执行 shell 命令

例如我想在当前目录的所有源码文件中查找 startswith 这个字符串,通常大家需要执行 shell 命令

grep startswith *.py

VIM 最大的缺点是,我找不到方便的方法在 VIM 与 Shell 之间切换的方法。而这恰好是 Emacs 的优势。

Meta-x shell (Mac 上的 Meta 键使用 alt/option 键代替)

在新的 tab 中输入

grep startswith *.py 即可

 

M-p 上次执行的命令(类似正常 shell 下的上箭头键)

M-n 下个执行的命令(类似正常 shell 下的下箭头键)

 

 

文件内查找字符串

Ctrl-s

在 i-search 提示栏输入要搜索的关键字。

按 Ctrl-s 查找下一个匹配。

按下 Enter 键结束搜索。

 

 

运行 python 代码,并查看输出结果

Ctrl-c Ctrl-c 

此时,屏幕会一分为2,右侧显示运行结果 

 

 

使用代码模板

 参考: http://www.emacswiki.org/emacs/AutoInsertMode

 修改 ~/.emacs 文件之后,需要重启 Aquamacs 才能生效

 

 

根据上下文已存在的变量名,半自动补全当前正在输入的变量名

(类似于 VIM 中的 Ctrl-n)

M-/

 

 

连续多行赋值语句对齐

http://stackoverflow.com/questions/60367/the-single-most-useful-emacs-feature

 

A not so well known feature that I find very useful is M-x align-regexp. If you mark a region and execute it, you will be asked for a regular expression, and emacs will then line up the first match of that expression on every line, by padding with spaces (or tabs, if you like). For example, say that you have a list of variables in your code:

int a = 2;
int a_longer_variable_name = 73;
int i = 0;
Then you can mark those lines and to M-x align-regexp and specify = as the expression, and it will align it like:

int a = 2;
int a_longer_variable_name = 73;
int i = 0;
Maybe not the most important feature in the world, but I use it regularly, and it sometimes impresses non-emacs people. :)
 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics