3

在 Emacs 24+ 的开发版本中通过 ELPA使用jtags-mode(版本 0.96),我似乎无法以编程方式启用次要模式(手动调用工作正常)。在我用我尝试过的东西和我期望工作的设置深入研究血腥细节之前,最重要的是,在添加jtags-mode到 Java 挂钩变量之后,当我第一次访问 Java 源文件时,我从 Emacs 收到以下抱怨:

Toggling jtags-mode off; better pass an explicit argument. [2 times]

在彻底阅读有关jtags-mode设置的文档后,我希望以下内容就足够了:

;; Support for Java coding. 
(autoload 'jtags-mode "jtags" "Toggle jtags mode." 1)

(defun java-setup ()
  (setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92)
    indent-tabs-mode nil
    tab-width 4
    fill-column 96
    c-comment-start-regexp "\\(@\\|/\\(/\\|[*][*]?\\)\\)"
    jtags-display-menu-flag t
    jtags-mode 1)
  (java-mode-indent-annotations-setup))

(add-hook 'java-mode-hook 'java-setup)
(add-hook 'java-mode-hook 'jtags-mode)
...

但这导致了上面的抱怨。从那以后,我试图jtags-mode直接在java-setup()函数中调用,但无济于事。

如果没有明显或简单的解决方案,我很乐意就如何调试此问题提供指导。

4

2 回答 2

4

Functions named xxx-mode are often toggle functions when called without arguments, i.e. they turn the mode on if it was off and vice versa. As you have added this function to a hook, this is how it is called. Several minor modes provide a function like turn-on-xxx-mode that are designed to be added to hook directly.

When called with an argument, 1 typically activates them and -1 deactivates. Try calling it from your setup function rather than adding the jtags-mode function to the hook

I would suggest activating the minor mode from your setup function. Also, in your setup code, you set the jtags-mode variable to 1, which normall is not the right thing to do. For example:

(defun java-setup ()
  (setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92)
    indent-tabs-mode nil
    tab-width 4
    fill-column 96
    c-comment-start-regexp "\\(@\\|/\\(/\\|[*][*]?\\)\\)"
    jtags-display-menu-flag t)
  (jtags-mode 1)
  (java-mode-indent-annotations-setup))

(add-hook 'java-mode-hook 'java-setup)

Finally, a reservation. I haven't used jtags-mode, this answer is based on general knowledge on how minor modes work.

于 2012-04-22T20:11:18.597 回答
0

顺便说一句,如果您使用 Emacs-24 重新编译 jtags-mode 文件,问题应该会消失,因为 Emacs-24 在这方面更改为次要模式的工作方式,因此没有参数并不意味着再切换。之所以进行此更改,是因为您遇到了类似的问题。

于 2012-04-24T02:13:13.890 回答