65a66,68 > (eval-when-compile > (require 'cl)) > 113a117,143 > > (defconst gtags-default-error ": tag not found") > > (defvar gtags-flag-table > ;; name > `((symbol "s" "(S)" ": symbol not found") > (context "c" "(CONTEXT)" ,gtags-default-error) > (grep "g" "(GREP)" ": pattern not found") > (idutils "I" "(IDUTILS)" ": token not found") > (path "P" "(P)" ": path not found") > (reference "r" "(Ref)" ,gtags-default-error) > ;; optional flags > (local "l" "(local)")) > " table of legitimate flags") > > (defmacro gtags-flag-sym (flag) > `(car ,flag)) > > (defmacro gtags-flag-cmd-line-arg (flag) > `(cadr ,flag)) > > (defmacro gtags-flag-prefix-msg (flag) > `(caddr ,flag)) > > (defmacro gtags-flag-err-msg (flag) > `(cadddr ,flag)) > 296c326 < (gtags-goto-tag tagname "" other-win))) --- > (gtags-goto-tag tagname nil other-win))) 303c333,336 < (defun gtags-find-rtag () --- > (defmacro concat-local-macro (local) > `(if ,local (assq 'local gtags-flag-table))) > > (defun gtags-find-rtag (tagname &optional local) 305,316c338,350 < (interactive) < (let (tagname prompt input) < (setq tagname (gtags-current-token)) < (if tagname < (setq prompt (concat "Find tag (reference): (default " tagname ") ")) < (setq prompt "Find tag (reference): ")) < (setq input (completing-read prompt 'gtags-completing-gtags < nil nil nil gtags-history-list)) < (if (not (equal "" input)) < (setq tagname input)) < (gtags-push-context) < (gtags-goto-tag tagname "r"))) --- > (interactive > (let (tagname prompt input) > (setq tagname (gtags-current-token)) > (if tagname > (setq prompt (concat "Find tag (reference): (default " tagname ") ")) > (setq prompt "Find tag (reference): ")) > (setq input (completing-read prompt 'gtags-completing-gtags > nil nil nil gtags-history-list)) > (if (not (equal "" input)) (setq tagname input)) > (list tagname current-prefix-arg))) > (gtags-push-context) > (gtags-goto-tag tagname (list (assq 'reference gtags-flag-table) > (concat-local-macro local)))) 318c352 < (defun gtags-find-symbol () --- > (defun gtags-find-symbol (tagname &optional local) 320,328c354,363 < (interactive) < (let (tagname prompt input) < (setq tagname (gtags-current-token)) < (if tagname < (setq prompt (concat "Find symbol: (default " tagname ") ")) < (setq prompt "Find symbol: ")) < (setq input (completing-read prompt 'gtags-completing-gsyms < nil nil nil gtags-history-list)) < (if (not (equal "" input)) (setq tagname input)) --- > (interactive > (let (tagname prompt input) > (setq tagname (gtags-current-token)) > (if tagname > (setq prompt (concat "Find symbol: (default " tagname ") ")) > (setq prompt "Find symbol: ")) > (setq input (completing-read prompt 'gtags-completing-gsyms > nil nil nil gtags-history-list)) > (if (not (equal "" input)) (setq tagname input)) > (list tagname current-prefix-arg))) 330c365,367 < (gtags-goto-tag tagname "s"))) --- > (message "local: %s" local) > (gtags-goto-tag tagname (list (assq 'symbol gtags-flag-table) > (concat-local-macro local)))) 340c377 < (gtags-find-with "g")) --- > (gtags-find-with (list (assq 'grep gtags-flag-table)))) 345c382 < (gtags-find-with "I")) --- > (gtags-find-with (list (assq 'grep gtags-flag-table)))) 347c384 < (defun gtags-find-file () --- > (defun gtags-find-file (tagname &optional local) 349,355c386,393 < (interactive) < (let (tagname prompt input) < (setq prompt "Find files: ") < (setq input (read-string prompt)) < (if (not (equal "" input)) (setq tagname input)) < (gtags-push-context) < (gtags-goto-tag tagname "P"))) --- > (interactive > (let (tagname input) > (setq input (read-string "Find files: ")) > (if (not (equal "" input)) (setq tagname input)) > (list tagname current-prefix-arg))) > (gtags-push-context) > (gtags-goto-tag tagname (list (assq 'path gtags-flag-table) > (concat-local-macro local)))) 357c395 < (defun gtags-parse-file () --- > (defun gtags-parse-file (tagname &optional local) 359,365c397,405 < (interactive) < (let (tagname prompt input) < (setq input (read-file-name "Parse file: " < nil nil t (file-name-nondirectory buffer-file-name))) < (if (not (equal "" input)) (setq tagname input)) < (gtags-push-context) < (gtags-goto-tag tagname "f"))) --- > (interactive > (let (tagname prompt input) > > (setq input (read-file-name "Parse file: " > nil nil t (file-name-nondirectory buffer-file-name))) > (if (not (equal "" input)) (setq tagname input)) > (list tagname current-prefix-arg))) > (gtags-push-context) > (gtags-goto-tag tagname "f")) 367c407 < (defun gtags-find-tag-from-here () --- > (defun gtags-find-tag-from-here (tagname &optional local) 369,375c409,416 < (interactive) < (let (tagname flag) < (setq tagname (gtags-current-token)) < (if (not tagname) < nil < (gtags-push-context) < (gtags-goto-tag tagname "C")))) --- > (interactive > (let (tagname flag) > (setq tagname (gtags-current-token)) > (list tagname current-prefix-arg))) > (when tagname > (gtags-push-context) > (gtags-goto-tag tagname (list (assq 'context gtags-flag-table) > (concat-local-macro local))))) 396,397c437 < (progn (setq tagname "main") < (setq flag "")) --- > (setq tagname "main") 404c444 < (setq flag "C")) --- > (setq flag (assq 'context gtags-flag-table))) 408c448 < (gtags-goto-tag tagname flag)))) --- > (gtags-goto-tag tagname (list flag))))) 458c498 < (defun gtags-find-with (flag) --- > (defun gtags-find-with (flags) 468c508 < (gtags-goto-tag tagname flag))) --- > (gtags-goto-tag tagname flags))) 471,474c511,514 < (defun gtags-goto-tag (tagname flag &optional other-win) < (let (option context save prefix buffer lines) < (setq save (current-buffer)) < ; Use always ctags-x format. --- > (defun gtags-goto-tag (tagname flags &optional other-win) > (let (option context prev-buffer prefix buffer process-result lines) > (setq prev-buffer (current-buffer)) > ;; Use always ctags-x format. 476,492c516,521 < (if (equal flag "C") < (setq context (concat "--from-here=" (number-to-string (gtags-current-lineno)) ":" buffer-file-name)) < (setq option (concat option flag))) < (cond < ((equal flag "C") < (setq prefix "(CONTEXT)")) < ((equal flag "P") < (setq prefix "(P)")) < ((equal flag "g") < (setq prefix "(GREP)")) < ((equal flag "I") < (setq prefix "(IDUTILS)")) < ((equal flag "s") < (setq prefix "(S)")) < ((equal flag "r") < (setq prefix "(R)")) < (t (setq prefix "(D)"))) --- > (dolist (flag flags) > (if (equal (gtags-flag-sym flag) 'context) > (setq context (concat "--from-here=" (number-to-string (gtags-current-lineno)) ":" buffer-file-name)) > (setq option (concat option (gtags-flag-cmd-line-arg flag)))) > (setq prefix (concat prefix (gtags-flag-prefix-msg flag)))) > 495,510c524,534 < (set-buffer buffer) < ; < ; Path style is defined in gtags-path-style: < ; root: relative from the root of the project (Default) < ; relative: relative from the current directory < ; absolute: absolute (relative from the system root directory) < ; < (cond < ((equal gtags-path-style 'absolute) < (setq option (concat option "a"))) < ((equal gtags-path-style 'root) < (let (rootdir) < (if gtags-rootdir < (setq rootdir gtags-rootdir) < (setq rootdir (gtags-get-rootpath))) < (if rootdir (cd rootdir))))) --- > > ;; Path style is defined in gtags-path-style: > ;; root: relative from the root of the project (Default) > ;; relative: relative from the current directory > ;; absolute: absolute (relative from the system root directory) > ;; > (cond ((equal gtags-path-style 'absolute) (setq option (concat option "a"))) > ((and (equal gtags-path-style 'root) (not (assq 'local flags))) > (let ((rootdir (or gtags-rootdir (gtags-get-rootpath)))) > (if rootdir (cd rootdir))))) > 512,542c536,565 < (if (not (= 0 (if (equal flag "C") < (call-process "global" nil t nil option context tagname) < (call-process "global" nil t nil option tagname)))) < (progn (message (buffer-substring (point-min)(1- (point-max)))) < (gtags-pop-context)) < (goto-char (point-min)) < (setq lines (count-lines (point-min) (point-max))) < (cond < ((= 0 lines) < (cond < ((equal flag "P") < (message "%s: path not found" tagname)) < ((equal flag "g") < (message "%s: pattern not found" tagname)) < ((equal flag "I") < (message "%s: token not found" tagname)) < ((equal flag "s") < (message "%s: symbol not found" tagname)) < (t < (message "%s: tag not found" tagname))) < (gtags-pop-context) < (kill-buffer buffer) < (set-buffer save)) < ((= 1 lines) < (message "Searching %s ... Done" tagname) < (gtags-select-it t other-win)) < (t < (if (null other-win) < (switch-to-buffer buffer) < (switch-to-buffer-other-window buffer)) < (gtags-select-mode)))))) --- > > (setq process-result (if context > (start-process "gtags" buffer "global" option context tagname) > (start-process "gtags" buffer "global" option tagname))) > (lexical-let ((other-win other-win) (flags flags) (tagname tagname) gtags-process-sentinel) > (defun gtags-process-sentinel (process event) > (let ((prev-buf (current-buffer)) > (buf (process-buffer process))) > (message "process: %s event: %s" process event) > (cond ((string-match "finished" event) > (set-buffer buf) > (goto-char (point-min)) > (setq lines (count-lines (point-min) (point-max))) > (cond ((= 0 lines) > (message (concat "%s" (gtags-flag-err-msg (car flags))) tagname) > (gtags-pop-context) > (kill-buffer buf) > (set-buffer prev-buf)) > ((= 1 lines) > (message "Searching %s ... Done" tagname) > (gtags-select-it t other-win)) > (t (if (null other-win) > (switch-to-buffer buf) > (switch-to-buffer-other-window buf)) > (gtags-select-mode)))) > ;; otherwise assume failure > (t (message "failure") > (message (buffer-substring (point-min) (1- (point-max)))) > (gtags-pop-context))))) > (set-process-sentinel process-result 'gtags-process-sentinel))))