;; Automatic Etags for prolog (setq tags-table-list '("~/Documents/build/ClioPatria/cpack/mySource")) (defun create-prolog-tags (dir-name) "Create prolog tags file." (interactive "DDirectory: ") (eshell-command (format "cd %s; find %s -type f -name \"*.pl\" | etags -l prolog -" dir-name dir-name))) (defadvice xref--find-definitions (around refresh-etags activate) "Rerun etags and reload tags if tag not found and redo find-tag. If buffer is modified, ask about save before running etags." (let ((extension (file-name-extension (buffer-file-name)))) (condition-case err ad-do-it (error (and (buffer-modified-p) (not (ding)) (y-or-n-p "Buffer is modified, save it? ") (save-buffer)) (er-refresh-etags extension) ad-do-it)))) (defun er-refresh-etags (&optional extension) "Run etags on all peer files in current dir and reload them silently." (let ((my-tags-file (locate-dominating-file default-directory "TAGS"))) (when my-tags-file (message "Loading tags file: %s" my-tags-file) (let ((tags-dir (file-name-directory my-tags-file))) (create-prolog-tags tags-dir) (visit-tags-table my-tags-file)))))

Have you ever wanted M-. (the emacs command which finds the definition of the term under the cursor) to just "do the right thing" and go to the most current definition site, but were in a language that didn't have an inferior process set-up to query about source locations correctly (as is done in lisp, ocaml and some other languages with sophisticated emacs interfaces)?Well, fret no more. Here is an approach that will let you save the appropriate files and regenerate your TAGS file automatically when things change assuring that M-. takes you to the appropriate place.You will have to reset the tags-table-list or set it when you first use M-. and you'll want to change the language given to find and etags in the 'create-prolog-tags function (as you're probably not using prolog), but otherwise it shouldn't require much customisation.And finally, you will need to run etags once manually, or run 'M-x create-prolog-tags' in order to get the initial TAGS file so that the code knows where you think the appropriate tags file should be.