如何在emacs中安全地覆盖仅用于缩进的tab键
我是emacs的新用户,我并不特别喜欢emacs模式处理缩进的方式,尤其是在混合模式(比如ASP和perl)时。我编写了以下函数,以“经典”编辑器的方式缩进内容:如何在emacs中安全地覆盖仅用于缩进的tab键,emacs,customization,indentation,Emacs,Customization,Indentation,我是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
(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)))
这里的想法是将缩进绑定回
,并将缩进绑定到
。当使用M-x
调用函数时,它们工作得很好,
绑定工作得很好,但是如果我尝试直接绑定
,它会干扰各种很酷的事情,比如自动完成。我尝试设置缩进行函数:
(setq indent-line-function 'indent-forward)
并设置我的主模式缩进功能:
(setq cperl-indent-command 'indent-forward)
但两者都没有任何效果。我不确定我是否设置错误,或者这是否是正确的方法
总而言之,如何使用tab键覆盖缩进,而不影响自动完成等其他“tab”行为?Emacs wiki有一个关于缩进和tab的完整分类页面:。有关提供各种选项卡DWIM(“智能”选项卡)行为的库或代码段的其他wiki页面,请参见。以下是几点:
(添加钩子'长生不老药模式钩子
(lambda()
(电子缩进模式-1)
(setq缩进行函数“向前缩进”))
参考:您是否正在全局更改
绑定(例如使用全局设置键
)?如果没有,您要更改它的模式是什么?另外,您肯定应该尝试习惯Emacs进行缩进的方式——与您喜欢的方案相比,它为我节省了大量的工作。一旦我习惯了,老办法就不再有意义了。