简体   繁体   English

TAB键在emacs的暂存缓冲区中不起作用

[英]TAB key not working in scratch buffer of emacs

Hitting TAB key while entering text into scratch buffer does not do anything. 在暂存器中输入文本时,按TAB键不会执行任何操作。 I would like TAB key to behave exactly as it would in other normal buffers(move point forward by inserting some X number of spaces or insert a TAB character). 我希望TAB键的行为与在其他普通缓冲区中完全一样(通过插入一些X数量的空格或插入TAB字符来向前移动点)。 Could you please help me achieve that? 你能帮我实现这个目标吗? Thank you. 谢谢。

I have come across below question, but it doesn't have an answer and the link mentioned in its comment is not working. 我遇到了以下问题,但没有答案,评论中提到的链接无效。 I do not have enough score to add a comment to it. 我没有足够的分数要添加评论。

How to enable tab key in scratch buffer of emacs? 如何在emacs的暂存缓冲区中启用Tab键?

Feel free to close the current question if you could add an answer to above question. 如果您可以为上述问题添加答案,请随时关闭当前问题。

TAB's behavior in most programming-language modes is not "insert a tab" but "make sure the code on this line is indented correctly according to the current rules". 在大多数编程语言模式下,TAB的行为不是“插入选项卡”,而是“确保根据当前规则在此行上的代码正确缩进”。 The default mode for the scratch buffer is lisp-interaction-mode , and since you have not written any Lisp code, there is no indenting to do, so TAB does nothing. 暂存缓冲区的默认模式为lisp-interaction-mode ,并且由于您尚未编写任何Lisp代码,因此无需缩进,因此TAB不会执行任何操作。

There are a few ways you could change this. 您可以通过几种方法来更改此设置。 You could change the major mode to, say, text-mode or fundamental-mode , either for a single session (with Mx text-mode ) or permanently (by putting (setq initial-major-mode 'text-mode) into your .emacs file). 您可以将单个会话的主要模式更改为text-modefundamental-mode (使用Mx text-mode ),也可以永久更改(通过将(setq initial-major-mode 'text-mode)放入(setq initial-major-mode 'text-mode) 。 emacs文件)。

Or you could leave the mode alone, and rebind the TAB key entirely. 或者,您可以不使用该模式,而完全重新绑定TAB键。 One way to do this would be 一种方法是

M-: (global-set-key (kbd "TAB") 'self-insert-command)

I'm sure there are many other alternatives, depending on how exactly you want your scratch buffer to act. 我确定还有很多其他选择,具体取决于您希望暂存缓冲区的运行方式。

If all you're interested in is to insert the TAB character (ie \\t ), then you could use the quoted-insert function. 如果您只想插入TAB字符(即\\t ),则可以使用带quoted-insert功能。 By default it's bound to Cq . 默认情况下,它绑定到Cq It captures the next input character and inserts it verbatim. 它捕获下一个输入字符并将其逐字插入。 So in your case that would be Cq TAB . 因此,在您的情况下,这将是Cq TAB

I posted that comment with the now dead link, so I'll quote from the Wayback Machine copy : 我用现在已失效的链接发布了该评论 ,因此我将引用Wayback Machine的副本

Emacs isn't inserting anything!! Emacs没有插入任何东西!

If you feel like I do, you probably are considering this a fault. 如果您感觉像我一样,您可能正在考虑这是一个错误。 You keep pressing the TAB key, but nothing happens. 您一直按TAB键,但是什么也没有发生。

In programming modes, such as when you're editing C or Perl or Lisp source code, the TAB key is bound to special indentation rules. 在编程模式下(例如,当您编辑C或Perl或Lisp源代码时),TAB键绑定到特殊的缩进规则。 That is, instead of being bound to indent-relative as in text-mode, the TAB key is pre-bound to cc-indent-line or lisp-indent-line (if editing your .emacs file), and so on. 也就是说,TAB键不是预先绑定到indent-relative文本模式的indent-relative ,而是预先绑定到cc-indent-linelisp-indent-line (如果编辑.emacs文件),依此类推。 In c-mode, pressing the TAB key will move the cursor to the first indentation level, and then may not move the cursor forward after that, no matter how many times you press it. 在c模式下,按TAB键会将光标移到第一个缩进级别,此后无论按多少次,都可能不会向前移动光标。

If this behavior isn't what you want, you can do one of these things: 如果这种行为不是您想要的,则可以执行以下操作之一:

  • Press Ctrl-q <TAB> to insert a TAB character right now Ctrl-q <TAB>立即插入TAB字符
  • Temporarily reassign the TAB key to self-insert-command while staying in the same editing mode 保持相同的编辑模式时,暂时将TAB键重新分配给self-insert-command
  • Switch to a different editing mode for this session; 切换到该会话的其他编辑模式; the TAB behavior will change with the editing mode TAB行为将随着编辑模式而改变
  • Change your .emacs file to permanently change the editing mode for the filetype you're using now 更改您的.emacs文件以永久更改您正在使用的文件类型的编辑模式

I'd recommend reading the entire page, as it explains well how Emacs treats the TAB key and tab characters different from pretty much everything else. 我建议您阅读整个页面,因为它很好地解释了Emacs如何对待TAB键和制表符与几乎所有其他内容不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM