Skip to content

Commit 2cca689

Browse files
committed
Better gtags-helm support.
Closes #67.
1 parent 3cae8be commit 2cca689

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

drupal-mode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ mode-hook."
922922
(eval-after-load 'eldoc '(require 'drupal/eldoc))
923923
(eval-after-load 'etags '(require 'drupal/etags))
924924
(eval-after-load 'gtags '(require 'drupal/gtags))
925-
(eval-after-load 'helm-gtags '(require 'drupal/gtags))
925+
(eval-after-load 'helm-gtags '(require 'drupal/helm-gtags))
926926
(eval-after-load 'ggtags '(require 'drupal/ggtags))
927927
(eval-after-load 'ispell '(require 'drupal/ispell))
928928
(eval-after-load 'flymake-phpcs '(require 'drupal/flymake-phpcs))

drupal/helm-gtags.el

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
;;; drupal/helm-gtags.el --- Drupal-mode support for helm-gtags
2+
3+
;; Copyright (C) 2012, 2013, 2014, 2015, 2016 Arne Jørgensen
4+
5+
;; Author: Arne Jørgensen <[email protected]>
6+
7+
;; This file is part of Drupal mode.
8+
9+
;; Drupal mode is free software: you can redistribute it and/or modify
10+
;; it under the terms of the GNU General Public License as published
11+
;; by the Free Software Foundation, either version 3 of the License,
12+
;; or (at your option) any later version.
13+
14+
;; Drupal mode is distributed in the hope that it will be useful, but
15+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
16+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
;; General Public License for more details.
18+
19+
;; You should have received a copy of the GNU General Public License
20+
;; along with Drupal mode. If not, see <http://www.gnu.org/licenses/>.
21+
22+
;;; Commentary:
23+
24+
;; Enable drupal-mode support for helm-gtags.
25+
26+
;;; Code:
27+
28+
(require 'helm-gtags)
29+
30+
(defvar drupal/helm-gtags-global-command (executable-find "global")
31+
"Name of the GNU GLOBAL `global' executable.
32+
Include path to the executable if it is not in your $PATH.")
33+
34+
(defun drupal/helm-gtags-enable ()
35+
"Setup rootdir for helm-gtags."
36+
(let ((dir (locate-dominating-file (or buffer-file-name default-directory) "GTAGS")))
37+
(when dir
38+
(set (make-local-variable 'helm-gtags--tag-location) dir)
39+
40+
;; Set `drupal-symbol-collection' to a call to
41+
;; `gtags-completing-gtags' so that inserting hooks will do
42+
;; completion based on gtags.
43+
(setq drupal-symbol-collection #'(lambda() (helm-gtags--complete 'tag "" nil t)))
44+
(setq drupal-get-function-args #'drupal/helm-gtags-get-function-args)
45+
(helm-gtags-mode 1))))
46+
47+
(defun drupal/helm-gtags-get-function-args (symbol &optional version)
48+
"Get function arguments from GNU GLOBAL."
49+
(when (file-exists-p (concat helm-gtags--tag-location "GTAGS"))
50+
(with-temp-buffer
51+
(ignore-errors
52+
(call-process drupal/helm-gtags-global-command nil t nil "-x" symbol)
53+
(goto-char (point-min))
54+
(search-forward-regexp "[^(]*(\\(.*\\))[^)]*" nil t)
55+
(match-string-no-properties 1)))))
56+
57+
(add-hook 'drupal-mode-hook #'drupal/helm-gtags-enable)
58+
59+
60+
61+
(provide 'drupal/helm-gtags)
62+
63+
;;; drupal/helm-gtags.el ends here

0 commit comments

Comments
 (0)