Skip to content

Commit 97b6019

Browse files
committed
Improved rootdir detection for etags and gtags.
No need to rely on `drupal-rootdir`. Use root directories based on the TAGS and GTAGS files.
1 parent 4adeb0c commit 97b6019

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

drupal/emacs-drush.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;; drupal/emacs-drush.el --- Drupal-mode support for Drush utilities for Emacs users
22

3-
;; Copyright (C) 2012 Arne Jørgensen
3+
;; Copyright (C) 2012, 2013 Arne Jørgensen
44

55
;; Author: Arne Jørgensen <[email protected]>
66

@@ -47,11 +47,12 @@ Requires `Drush utilities for Emacs users' to be installed."
4747
(defun drupal/emacs-drush-run-after-save ()
4848
"Run drush etags/gtags on after-save-hook."
4949
(when (and drupal/emacs-drush-update-tags-after-save
50-
(boundp 'drupal-rootdir)
5150
drupal-drush-program)
52-
(when (file-exists-p (concat drupal-rootdir "TAGS"))
51+
(when (and (boundp 'drupal/etags-rootdir)
52+
(file-exists-p (concat drupal/etags-rootdir "TAGS")))
5353
(call-process drupal-drush-program nil 0 nil "etags"))
54-
(when (file-exists-p (concat drupal-rootdir "GTAGS"))
54+
(when (and (boundp 'gtags-rootdir)
55+
(file-exists-p (concat gtags-rootdir "GTAGS")))
5556
(call-process drupal-drush-program nil 0 nil "gtags"))))
5657

5758
(defun drupal/emacs-drush-enable ()

drupal/etags.el

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;; drupal/etags.el --- Drupal-mode support for etags
22

3-
;; Copyright (C) 2012 Arne Jørgensen
3+
;; Copyright (C) 2012, 2013 Arne Jørgensen
44

55
;; Author: Arne Jørgensen <[email protected]>
66

@@ -29,23 +29,25 @@
2929
(require 'drupal/emacs-drush)
3030

3131
(defun drupal/etags-enable ()
32-
"Setup TAGS file for etags if it exists in DRUPAL_ROOT."
33-
(when (and (boundp 'drupal-rootdir)
34-
(file-exists-p (concat drupal-rootdir "TAGS")))
35-
;; Set `tags-file-name' to the TAGS file located in
36-
;; `drupal-rootdir'.
37-
(setq tags-file-name (concat drupal-rootdir "TAGS"))
38-
(tags-completion-table)
39-
40-
;; Set `drupal-symbol-collection' to `tags-completion-table' so
41-
;; that inserting hooks will do completion based on etags.
42-
(setq drupal-get-function-args #'drupal/etags-get-function-args)
43-
(setq drupal-symbol-collection #'tags-completion-table)))
32+
"Setup TAGS file for etags if it exists."
33+
(let ((dir (locate-dominating-file (buffer-file-name) "TAGS")))
34+
(when dir
35+
(set (make-local-variable 'drupal/etags-rootdir) dir)
36+
37+
;; Set `tags-file-name' to the TAGS file located in
38+
;; `drupal-rootdir'.
39+
(setq tags-file-name (concat drupal/etags-rootdir "TAGS"))
40+
(tags-completion-table)
41+
42+
;; Set `drupal-symbol-collection' to `tags-completion-table' so
43+
;; that inserting hooks will do completion based on etags.
44+
(setq drupal-get-function-args #'drupal/etags-get-function-args)
45+
(setq drupal-symbol-collection #'tags-completion-table))))
4446

4547
(defun drupal/etags-get-function-args (symbol &optional version)
4648
"Get function arguments from etags TAGS."
47-
(when (and (boundp 'drupal-rootdir)
48-
(file-exists-p (concat drupal-rootdir "TAGS")))
49+
(when (and (boundp 'drupal/etags-rootdir)
50+
(file-exists-p (concat drupal/etags-rootdir "TAGS")))
4951
(with-current-buffer (find-tag-noselect symbol nil nil)
5052
(goto-char (point-min))
5153
(when (re-search-forward

drupal/gtags.el

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@
3535
Include path to the executable if it is not in your $PATH.")
3636

3737
(defun drupal/gtags-enable ()
38-
"Setup rootdir for gtags to be DRUPAL_ROOT."
39-
(when (and (boundp 'drupal-rootdir)
40-
(file-exists-p (concat drupal-rootdir "GTAGS")))
41-
(setq gtags-rootdir drupal-rootdir)
42-
43-
;; Set `drupal-symbol-collection' to a call to
44-
;; `gtags-completing-gtags' so that inserting hooks will do
45-
;; completion based on gtags.
46-
(setq drupal-symbol-collection #'(lambda() (gtags-completing-gtags "" nil t)))
47-
(setq drupal-get-function-args #'drupal/gtags-get-function-args)
48-
(gtags-mode 1)))
38+
"Setup rootdir for gtags."
39+
(let ((dir (locate-dominating-file (buffer-file-name) "GTAGS")))
40+
(when dir
41+
(set (make-local-variable 'gtags-rootdir) dir)
42+
43+
;; Set `drupal-symbol-collection' to a call to
44+
;; `gtags-completing-gtags' so that inserting hooks will do
45+
;; completion based on gtags.
46+
(setq drupal-symbol-collection #'(lambda() (gtags-completing-gtags "" nil t)))
47+
(setq drupal-get-function-args #'drupal/gtags-get-function-args)
48+
(gtags-mode 1))))
4949

5050
(defun drupal/gtags-get-function-args (symbol &optional version)
5151
"Get function arguments from GNU GLOBAL."
52-
(when (and (boundp 'drupal-rootdir)
53-
(file-exists-p (concat drupal-rootdir "GTAGS")))
52+
(when (and (boundp 'gtags-rootdir)
53+
(file-exists-p (concat gtags-rootdir "GTAGS")))
5454
(with-temp-buffer
5555
(ignore-errors
5656
(call-process drupal/gtags-global-command nil t nil "-x" symbol)

0 commit comments

Comments
 (0)