help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The built-in visit-tags-table function


From: Matthias Pfeifer
Subject: The built-in visit-tags-table function
Date: Fri, 11 Jul 2014 12:36:44 +0200

Hello,

from time to time i come into the situation where i write/edit/view shell
scripts with emacs. I was trying to benefit from etags ability to tag the
file and enable me to jump around in the file with the "find-tag" method.
so i started tuning my init.el. I wrote a method that in the sh-mode-hook
checks if a tags file for the edited file is already available and in case
it is not starts an etags process and feeds it with the text from the
buffer. However i run into some sort of recursion when doing
visit-tags-table.

The question is where can i place my generate-tags-file method if not in
the sh-mode-hook? Is there a way to not run into this recursion?

(defconst mp/tags-repository "/home/matthias/.emacs.d/tags/"
  "The name of the directory where tags files are stored.")
(defconst mp/tags-program "/usr/bin/etags")
(defconst mp/tags-status-buffer-name "*etags*")
(defconst mp/auto-etags-modes (list 'perl-mode-hook 'sh-mode-hook))
(defvar mp/recursion-guard nil "Here i am trying to work around the strange
recursion that appears here".)

(defun mp/generate-tags-file ()
  "Create tags file for current buffer."
  (interactive)
  (when (null mp/recursion-guard)
    (setq mp/recursion-guard t)
    (let* (
       (tags-file (replace-regexp-in-string "/" "_" (buffer-file-name)))
       (tags-file-path (concat mp/tags-repository tags-file))
       )
      (when (or (not (file-exists-p tags-file-path))
        (file-newer-than-file-p (buffer-file-name) tags-file-path))
    (let ((etags-process (start-process "etags" mp/tags-status-buffer-name
mp/tags-program
                        (concat "--output=" tags-file-path)
                        (concat "--parse-stdin=" (buffer-name)))))
      (process-send-region etags-process (point-min) (point-max))
      (process-send-eof etags-process)
      )
    )
      (when (file-exists-p tags-file-path)
    (visit-tags-table tags-file-path t)
    )
      )
    )
  (setq mp/recursion-guard nil)
  )

(defun mp/stop-auto-tagging()
  (interactive)
  (dolist (mode-hook mp/auto-etags-modes)
    (add-hook mode-hook 'mp/generate-tags-file)
    )
  )

(defun mp/start-auto-tagging()
  (interactive)
  (dolist (mode-hook mp/auto-etags-modes)
    (remove-hook mode-hook 'mp/generate-tags-file)
    )
  )

;; ---------------------------------------------------------

Sincerely

Matthias


reply via email to

[Prev in Thread] Current Thread [Next in Thread]