我是一个Emacs的新用户,我特别不喜欢Emacs模式处理缩进的方式,特别是当混合使用模式时(比如ASP和perl)。我编写了以下函数来按照“经典”编辑器的方式进行缩进:
(defun classic-indent (width)
"Tab the current line or block the 'classic' way"
(save-excursion
(if (not (use-region-p)) (select-current-line))
(indent-rigidly (mark) (point) width)))
(defun indent-forward ()
"tab two space forward"
(interactive)
(classic-indent 2))
(defun indent-back ()
"tab two spaces back"
(interactive)
(classic-indent -2))
(defun select-current-line ()
"Select the current line"
(interactive)
(end-of-line) ; move to end of line
(set-mark (line-beginning-position)))
这里的想法是将 <backtab>
绑定到 indent-back 函数,将 <tab>
绑定到 indent-forward 函数。使用 M-x
调用这些函数时效果很好, <backtab>
绑定也没问题,但是如果我直接绑定 <tab>
,它会干扰所有酷炫的功能,比如自动补全。我尝试使用以下代码设置 indent-line-function
:
(setq indent-line-function 'indent-forward)
并使用以下代码设置我的主模式缩进功能:
(setq cperl-indent-command 'indent-forward)
但是,它们都没有任何作用。我不确定是我设置有误还是这根本就不是正确的方法。
总之,如何在使用tab键时覆盖缩进而不会破坏其他“tab”行为(如自动完成)?
<tab>
绑定(例如使用global-set-key
)吗?如果不是,你是为哪些模式更改它的? - Tikhon Jelvis