如何模拟 Vim 的“softtabstop”在 Emacs 中?
我最近一直在尝试使用 emacs,我需要做的事情之一就是缩进。
示例 1:
sub foo {
my $bar = 'quux';
|
示例 2:
sub foo {
my $bar = 'quux'; |# foo
假设上面示例中的竖线字符表示光标位置。现在,我对每个缩进级别使用 (4) 个空格(无制表符),并且我有 emacs 设置来自动缩进我的代码,并牢记这一点。那里没有问题。但在上面的示例中,如果我要在指示的光标位置按退格键,我希望 emacs 一直退格到下一个缩进级别(第 / 4 列)。也就是说,我希望它将前面的空格视为由制表符组成。相反,它总是只删除一个空格字符。
在 vim 中,我打开“expandtab”以使其插入空格而不是制表符,以及“softtabstop”,这使其(除其他外)退格到下一个“软制表符”,如上所述。
在 emacs 中,我想我可以(如果我更好地了解 emacs/elisp)将退格键绑定到执行以下操作的函数:
if indent-tabs-mode is nil
if the cursor position is preceded by whitespace
calculate the position of the previous "soft tabstop"
if there's enough whitespace
backspace all the way to that point
else
backspace by one character
我想知道的是,是否有更简单的方法可以做到这一点,和/或有人知道吗现有的解决方案?
I've been trying to get into emacs lately, and one of the things I need to get right is indentation.
Example 1:
sub foo {
my $bar = 'quux';
|
Example 2:
sub foo {
my $bar = 'quux'; |# foo
Imagine that the pipe character in the above examples indicates the cursor position. Now, I use (4) spaces for every indent level (no tabs), and I have emacs setup to indent my code automatically with that in mind. No problems there. But in the examples above, if I were to hit backspace at the indicated cursor positions, I want emacs to backspace all the way back to the next indent level (column / 4). That is, I want it to treat the preceding whitespace as if it were made up of tabs. Instead, it always just erases a single space character.
In vim, I turn on 'expandtab' to make it insert spaces instead of tabs, and 'softtabstop', which makes it (among other things) backspace to the next "soft tabstop" as described above.
In emacs, I suppose I could (if I knew emacs/elisp better) bind backspace to a function which does something like the following:
if indent-tabs-mode is nil
if the cursor position is preceded by whitespace
calculate the position of the previous "soft tabstop"
if there's enough whitespace
backspace all the way to that point
else
backspace by one character
What I want to know is, is there a simpler way to do this, and/or does anyone know of an existing solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用,其中
'tab-width
用作列的宽度。在适当的键盘映射中设置键...This works for me, where the
'tab-width
is used as the width of the columns. Set the key in the appropriate keymaps...