几乎*始终启用某些emacs模式或功能*

raf*_*afl 3 emacs

有一对夫妇的emacs的功能,例如flyspell-mode, highlight-beyond-fill-column或者auto-fill-mode,我觉得非常有用,所以我希望他们能几乎所有的时间.然而,总有一些条件它们没有多大意义.

highlight-beyond-fill-column例如,我倾向于想要几乎所有我自己编辑的东西,但是对于阅读别人写的东西,比如在Gnus或者在阅读内置文档时,它实际上非常烦人.

同样,auto-fill-mode在编写Text时非常方便.但是,在编程时它完全没有用.

出于这些原因,我不能只在全局范围内启用这样的功能.总是手动启用它们也不是很实用,但是必须为我在emacs中使用的每个模式或应用程序编写挂钩,显然无法覆盖所有这些模式或应用程序,并且仍然最终启用这些功能手动.

我认为我正在寻找的是一种全局启用某些功能的方法,但是根据各种条件选择性地关闭它们,例如使用哪种主要或次要模式,缓冲区是只读还是可写,或者取决于包含文本或源代码的缓冲区.我确实意识到至少最后一件事可能不容易让emacs回答,但至少我认为我可以使用经常使用的"编程模式"的硬编码列表.

Jér*_*dix 5

因此,您希望完全控制在打开特定模式或特定类型的文件时执行的内容...确定这是您需要的:

;; The function where you could put all your customization
(defun my-func ()
  (turn-on-auto-fill))

;; This is an example, customize it like you need it.
(defvar functions-to-call
  `(((c-mode c++-mode) ".h$" (my-func))
    ((cperl-mode perl-mode) nil (my-func)))
  "A list of triples, used for storing functions.
A triplet is composed of a symbol for the major mode (or a list of symbols),
a regular expression to match against the buffer's file name,
and the functions to call when both the major mode and regular expr match.")

(defun call-mode-functions ()
  "call functions, based on major mode and buffer name regexp matching"
  (interactive)
  (let ((l functions-to-call))
      (while l
        (let* ((elt (car l))
               (modes (if (listp (car elt)) (car elt) (list (car elt))))
               (re (cadr elt))
               (fcts (caddr elt)))
          (when (and (member major-mode modes)
                     (or (null re)
                         (string-match re (buffer-file-name))))
            (while fcts
              (funcall (car fcts))
              (setq fcts (cdr fcts)))
            (setq l nil)))
        (setq l (cdr l)))))

(add-hook 'after-change-major-mode-hook 'call-mode-functions)
Run Code Online (Sandbox Code Playgroud)

使用此代码,您可以执行所需的细粒度自定义.这只是一个例子,您可以根据自己的需要进行调整.