如何使用emacs重构C ++源代码? [英] How can I refactor C++ source code using emacs?
问题描述
我感兴趣的主要是C ++和方法/类名/签名自动更改。
I'm interested mostly in C++ and method/class name/signature automatic changes.
推荐答案
,所以我也一直在等待其他回复。
I do this a lot, so I'm axiously awaiting other replies too.
我知道的唯一的技巧是基本的。这是我在Emacs重构代码时最好的朋友:
The only tricks I know are really basic. Here are my best friends in Emacs when refactoring code:
M-x query-replace
这允许您进行全局搜索和替换。
This allows you to do a global search and replace. You'll be doing this a ton when you move methods and commonly-accessed data to other classes or namespaces.
C-x 3
这样可以显示两个并排的缓冲区。然后,您可以继续加载其中的不同文件,并使用 C-x o
将光标从一个移动到另一个。这是很基本的东西,但我提到它,因为它使下一个有多么强大...
This gives you a display with two buffers side-by side. You can then proceed to load different files in them, and move your cursor from one to the other with C-x o
. This is pretty basic stuff, but I mention it because of how powerful it makes the next one...
C-x (
(type any amount of stuff and/or emacs commands here)
C-x )
这是如何在emacs中定义一个宏。任何时候,你发现自己需要做同样的事情一遍又一遍的代码(它对于查询替换太复杂),这是一个救命。如果你搞错了,可以按 Cg
停止宏定义,然后撤消( C -_
),直到你回到你开始的地方。调用宏的键是 C-x e
。如果你想多次做,你可以点击 Esc
,然后输入一个数字。例如: Esc 100 Cx e
将尝试调用您的宏100次。
This is how you define a macro in emacs. Any time you find yourself needing to do the same thing over and over to a bunch of code (and it is too complex for query-replace), this is a lifesaver. If you mess up, you can hit C-g
to stop the macro definition, and then undo (C-_
) until you are back to where you started. The keys to invoke the macro are C-x e
. If you want to do it a bunch of times, you can hit Esc
and type in a number first. Eg: Esc 100 C-x e
will try to invoke your macro 100 times.
通过按Esc键或按住Alt)获得Meta。
(Note: On Windows you can get "Meta" by hitting the Esc key, or holding down Alt).
这篇关于如何使用emacs重构C ++源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!