Ergus / gtags-mode

Gnu Global integration for emacs as simple as possible with TRAMP support.
14 stars 7 forks source link

gtags-mode--after-save-hook should check whether we are in GLOBAL project #7

Open mandarm opened 1 week ago

mandarm commented 1 week ago

Whenever gtags-mode is enabled, gtags-mode--after-save-hook is added to after-save-hook, and runs every time a buffer is saved. This results in spurious error messages like

process-file: Setting current directory: Not a directory

when I am editing files that are not part of any project tagged with GNU global.

Please consider whether it would be a good idea to replace the following condition at the beginning of gtags-mode--after-save-hook

(when (and buffer-file-name

with something like

(when (and (gtags-root-dir) buffer-file-name

http://www.emacswiki.org/emacs/GnuGlobal contains the gtags-root-dir function.

  (defun gtags-root-dir ()
  "Returns GTAGS root directory or nil if doesn't exist."
  (with-temp-buffer
    (if (zerop (call-process "global" nil t nil "-pr"))
        (buffer-substring (point-min) (1- (point-max)))
      nil)))
mandarm commented 1 week ago

I'm sorry, I think your code already tries to determine the project root, and store it in a property list, but I did not fully understand your code. Here are some errors from the Messages buffer that may help to identify where things go wrong, if I save a file that is not a part of any project.

gtags-mode: Global sync error output: global: GTAGS not found. gtags-mode: Sync /bin/global (--print-dbpath): exited abnormally with code 3