* The built-in visit-tags-table function
@ 2014-07-11 10:36 Matthias Pfeifer
0 siblings, 0 replies; only message in thread
From: Matthias Pfeifer @ 2014-07-11 10:36 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-07-11 10:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-11 10:36 The built-in visit-tags-table function Matthias Pfeifer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).