简体   繁体   English

Emacs c++ 制表符写入空格删除

[英]Emacs c++ tabs writing spaces removing

I have seen a lot of questions about emacs and tabs/spaces topic but no one talking about this:我已经看到很多关于 emacs 和制表符/空格主题的问题,但没有人谈论这个:

I have emacs in C++ mode and tabs as indent character, if i press enter for a newline emacs auto-indent with tab but if i try to remove that "tab" i remove only one space.我有 emacs 在 C++ 模式和制表符作为缩进字符,如果我按 Enter 换行 emacs 自动缩进,但如果我尝试删除一个制表符空格。

I understand that emacs create tabs using spaces but if i want to remove that "tab" i would want to remove the 4 (or 8) spaces directly not one by one, in python-mode works as intended but in c++ mode no.我知道 emacs 使用空格创建制表符,但是如果我想删除那个“制表符”,我想直接删除 4 个(或 8 个)空格而不是一个一个,在 python 模式下按预期工作,但在 c++ 模式下没有。 There is a variable for that or any work around?有一个变量或任何解决方法?

Your Backspace key ( <DEL> ) is probably bound to command backward-delete-char-untabify .您的 Backspace 键 ( <DEL> ) 可能绑定到命令backward-delete-char-untabify Bind it to something else, eg delete-backward-char .将它绑定到其他东西,例如delete-backward-char

From the Elisp manual, node Program Modes :从 Elisp 手册中,节点程序模式

In most programming languages, indentation should vary from line to line to illustrate the structure of the program.在大多数编程语言中,缩进应该因行而异,以说明程序的结构。 Therefore, in most programming language modes, typing <TAB> updates the indentation of the current line.因此,在大多数编程语言模式下,键入<TAB>会更新当前行的缩进。

Furthermore, <DEL> is usually bound to backward-delete-char-untabify , which deletes backward treating each tab as if it were the equivalent number of spaces , so that you can delete one column of indentation without worrying whether the whitespace consists of spaces or tabs.此外, <DEL>通常绑定到backward-delete-char-untabify ,它删除向后删除每个选项卡,就好像它是等效数量的空格一样,这样您就可以删除一列缩进而不用担心空格是否由空格组成或标签。

IOW, the behavior you don't like is provided by default in the programming mode you are using. IOW,您不喜欢的行为默认在您使用的编程模式中提供。

Actually, if you are in c++-mode , <DEL> is bound to command c-electric-backspace .实际上,如果您处于c++-mode<DEL>将绑定到命令c-electric-backspace The doc for that function ( Ch f c-electric-backspace ) tells you:该 function ( Ch f c-electric-backspace ) 的文档告诉您:

c-electric-backspace is an interactive compiled Lisp function in cc-cmds.el . c-electric-backspacecc-cmds.el

(c-electric-backspace ARG)

Delete the preceding character or whitespace.删除前面的字符或空格。

If c-hungry-delete-key is non- nil (indicated by "/h" on the mode line) then all preceding whitespace is consumed.如果c-hungry-delete-keynil (在模式行上由"/h"指示),则所有前面的空格都会被消耗。 If however a prefix argument is supplied, or c-hungry-delete-key is nil , or point is inside a literal then the function in the variable c-backspace-function is called.但是,如果提供了前缀参数,或者c-hungry-delete-keynil ,或者 point 在文字内,则调用变量c-backspace-function中的 function 。

And by default it seems that the value of user option c-backspace-function ( Ch v ) is... backward-delete-char-untabify .默认情况下,用户选项c-backspace-function ( Ch v ) 的值似乎是... backward-delete-char-untabify So you can just customize that option to set it to some other function, such as delete-backward-char .因此,您可以自定义该选项以将其设置为其他一些 function,例如delete-backward-char That will change the behavior only for C++ and C modes.这只会改变 C++ 和 C 模式的行为。

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

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