[EMAIL PROTECTED] wrote: > I am using the Emacs interface to the GNU GLOBAL source code tagging > system and it works mostly great for me. I am however a bit unsatisfied > with its ruff behaviour when doing incremental updates when a buffer is > saved into a file from Emacs. In order for it to work properly during > the development process I want the database to be updated every time I > save the buffer to a file. I have solved this in the following way: ... > I have, however, a feeling that this is a bit complicated solution. > Does anyone have a better idea? If not, I still hope the code can be of > use to other uses of global from emacs.
I can't critique the overall approach, but I think it could be improved in minor ways (like using after-save-hook instead of rebinding C-x C-s): (when (locate-library "gtags") (autoload 'gtags-mode "gtags" nil t) (when (executable-find "global") (defadvice gtags-visit-rootdir (after make-complete-list activate) "Rebuilds completion list when changing GLOBAL database rootdir." (gtags-make-complete-list)) (defun gtags-global-dir-p (dir) "Return non-nil if directory DIR contains a GLOBAL database." (and (file-exists-p (expand-file-name "GPATH" dir)) (file-exists-p (expand-file-name "GRTAGS" dir)) (file-exists-p (expand-file-name "GSYMS" dir)) (file-exists-p (expand-file-name "GTAGS" dir)))) (defun gtags-global-dir (&optional dir) "Return the nearest super directory that contains a GLOBAL database." (interactive) (when (null dir) (setq dir default-directory)) (cond ((gtags-global-dir-p dir) dir) ((equal (file-truename dir) (file-truename "/")) nil) (t (gtags-global-dir (file-name-as-directory (expand-file-name ".." dir)))))) (defvar gtags-global-complete-list-obsolete-flag nil "When non-nil, the GLOBAL complete list should be rebuilt.") (defun gtags-global-update () "If current directory is part of a GLOBAL database update it." (interactive) (when (gtags-global-dir) (if (equal (call-process "global" nil nil nil "-vu") 0) (setq gtags-global-complete-list-obsolete-flag t) (error "global database update failed")))) (defun gtags-global-complete-list-maybe () "Rebuild the GLOBAL complete list when indicated. See `gtags-global-complete-list-obsolete-flag'." (interactive) (when gtags-global-complete-list-obsolete-flag (gtags-make-complete-list) (setq gtags-global-complete-list-obsolete-flag nil))) (add-hook 'gtags-mode-hook (lambda () (add-hook 'after-save-hook 'gtags-global-update nil t) (defadvice gtags-find-tag (before gtags-global-complete-list-maybe activate) (gtags-global-complete-list-maybe)) (defadvice gtags-find-rtag (before gtags-global-complete-list-maybe activate) (gtags-global-complete-list-maybe)) (defadvice gtags-find-symbol (before gtags-global-complete-list-maybe activate) (gtags-global-complete-list-maybe)) (defadvice gtags-find-pattern (before gtags-global-complete-list-maybe activate) (gtags-global-complete-list-maybe)) (defadvice gtags-find-with-grep (before gtags-global-complete-list-maybe activate) (gtags-global-complete-list-maybe)) (defadvice gtags-find-with-idutils (before gtags-global-complete-list-maybe activate) (gtags-global-complete-list-maybe)) (defadvice gtags-find-file (before gtags-global-complete-list-maybe activate) (gtags-global-complete-list-maybe)) (defadvice gtags-parse-file (before gtags-global-complete-list-maybe activate) (gtags-global-complete-list-maybe)) (defadvice gtags-find-tag-from-here (before gtags-global-complete-list-maybe activate) (gtags-global-complete-list-maybe)) ) ; (lambda () ...) ) ; (add-hook 'gtags-mode-hook ...) ) ; (when (executable-find "global") ...) ;; Use gtags in all modes for now. (gtags-mode 1) ) ; (when (locate-library "gtags") ...) -- Kevin Rodgers _______________________________________________ Help-gnu-emacs mailing list Help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs