gpt4 book ai didi

emacs - 如何安全地覆盖 tab 键只是为了在 emacs 中缩进

转载 作者:行者123 更新时间:2023-12-01 10:21:39 26 4
gpt4 key购买 nike

我是 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)))

这里的想法是将缩进绑定(bind)到 <backtab>并缩进到<tab> .使用 M-x 调用这些函数时效果很好, 和 <backtab>绑定(bind)工作正常,但如果我尝试绑定(bind) <tab>直接地,它会干扰各种很酷的事情,比如自动完成。我尝试设置 indent-line-function与:

(setq indent-line-function 'indent-forward)

并设置我的主要模式缩进函数:

(setq cperl-indent-command 'indent-forward)

但两者都没有任何作用。我不确定我是否设置错误,或者这是否是正确的方法。

总而言之,如何在不破坏其他“tab”行为(如自动完成)的情况下使用 tab 键覆盖缩进?

最佳答案

Emacs wiki 有一个关于缩进和 TAB 的完整类别页面:http://www.emacswiki.org/emacs/CategoryIndentation .请参阅有关为您提供各种 TAB DWIM(“智能”TAB)行为的库或片段的其他 wiki 页面。这里有一对:

关于emacs - 如何安全地覆盖 tab 键只是为了在 emacs 中缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8406238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com