branch: elpa/drupal-mode
commit 97b60197d00b29e3fc47a38b79ccfbc4a0e4ff64
Author: Arne Jørgensen <[email protected]>
Commit: Arne Jørgensen <[email protected]>
Improved rootdir detection for etags and gtags.
No need to rely on `drupal-rootdir`. Use root directories based on the
TAGS and GTAGS files.
---
drupal/emacs-drush.el | 9 +++++----
drupal/etags.el | 32 +++++++++++++++++---------------
drupal/gtags.el | 26 +++++++++++++-------------
3 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/drupal/emacs-drush.el b/drupal/emacs-drush.el
index df7d808682..d483e6c2ee 100644
--- a/drupal/emacs-drush.el
+++ b/drupal/emacs-drush.el
@@ -1,6 +1,6 @@
;;; drupal/emacs-drush.el --- Drupal-mode support for Drush utilities for
Emacs users
-;; Copyright (C) 2012 Arne Jørgensen
+;; Copyright (C) 2012, 2013 Arne Jørgensen
;; Author: Arne Jørgensen <[email protected]>
@@ -47,11 +47,12 @@ Requires `Drush utilities for Emacs users' to be installed."
(defun drupal/emacs-drush-run-after-save ()
"Run drush etags/gtags on after-save-hook."
(when (and drupal/emacs-drush-update-tags-after-save
- (boundp 'drupal-rootdir)
drupal-drush-program)
- (when (file-exists-p (concat drupal-rootdir "TAGS"))
+ (when (and (boundp 'drupal/etags-rootdir)
+ (file-exists-p (concat drupal/etags-rootdir "TAGS")))
(call-process drupal-drush-program nil 0 nil "etags"))
- (when (file-exists-p (concat drupal-rootdir "GTAGS"))
+ (when (and (boundp 'gtags-rootdir)
+ (file-exists-p (concat gtags-rootdir "GTAGS")))
(call-process drupal-drush-program nil 0 nil "gtags"))))
(defun drupal/emacs-drush-enable ()
diff --git a/drupal/etags.el b/drupal/etags.el
index a22b49e0f5..9dfda51d0a 100644
--- a/drupal/etags.el
+++ b/drupal/etags.el
@@ -1,6 +1,6 @@
;;; drupal/etags.el --- Drupal-mode support for etags
-;; Copyright (C) 2012 Arne Jørgensen
+;; Copyright (C) 2012, 2013 Arne Jørgensen
;; Author: Arne Jørgensen <[email protected]>
@@ -29,23 +29,25 @@
(require 'drupal/emacs-drush)
(defun drupal/etags-enable ()
- "Setup TAGS file for etags if it exists in DRUPAL_ROOT."
- (when (and (boundp 'drupal-rootdir)
- (file-exists-p (concat drupal-rootdir "TAGS")))
- ;; Set `tags-file-name' to the TAGS file located in
- ;; `drupal-rootdir'.
- (setq tags-file-name (concat drupal-rootdir "TAGS"))
- (tags-completion-table)
-
- ;; Set `drupal-symbol-collection' to `tags-completion-table' so
- ;; that inserting hooks will do completion based on etags.
- (setq drupal-get-function-args #'drupal/etags-get-function-args)
- (setq drupal-symbol-collection #'tags-completion-table)))
+ "Setup TAGS file for etags if it exists."
+ (let ((dir (locate-dominating-file (buffer-file-name) "TAGS")))
+ (when dir
+ (set (make-local-variable 'drupal/etags-rootdir) dir)
+
+ ;; Set `tags-file-name' to the TAGS file located in
+ ;; `drupal-rootdir'.
+ (setq tags-file-name (concat drupal/etags-rootdir "TAGS"))
+ (tags-completion-table)
+
+ ;; Set `drupal-symbol-collection' to `tags-completion-table' so
+ ;; that inserting hooks will do completion based on etags.
+ (setq drupal-get-function-args #'drupal/etags-get-function-args)
+ (setq drupal-symbol-collection #'tags-completion-table))))
(defun drupal/etags-get-function-args (symbol &optional version)
"Get function arguments from etags TAGS."
- (when (and (boundp 'drupal-rootdir)
- (file-exists-p (concat drupal-rootdir "TAGS")))
+ (when (and (boundp 'drupal/etags-rootdir)
+ (file-exists-p (concat drupal/etags-rootdir "TAGS")))
(with-current-buffer (find-tag-noselect symbol nil nil)
(goto-char (point-min))
(when (re-search-forward
diff --git a/drupal/gtags.el b/drupal/gtags.el
index e2267ac54f..2b7959eadf 100644
--- a/drupal/gtags.el
+++ b/drupal/gtags.el
@@ -35,22 +35,22 @@
Include path to the executable if it is not in your $PATH.")
(defun drupal/gtags-enable ()
- "Setup rootdir for gtags to be DRUPAL_ROOT."
- (when (and (boundp 'drupal-rootdir)
- (file-exists-p (concat drupal-rootdir "GTAGS")))
- (setq gtags-rootdir drupal-rootdir)
-
- ;; Set `drupal-symbol-collection' to a call to
- ;; `gtags-completing-gtags' so that inserting hooks will do
- ;; completion based on gtags.
- (setq drupal-symbol-collection #'(lambda() (gtags-completing-gtags "" nil
t)))
- (setq drupal-get-function-args #'drupal/gtags-get-function-args)
- (gtags-mode 1)))
+ "Setup rootdir for gtags."
+ (let ((dir (locate-dominating-file (buffer-file-name) "GTAGS")))
+ (when dir
+ (set (make-local-variable 'gtags-rootdir) dir)
+
+ ;; Set `drupal-symbol-collection' to a call to
+ ;; `gtags-completing-gtags' so that inserting hooks will do
+ ;; completion based on gtags.
+ (setq drupal-symbol-collection #'(lambda() (gtags-completing-gtags ""
nil t)))
+ (setq drupal-get-function-args #'drupal/gtags-get-function-args)
+ (gtags-mode 1))))
(defun drupal/gtags-get-function-args (symbol &optional version)
"Get function arguments from GNU GLOBAL."
- (when (and (boundp 'drupal-rootdir)
- (file-exists-p (concat drupal-rootdir "GTAGS")))
+ (when (and (boundp 'gtags-rootdir)
+ (file-exists-p (concat gtags-rootdir "GTAGS")))
(with-temp-buffer
(ignore-errors
(call-process drupal/gtags-global-command nil t nil "-x" symbol)