Re: Proposed feature - Optionally generate gtags for gtags-visit-rootdir

Earl Chew <[email protected]>
Newsgroups gmane.comp.gnu.global.bugs
Message-ID <[email protected]>
On 8/10/2015 21:15, Shigio YAMAGUCHI wrote:
> I agree with you.
> No problem with 1).

What do you think about this attempt ?

Earl

--- gtags.el.orig	2015-10-11 10:28:05.269639542 -0700
+++ gtags.el	2015-10-11 11:06:05.468301202 -0700
@@ -197,12 +197,19 @@
    "Root directory of source tree.")
  (defvar gtags-global-command nil
    "Command name of global.")
+(defvar gtags-command nil
+  "Command name of gtags.")

  ;; Set global's command name
  (setq gtags-global-command (getenv "GTAGSGLOBAL"))
  (if (or (not gtags-global-command) (equal gtags-global-command ""))
      (setq gtags-global-command "global"))

+;; Set global's command name
+(setq gtags-command (getenv "GTAGS"))
+(if (or (not gtags-command) (equal gtags-command ""))
+    (setq gtags-command "gtags"))
+
  ;; Key mapping of gtags-mode.
  (if gtags-suggested-key-mapping
      (progn
@@ -512,9 +519,9 @@
  ;;
  ;; interactive command
  ;;
-(defun gtags-visit-rootdir ()
+(defun gtags-visit-rootdir (arg)
    "Tell tags commands the root directory of source tree."
-  (interactive)
+  (interactive "P")
    (let (path input default-path)
      (setq path gtags-rootdir)
      (if (not path)
@@ -530,7 +537,21 @@
        (if (not (file-directory-p input))
          (message "%s is not directory." input)
         (setq gtags-rootdir (expand-file-name input))
-       (setenv "GTAGSROOT" gtags-rootdir)))))
+       (setenv "GTAGSROOT" gtags-rootdir)
+       (when arg
+         (let (stdout)
+           (message "Building gtags %s" gtags-rootdir)
+           (gtags-push-tramp-environment)
+           (setq stdout
+             (shell-command-to-string
+               (format "exec %s"
+                (shell-quote-argument gtags-command))))
+           (gtags-pop-tramp-environment)
+           (message "Built gtags %s%s"
+             gtags-rootdir
+             (if (= 0 (length stdout))
+               ""
+               (concat ": " stdout)))))))))

  (defun gtags-find-tag (&optional other-win)
    "Input tag name and move to the definition."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.