【发布时间】:2014-08-13 00:05:31
【问题描述】:
我只有一个来自addon 的模式,我想全局启用它。为了手动打开它,我需要输入 M-x highlight-indentation-mode。所以,下面是我尝试过的列表:(highlight-indentation-mode t)、(highlight-indentation-mode 1)、(setq highlight-indentation-mode t)。没有任何效果。接下来我发现可能是我需要全局启用一个模式,于是我开始用谷歌搜索它。我接下来尝试了什么:
(define-globalized-minor-mode global-highlight-indentation-mode highlight-indentation-mode
(lambda () (setq highlight-indentation-mode t)))
不,这肯定不是我要找的机器人,它打开了变量,但模式仍然不起作用。
(define-globalized-minor-mode global-highlight-indentation-mode highlight-indentation-mode
(lambda () highlight-indentation-mode t))
(define-globalized-minor-mode global-highlight-indentation-mode highlight-indentation-mode
(highlight-indentation-mode t))
这两个只是破坏了我的 Emacs:当我尝试在 config 中使用这两个命令打开文件时,Emacs 写了一个错误,并拒绝打开文件。
UPD:基于 cmets 我也尝试过
(defun enable-highlight-indentation-mode ()
(interactive)
(highlight-indentation-mode t))
(define-globalized-minor-mode global-highlight-indentation-mode highlight-indentation-mode
enable-highlight-indentation-mode)
(global-highlight-indentation-mode t)
没有(interactive) 也一样。当我尝试用这个打开一个文件时,Emacs 拒绝打开,并写一个错误:
File mode specification error: (void-function nil)
c-font-lock-fontify-region: Symbol's function definition is void: nil
【问题讨论】:
-
以下链接包含如何为半旧 Emacs 版本创建全局模式的示例:superuser.com/a/762495/206164 Emacs 的开发人员版本(尚未作为稳定的公开版本发布)有一个选项:
:global t本质上,对于半旧的 Emacs 版本,您只需要一个小函数来打开次要模式并在 globalized 中命名该函数。 . .陈述。您的第二个示例看起来非常接近,只是您没有将highlight-indentation-mode t括在括号中。 -
(defun turn-on-highlight-indentation-mode () (highlight-indentation-mode 1)) (define-globalized-minor-mode global-highlight-indentation-mode highlight-indentation-mode turn-on-highlight-indentation-mode) -
@lawlist 我试过了。我在更新中写的结果。
-
函数通常是无效的,因为缺少函数名后面的括号。 CORRECT:
(defun turn-on-highlight-indentation-mode () (interactive) (highlight-indentation-mode 1))INCORRECT:(defun turn-on-highlight-indentation-mode (interactive) (highlight-indentation-mode 1))不一定是这个新函数有错误——它可能是您的配置中缺少的另一个函数一些括号。 -
是安东·约翰逊的那个吗?如果是这样,下面答案中的那个似乎可以正常工作。我添加了全局模式。
标签: emacs configuration mode minor-mode