[英]How do I determine why emacs indented a certain amount?
In Emacs I'm editing some source code, and I hit <tab>. 在Emacs我正在编辑一些源代码,然后点击<tab>。 Emacs indents the line to n spaces.
Emacs将行缩进到n个空格。 I'd like to change the amount that indents for that kind of line.
我想改变那种线的缩进量。 How do I figure out what rule emacs applied to indent that line by n spaces?
我如何弄清楚应用什么规则emacs来缩进n行空格?
I want to change n, but I need to figure out which of the many indentation-related variables Emacs just used. 我想改变n,但我需要弄清楚Emacs中使用的许多与缩进相关的变量中的哪一个。
If you're using a mode based on cc-mode (eg c-mode, c++-mode, java-mode, etc.), you can hit Cc Cs and it'll tell you what syntactic category the line is. 如果你正在使用基于cc模式的模式(例如c-mode,c ++-mode,java-mode等),你可以点击Cc Cs ,它会告诉你该行的句法类别。 If you want to change it, hit Cc Co and you'll be guided through the process.
如果你想改变它,点击Cc Co ,你将被引导完成整个过程。 Check out the cc-mode docs on customization for more details: https://www.gnu.org/s/emacs/manual/html_node/ccmode/Customizing-Indentation.html
有关更多详细信息,请查看有关自定义的cc模式文档: https : //www.gnu.org/s/emacs/manual/html_node/ccmode/Customizing-Indentation.html
A generic answer is difficult. 一般的答案很难。 Some modes will make this more apparent than others, but in the general case (as they are free to implement indentation however they wish) I don't think you'll get away from needing to read some elisp.
有些模式会比其他模式更明显,但在一般情况下(因为他们可以自由地实现缩进),我认为你不会需要阅读一些elisp。
Starting with the binding for TAB will work, but might be slightly time-consuming depending on how many layers of indirection are involved. 从TAB的绑定开始将起作用,但可能稍微耗时,具体取决于涉及多少个间接层。
If you know that the major mode in question implements its own indentation, then one (non-rigorous, but fast) approach that you could try to help track down the functions being called is to use ELP, the built in elisp profiler. 如果您知道有问题的主要模式实现了自己的缩进,那么您可以尝试帮助跟踪被调用函数的一种(非严格但快速)方法是使用ELP,内置的elisp分析器。
elp-instrument-package
will instrument for profiling all functions with names matching the prefix string argument you specify. elp-instrument-package
将检测所有具有与您指定的前缀字符串参数匹配的名称的函数。 Therefore you might do something like the following in a PHP file (noting that php-mode tells you that it is derived from c-mode) 因此,您可能会在PHP文件中执行以下操作(注意php模式告诉您它是从c模式派生的)
Mx elp-instrument-package
RET php-
RET Mx
elp-instrument-package
RET php-
RET
Mx elp-instrument-package
RET c-
RET Mx
elp-instrument-package
RET c-
elp-instrument-package
RET
Mx elp-instrument-package
RET indent
RET Mx
elp-instrument-package
RET indent
RET
Now type TAB in your source code, and run Mx elp-results
to see which of those instrumented functions were called. 现在在源代码中键入TAB ,并运行Mx
elp-results
以查看调用了哪些已检测的函数。
At this point you're on your own -- look for the likely suspects, and see what the code is doing -- but it can be a handy way to filter the search. 在这一点上,你是独立的 - 寻找可能的嫌疑人,看看代码在做什么 - 但它可以是一种过滤搜索的方便方法。
Once you've finished, use Mx elp-restore-all
to prevent any further profiling. 完成后,使用Mx
elp-restore-all
来阻止任何进一步的分析。
If you happen to enjoy getting your hands really dirty, there's always the elisp debugger to tell you just what Emacs is up to. 如果您碰巧喜欢让自己的手真的很脏,那么总会有elisp调试器告诉您Emacs的最新动态。
If you hit Ch k TAB
you'll find the function that Emacs is running (eg indent-for-tab-command
) then you can do Mx debug-on-entry RET indent-for-tab-command RET
. 如果你点击
Ch k TAB
你会发现Emacs正在运行的功能(例如indent-for-tab-command
),那么你可以进行Mx debug-on-entry RET indent-for-tab-command RET
。 Now whenever you hit TAB
you'll pop up a debugger and can watch the execution step by step. 现在每当你点击
TAB
你都会弹出一个调试器,并且可以逐步观察执行。
Depending on your taste for debugging, it's either a maddening or enlightening experience. 根据您的调试品味,这可能是令人抓狂或有启发性的体验。 Either way, don't forget to
Mx cancel-debug-on-entry
when you're done. 无论哪种方式,当你完成时,不要忘记
Mx cancel-debug-on-entry
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.