简体   繁体   中英

How does one enable Emacs jtags-mode automagically?

Using jtags-mode (version 0.96) via ELPA in a development version of Emacs 24+, I cannot seem to enable the minor mode programmatically (manual invocation works fine). Before I drill into the gory details with what I have tried and the setup that I expect to work, the bottom line is that, after adding jtags-mode to the Java hook variable, I get the following complaint from Emacs when I first vist a Java source file:

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

After thoroughly reading the documentation on jtags-mode setup, I expected the following to suffice:

;; 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)
...

But this led to the complaint above. I have since tried to invoke jtags-mode directly in the java-setup() function, to no avail.

I would gladly take pointers on how to debug this issue if there is no obvious or easy solution.

Functions named xxx-mode are often toggle functions when called without arguments, ie 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.

BTW, if you recompile the jtags-mode file with Emacs-24,the problem should disappear since Emacs-24 changed to way minor modes work in this respect, so that the absence of argument does not mean toggle any more. This change was made specifically because of problems like the one you encountered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM