emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/drupal-mode da97264d7e 195/308: Merge branch 'release/0.4.


From: ELPA Syncer
Subject: [nongnu] elpa/drupal-mode da97264d7e 195/308: Merge branch 'release/0.4.1'
Date: Tue, 25 Jan 2022 10:59:47 -0500 (EST)

branch: elpa/drupal-mode
commit da97264d7e37f6d63cbd723a7f60dac7f96a4bc7
Merge: a08207b0c9 95d6ecdd75
Author: Arne Jørgensen <arne@arnested.dk>
Commit: Arne Jørgensen <arne@arnested.dk>

    Merge branch 'release/0.4.1'
---
 Makefile                |   4 +-
 drupal-mode.el          | 196 +++++++++++++++++++++++++++++++-----------------
 drupal/autoinsert.el    |   6 +-
 drupal/emacs-drush.el   |   2 +-
 drupal/etags.el         |   4 +-
 drupal/flycheck.el      |  25 +++---
 drupal/flymake-phpcs.el | 123 ++++++++++++++++++++++++++++--
 drupal/gtags.el         |   4 +-
 drupal/phpcs.el         |   4 +-
 drush-make-mode.el      |   4 +-
 10 files changed, 273 insertions(+), 99 deletions(-)

diff --git a/Makefile b/Makefile
index fa4603b339..808de21563 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@
 
 CASK?=cask
 EMACS?=emacs
-TAR?=bsdtar
+TAR?=COPYFILE_DISABLE=1 bsdtar
 PANDOC?=pandoc --atx-headers
 
 VERSION?=$(shell $(CASK) version)
@@ -46,7 +46,7 @@ $(ARCHIVE_NAME)-pkg.el: $(ARCHIVE_NAME).el
 
 # create a tar ball in package.el format for uploading to 
http://marmalade-repo.org
 $(PACKAGE_NAME).tar: README $(ARCHIVE_NAME).el $(ARCHIVE_NAME)-pkg.el 
$(ARCHIVE_NAME).info dir drupal/*.el drupal-tests.el drush-make-mode.el
-       COPYFILE_DISABLE=1 $(TAR) -c -s "@^@$(PACKAGE_NAME)/@" -f 
$(PACKAGE_NAME).tar $^
+       $(TAR) -c -s "@^@$(PACKAGE_NAME)/@" -f $(PACKAGE_NAME).tar $^
 
 install: $(PACKAGE_NAME).tar
        $(EMACS) --batch -l package -f package-initialize --eval 
"(package-install-file \"$(PWD)/$(PACKAGE_NAME).tar\")"
diff --git a/drupal-mode.el b/drupal-mode.el
index 2773a0203d..c8cb7a8037 100644
--- a/drupal-mode.el
+++ b/drupal-mode.el
@@ -1,11 +1,11 @@
 ;;; drupal-mode.el --- Advanced minor mode for Drupal development
 
-;; Copyright (C) 2012, 2013 Arne Jørgensen
+;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen
 
 ;; Author: Arne Jørgensen <arne@arnested.dk>
 ;; URL: https://github.com/arnested/drupal-mode
 ;; Created: January 17, 2012
-;; Version: 0.3.1
+;; Version: 0.4.1
 ;; Package-Requires: ((php-mode "1.5.0"))
 ;; Keywords: programming, php, drupal
 
@@ -36,8 +36,8 @@
 (require 'php-mode)
 (require 'format-spec)
 
-(eval-when-compile 
-  (require 'css-mode))
+;; Silence byte compiler.
+(defvar css-indent-level)
 
 
 
@@ -62,7 +62,7 @@ If `Ask' ask the user whether to convert line endings.
 
 Drupal coding standards states that all text files should end in
 a single newline (\\n)."
-  :type `(choice 
+  :type `(choice
           :tag " we offer to change line endings if needed?"
           (const :tag "Always" t)
           (const :tag "Never" nil)
@@ -83,7 +83,7 @@ If `Default' do what the global setting is.
 
 Drupal coding standards states that lines should have no trailing
 whitespace at the end."
-  :type `(choice 
+  :type `(choice
           :tag "Whether to delete all the trailing whitespace."
           (const :tag "Always" always)
           (const :tag "Default" default)
@@ -98,6 +98,7 @@ whitespace at the end."
 %s is the search term."
   :type '(choice (const :tag "Api.drupal.org" 
"http://api.drupal.org/api/search/%v/%s";)
                  (const :tag "Api.drupalcontrib.org" 
"http://api.drupalcontrib.org/api/search/%v/%s";)
+                 (const :tag "Api.drupalize.me" 
"http://api.drupalize.me/api/search/%v/%s";)
                  (string :tag "Other" "http://example.com/api/search/%v/%s";))
   :link '(url-link :tag "api.drupalcontrib.org" "http://api.drupalcontrib.org";)
   :link '(url-link :tag "api.drupal.org" "http://api.drupal.org";)
@@ -162,6 +163,36 @@ Include path to the executable if it is not in your $PATH."
   :type '(repeat symbol)
   :group 'drupal)
 
+(defcustom drupal-enable-auto-fill-mode t
+  "Whether to use `auto-fill-mode' Drupal PHP buffers.
+Drupal mode will only do auto fill in comments (auto filling code
+is not nice).
+
+If `Yes' enable `auto-fill-mode' in Drupal PHP mode buffers.
+If `No' don't enable `auto-fill-mode' in Drupal PHP mode buffers 
(`auto-fill-mode' can still be enabled by other settings)."
+  :type `(choice
+          :tag "Enable `auto-fill-mode'."
+          (const :tag "Yes" t)
+          (const :tag "No" nil))
+  :link '(variable-link comment-auto-fill-only-comments)
+  :group 'drupal)
+
+(defcustom drupal-paragraph-separate "^[ 
\t]*\\(\\(/[/\\*]+\\)\\|\\(\\*+/\\)\\|\\(\\*?\\)\\|\\(\\*?[ 
\t]*@[[:alpha:]]+\\([ \t]+.*\\)?\\)\\)[ \t]*$"
+  "Regexp for beginning of a line that separates paragraphs.
+In Drupal mode we extend the regular `paragraph-separate' so we
+will get better filling in Doxygen comments."
+  :type 'regexp
+  :link '(variable-link paragraph-separate)
+  :group 'drupal)
+
+(defcustom drupal-paragraph-start (default-value 'drupal-paragraph-separate)
+  "Regexp for beginning of a line that starts OR separates paragraphs.
+In Drupal mode we extend the regular `paragraph-start' so we will
+get better filling in Doxygen comments."
+  :type 'regexp
+  :link '(variable-link paragraph-start)
+  :group 'drupal)
+
 
 
 (defvar drupal-version nil "Drupal version as auto detected.")
@@ -188,14 +219,23 @@ Include path to the executable if it is not in your 
$PATH."
 (make-variable-buffer-local 'drupal-project)
 (put 'drupal-project 'safe-local-variable 'string-or-null-p)
 
+(defvar drupal-mode-map-alist
+  '((?d . drupal-search-documentation)
+    (?c . drupal-drush-cache-clear)
+    (?h . drupal-insert-hook)
+    (?f . drupal-insert-function)
+    (?m . drupal-module-name)
+    (?t . drupal-wrap-string-in-t-function))
+  "Map of mnemonic keys and functions for keyboard shortcuts.
+See `drupal-mode-map'.")
+
 (defvar drupal-mode-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [(control c) (control v) (control d)] 
#'drupal-search-documentation)
-    (define-key map [(control c) (control v) (control c)] 
#'drupal-drush-cache-clear)
-    (define-key map [(control c) (control v) (control h)] #'drupal-insert-hook)
-    (define-key map [(control c) (control v) (control f)] 
#'drupal-insert-function)
-    (define-key map [(control c) (control v) (control m)] #'drupal-module-name)
-    (define-key map [(control c) (control v) (control t)] 
#'drupal-wrap-string-in-t-function)
+    ;; Iterate `drupal-mode-map-alist' and assign the functions to the
+    ;; mode map on C-c C-v C-`mnemonic-key'.
+    (dolist (elem drupal-mode-map-alist)
+      (define-key map `[(control c) (control v) (control ,(car elem))] (cdr 
elem)))
+
     (define-key map [(control a)] #'drupal-mode-beginning-of-line)
     map)
   "Keymap for `drupal-mode'")
@@ -228,9 +268,6 @@ function arguments.")
   :lighter " Drupal"
   :keymap drupal-mode-map
 
-  ;; Detect drupal version, drupal root, etc.
-  (drupal-detect-drupal-version)
-
   ;; Delete trailing white space.
   (when (eq drupal-delete-trailing-whitespace 'always)
     (add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
@@ -263,7 +300,16 @@ function arguments.")
     ;; Setup cc-mode style stuff.
     (when (derived-mode-p 'c-mode)
       (c-add-language 'drupal-mode 'c-mode)
-      (c-set-style "drupal"))))
+      (c-set-style "drupal"))
+
+    ;; Use `auto-fill' only in comments.
+    (when drupal-enable-auto-fill-mode
+      (set (make-local-variable 'comment-auto-fill-only-comments) t)
+      (auto-fill-mode 1))
+
+    ;; Improve filling in Doxygen comments.
+    (set (make-local-variable 'paragraph-separate) drupal-paragraph-separate)
+    (set (make-local-variable 'paragraph-start) drupal-paragraph-start)))
 
 
 
@@ -497,7 +543,7 @@ It is really slow to download `drupal-search-url'. You 
should
 probably not use this. Have a look at using GNU GLOBAL / Gtags
 instead."
   (unless version
-    (setq version (drupal-detect-drupal-version)))
+    (setq version drupal-version))
   (with-temp-buffer
     (ignore-errors
       (url-insert-file-contents (format-spec drupal-search-url `((?v . 
,version)
@@ -538,23 +584,26 @@ Heavily based on `message-beginning-of-line' from Gnus."
       (set zrs t)))
   (if (derived-mode-p 'conf-mode)
       (let* ((here (point))
-            (bol (progn (beginning-of-line n) (point)))
-            (eol (point-at-eol))
-            (eoh (re-search-forward "= *" eol t)))
-       (goto-char
-        (if (and eoh (or (< eoh here) (= bol here)))
-            eoh bol)))
+             (bol (progn (beginning-of-line n) (point)))
+             (eol (point-at-eol))
+             (eoh (re-search-forward "= *" eol t)))
+        (goto-char
+         (if (and eoh (or (< eoh here) (= bol here)))
+             eoh bol)))
     (beginning-of-line n)))
 
 
 
+(defvar drupal-local-variables (make-hash-table :test 'equal)
+  "Drupal local variables hash table.")
+
 ;; Detect Drupal and Drupal version
 (defun drupal-detect-drupal-version ()
   "Detect if the buffer is part of a Drupal project.
 If part of a Drupal project also detect the version of Drupal and
 the location of DRUPAL_ROOT."
   (interactive)
-  (hack-local-variables)
+  (drupal-hack-local-variables)
   (when (or (not drupal-version)
             (not drupal-rootdir))
     (dolist (file '("modules/system/system.module" "includes/bootstrap.inc" 
"core/lib/Drupal.php"))
@@ -562,55 +611,68 @@ the location of DRUPAL_ROOT."
         (when here
           (let ((dir (locate-dominating-file here file)))
             (when dir
-              (with-current-buffer (find-file-noselect (concat dir file) t)
-                (save-excursion
-                  (widen)
-                  (goto-char (point-min))
-                  (when (re-search-forward "\\(define('VERSION',\\|const 
VERSION =\\) +'\\(.+\\)'" nil t)
-                    (dir-locals-set-class-variables 'drupal-site `((nil . 
((drupal-version . ,(match-string-no-properties 2))
-                                                                           
(drupal-rootdir . ,dir)))))
-                    (dir-locals-set-directory-class dir 'drupal-site)))
-                (setq drupal-version (match-string-no-properties 2))))))))
-    (hack-local-variables))
+              (with-temp-buffer
+                (insert-file-contents-literally (concat dir file))
+                (goto-char (point-min))
+                (when (re-search-forward "\\(define('VERSION',\\|const VERSION 
=\\) +'\\(.+\\)'" nil t)
+                  (setq drupal-version (match-string-no-properties 2))
+                  (puthash (expand-file-name dir) `((drupal-version . 
,drupal-version)
+                                                    (drupal-rootdir . ,dir))
+                           drupal-local-variables)))))))))
+  (drupal-hack-local-variables)
   (let ((module (drupal-locate-dominating-module (or buffer-file-name 
default-directory) t))
         (version drupal-version)
         (module-name nil)
         (module-version nil)
         (project nil))
     (when module
-      (with-current-buffer (find-file-noselect module t)
-        (save-excursion
-          (widen)
-          (goto-char (point-min))
-          (when (and (not drupal-version)
-                     (re-search-forward "^core *=" nil t))
-            (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
-            (setq version (match-string-no-properties 1)))
-          (goto-char (point-min))
-          (when (re-search-forward "^name *=" nil t)
-            (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
-            (setq module-name (match-string-no-properties 1)))
-          (goto-char (point-min))
-          (when (re-search-forward "^version *=" nil t)
-            (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
-            (setq module-version (match-string-no-properties 1)))
-          (goto-char (point-min))
-          (when (re-search-forward "^project *=" nil t)
-            (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
-            (setq project (match-string-no-properties 1)))
-          (when (and (string= project "drupal")
-                     (string= module-version "VERSION"))
-            (setq module-version version))))
-      (dir-locals-set-class-variables 'drupal-module `((nil . ((drupal-module 
. ,(file-name-nondirectory
-                                                                               
   (file-name-sans-extension module)))
-                                                               (drupal-version 
. ,version)
-                                                               
(drupal-module-name . ,module-name)
-                                                               
(drupal-module-version . ,module-version)
-                                                               (drupal-project 
. ,project)))))
-      (dir-locals-set-directory-class (file-name-directory module) 
'drupal-module)))
-  (hack-local-variables)
+      (with-temp-buffer
+        (insert-file-contents-literally module)
+        (goto-char (point-min))
+        (when (and (not drupal-version)
+                   (re-search-forward "^core *=" nil t))
+          (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
+          (setq version (match-string-no-properties 1)))
+        (goto-char (point-min))
+        (when (re-search-forward "^name *=" nil t)
+          (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
+          (setq module-name (match-string-no-properties 1)))
+        (goto-char (point-min))
+        (when (re-search-forward "^version *=" nil t)
+          (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
+          (setq module-version (match-string-no-properties 1)))
+        (goto-char (point-min))
+        (when (re-search-forward "^project *=" nil t)
+          (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
+          (setq project (match-string-no-properties 1)))
+        (when (and (string= project "drupal")
+                   (string= module-version "VERSION"))
+          (setq module-version version))
+        (puthash (expand-file-name (file-name-directory module)) 
`((drupal-module . ,(file-name-nondirectory
+                                                                               
       (file-name-sans-extension module)))
+                                                                   
(drupal-version . ,version)
+                                                                   
(drupal-module-name . ,module-name)
+                                                                   
(drupal-module-version . ,module-version)
+                                                                   
(drupal-project . ,project))
+                 drupal-local-variables))))
+  (drupal-hack-local-variables)
   drupal-version)
 
+(defun drupal-hack-local-variables ()
+  "Drupal hack `drupal-local-variables' as buffer local variables."
+  (interactive)
+  (let ((dir (expand-file-name (or (file-name-directory buffer-file-name) 
default-directory)))
+        matches)
+    (maphash (lambda (key value)
+               (when (string-match (concat "^" (regexp-quote key)) dir)
+                 (add-to-list 'matches key)))
+             drupal-local-variables)
+    (sort matches #'(lambda (a b) (> (string-width a) (string-width b))))
+    (dolist (elem matches)
+      (let ((vars (gethash elem drupal-local-variables)))
+        (dolist (var vars)
+          (set (make-local-variable (car var)) (cdr-safe var)))))))
+
 (defun drupal-locate-dominating-module (file &optional info-file-location)
   "Look up the directory hierarchy from FILE for a Drupal module root.
 Stop at the first parent where a matching module is found and
@@ -666,7 +728,7 @@ Used in `drupal-insert-hook' and `drupal-insert-function'."
                                         drupal-module
                                       ;; Otherwise fall back to a very naive
                                       ;; way of guessing the module name.
-                                      (file-name-nondirectory 
(file-name-sans-extension (buffer-file-name)))))))
+                                      (file-name-nondirectory 
(file-name-sans-extension (or buffer-file-name (buffer-name))))))))
     (if (called-interactively-p 'any)
         (insert name)
       name)))
@@ -675,7 +737,7 @@ Used in `drupal-insert-hook' and `drupal-insert-function'."
   "Return major version number of version string.
 If major version number is 4 - return both major and minor."
   (unless version
-    (setq version (drupal-detect-drupal-version)))
+    (setq version drupal-version))
   (when version
     (let ((version-list (split-string version "\\.")))
       (if (= (string-to-number (car version-list)) 4)
diff --git a/drupal/autoinsert.el b/drupal/autoinsert.el
index 751bbdcaa6..1aa29d8472 100644
--- a/drupal/autoinsert.el
+++ b/drupal/autoinsert.el
@@ -1,9 +1,9 @@
 ;;; drupal/autoinsert.el --- Drupal-mode support for `auto-insert-mode'
 
-;; Copyright (C) 2012, 2013  Arne Jørgensen
+;; Copyright (C) 2012, 2013, 2014  Arne Jørgensen
 
 ;; Author: Arne Jørgensen <arne@arnested.dk>
-;; Keywords: 
+;; Keywords:
 
 ;; This file is part of Drupal mode.
 
@@ -34,7 +34,7 @@
 (define-skeleton drupal/autoinsert-insert-info-skeleton
   "Drupal info file skeleton."
   nil
-  '(setq v1 (file-name-nondirectory (file-name-sans-extension 
(buffer-file-name))))
+  '(setq v1 (file-name-nondirectory (file-name-sans-extension (or 
buffer-file-name (buffer-name)))))
   '(setq v2 (if (drupal-major-version) (>= (string-to-number 
(drupal-major-version)) 7) t))
   "name = " @ - (upcase-initials (replace-regexp-in-string "[-_\\.]+" " " v1)) 
\n
   "description = " @ \n
diff --git a/drupal/emacs-drush.el b/drupal/emacs-drush.el
index bc6245278c..dad8c5774e 100644
--- a/drupal/emacs-drush.el
+++ b/drupal/emacs-drush.el
@@ -38,7 +38,7 @@
 On `after-save-hook' run `drush etags' or `drush gtags'.
 
 Requires `Drush utilities for Emacs users' to be installed."
-  :type `(choice 
+  :type `(choice
           (const :tag "Yes" t)
           (const :tag "No" nil))
   :link '(url-link :tag "Drush utilities for Emacs users" 
"https://drupal.org/project/emacs_drush";)
diff --git a/drupal/etags.el b/drupal/etags.el
index ee2251154a..6c23a7e216 100644
--- a/drupal/etags.el
+++ b/drupal/etags.el
@@ -1,6 +1,6 @@
 ;;; drupal/etags.el --- Drupal-mode support for etags
 
-;; Copyright (C) 2012, 2013 Arne Jørgensen
+;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen
 
 ;; Author: Arne Jørgensen <arne@arnested.dk>
 
@@ -29,7 +29,7 @@
 
 (defun drupal/etags-enable ()
   "Setup TAGS file for etags if it exists."
-  (let ((dir (locate-dominating-file (buffer-file-name) "TAGS")))
+  (let ((dir (locate-dominating-file (or buffer-file-name default-directory) 
"TAGS")))
     (when dir
       (set (make-local-variable 'drupal/etags-rootdir) dir)
 
diff --git a/drupal/flycheck.el b/drupal/flycheck.el
index 1aef618e9e..84d5da1a46 100644
--- a/drupal/flycheck.el
+++ b/drupal/flycheck.el
@@ -1,6 +1,6 @@
 ;;; drupal/flycheck.el --- Drupal-mode support for flycheck and phpcs
 
-;; Copyright (C) 2012, 2013 Arne Jørgensen
+;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen
 
 ;; Author: Thomas Fini Hansen <xen@xen.dk>
 
@@ -25,6 +25,7 @@
 
 ;;; Code:
 
+(require 'flycheck)
 (require 'drupal/phpcs)
 
 (defcustom drupal/flycheck-phpcs-js-and-css t
@@ -44,31 +45,37 @@
 
     ;; Flycheck will also highlight trailing whitespace as an
     ;; error so no need to highlight it twice.
-    (drupal/phpcs-dont-show-trailing-whitespace)))
+    (when (fboundp 'drupal/phpcs-dont-show-trailing-whitespace)
+      (drupal/phpcs-dont-show-trailing-whitespace))))
 
 (add-hook 'drupal-mode-hook #'drupal/flycheck-hook)
 
-(flycheck-declare-checker css-js-phpcs
+(flycheck-define-checker css-js-phpcs
   "Check CSS and JavaScript  using PHP_CodeSniffer.
 
 PHP_CodeSniffer can be used to check non-PHP files, as exemplified by the
 Drupal code sniffer.
 
 See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
-  :command '("phpcs" "--report=emacs"
-             (option "--standard=" flycheck-phpcs-standard)
-             source)
+  :command ("phpcs" "--report=emacs"
+            (option "--standard=" flycheck-phpcs-standard)
+            source)
   ;; Though phpcs supports Checkstyle output which we could feed to
   ;; `flycheck-parse-checkstyle', we are still using error patterns here,
   ;; because PHP has notoriously unstable output habits.  See URL
   ;; `https://github.com/lunaryorn/flycheck/issues/78' and URL
   ;; `https://github.com/lunaryorn/flycheck/issues/118'
   :error-patterns
-  '(("\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): error - \\(?4:.*\\)" error)
-    ("\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): warning - \\(?4:.*\\)" 
warning))
-  :modes '(css-mode js-mode)
+  ((error line-start
+          (file-name) ":" line ":" column ": error - " (message)
+          line-end)
+   (warning line-start
+            (file-name) ":" line ":" column ": warning - " (message)
+            line-end))
+  :modes (css-mode js-mode)
   :predicate (lambda ()
                (and drupal/flycheck-phpcs-js-and-css (apply 'derived-mode-p 
(append drupal-php-modes drupal-css-modes drupal-js-modes)))))
+
 (add-to-list 'flycheck-checkers 'css-js-phpcs)
 
 
diff --git a/drupal/flymake-phpcs.el b/drupal/flymake-phpcs.el
index 671e3a172d..d0d881a688 100644
--- a/drupal/flymake-phpcs.el
+++ b/drupal/flymake-phpcs.el
@@ -1,6 +1,6 @@
 ;;; drupal/flymake-phpcs.el --- Drupal-mode support for flymake-phpcs
 
-;; Copyright (C) 2012, 2013 Arne Jørgensen
+;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen
 
 ;; Author: Arne Jørgensen <arne@arnested.dk>
 
@@ -32,26 +32,133 @@
 (define-obsolete-variable-alias 
'drupal/flymake-phpcs-dont-show-trailing-whitespace 
'drupal/phpcs-dont-show-trailing-whitespace)
 (require 'drupal/phpcs)
 
+;; Silence byte compiler.
+(defvar flymake-phpcs-location)
+
+;; Only available when `flymake' is the fork from
+;; https://github.com/illusori/emacs-flymake.
+(when (or (boundp 'flymake-run-in-place)
+          (fboundp 'flymake-phpcs-load))
+  (defcustom drupal/flymake-phpcs-run-in-place t
+    "If nil, flymake will run on copies in `temporary-file-directory' rather
+than the same directory as the original file.
+
+Drupal Coder Sniffer has some sniffs that will only work if run in place.
+
+Defaults to `t'. Set to `default' to use whatever
+`flymake-run-in-place' is set to.
+
+When editing a remote file via Tramp, this flag also has the side-effect of
+determining whether the syntax check is run in the same place as the original
+file (and thus on the remote machine), or in the same place as
+`temporary-file-directory' (usually the local machine)."
+    :type `(choice
+            (const :tag "Yes" t)
+            (const :tag "No" nil)
+            (const :tag "Default" default))
+    :link '(url-link :tag "Drupal Coder Sniffer" 
"https://drupal.org/project/coder";)
+    :group 'drupal))
+
 (defun drupal/flymake-phpcs-enable ()
   "Enable drupal-mode support for flymake-phpcs."
-  (when (and (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes 
drupal-js-modes))
+  (interactive)
+  (when (and (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes 
drupal-js-modes drupal-info-modes))
+             (not (derived-mode-p 'drush-make-mode))
              (executable-find flymake-phpcs-command)
              drupal/phpcs-standard)
     ;; Set the coding standard to "Drupal" (we checked that it is
-    ;; supported above.
+    ;; supported above).
     (set (make-local-variable 'flymake-phpcs-standard) drupal/phpcs-standard)
 
+    ;; Set whether flymake runs in place.
+    (when (and (boundp 'drupal/flymake-phpcs-run-in-place)
+               (not (eq drupal/flymake-phpcs-run-in-place 'default)))
+      (when (fboundp 'flymake-phpcs-load)
+        (if drupal/flymake-phpcs-run-in-place
+            (set (make-local-variable 'flymake-phpcs-location) 'inplace)
+          (set (make-local-variable 'flymake-phpcs-location) 'tempdir)))
+      (set (make-local-variable 'flymake-run-in-place) 
drupal/flymake-phpcs-run-in-place))
+
     ;; Flymake-phpcs will also highlight trailing whitespace as an
     ;; error so no need to highlight it twice.
-    (drupal/phpcs-dont-show-trailing-whitespace)
+    (when (fboundp 'drupal/phpcs-dont-show-trailing-whitespace)
+      (drupal/phpcs-dont-show-trailing-whitespace))
 
     ;; This is a php-mode file so add the extension to a buffer locale
     ;; version of `flymake-allowed-file-name-masks' and make
     ;; flymake-phpcs initialize.
-    (make-local-variable 'flymake-allowed-file-name-masks)
-    (add-to-list 'flymake-allowed-file-name-masks
-                 `(,(concat "\\." (file-name-extension (or buffer-file-name 
(buffer-name))) "\\'") flymake-phpcs-init))
-    (flymake-mode 1)))
+    (if (fboundp 'flymake-phpcs-load)
+        (flymake-phpcs-load)
+      (make-local-variable 'flymake-allowed-file-name-masks)
+      (setq flymake-allowed-file-name-masks '(("." drupal/flymake-phpcs-init)))
+      (flymake-mode 1))))
+
+(defun drupal/flymake-phpcs-init ()
+  (let* ((temp-file (flymake-init-create-temp-buffer-copy
+                     (if (and (fboundp 'flymake-create-temp-intemp)
+                              (not flymake-run-in-place))
+                         'drupal/flymake-phpcs-create-temp-intemp
+                       'drupal/flymake-phpcs-create-temp-inplace)))
+         (local-file (file-relative-name temp-file
+                                         (file-name-directory (file-truename 
buffer-file-name)))))
+    (list flymake-phpcs-command
+          (append
+           (list local-file)
+           (if flymake-phpcs-standard
+               (list (concat "--standard="
+                             ;; Looking for "/" is hardly portable
+                             (if (string-match "/" flymake-phpcs-standard)
+                                 (expand-file-name flymake-phpcs-standard)
+                               flymake-phpcs-standard))))
+           (if flymake-phpcs-show-rule (list "-s"))))))
+
+(defun drupal/flymake-phpcs-create-temp-inplace (file-name &optional prefix)
+  "Return filename in the same directory as FILE-NAME for a
+temporary copy of the buffer editing FILE-NAME.
+
+Note that this function, despite its name, does not actually create a
+copy of the file: it only choses and returns a filename for the temp
+copy."
+  (unless (stringp file-name)
+    (error "Invalid file-name"))
+  (or prefix
+      (setq prefix "flymake"))
+  (let* ((extension (if (string-match "\\.tpl\\.php\\'" (or buffer-file-name 
(buffer-name)))
+                        ".tpl.php"
+                      (file-name-extension file-name t)))
+         (base-name (replace-regexp-in-string (concat (regexp-quote extension) 
"\\'") "" file-name))
+         (temp-name (file-truename (concat base-name "._" prefix extension))))
+    (flymake-log 3 "create-temp-inplace: file=%s temp=%s" file-name temp-name)
+    temp-name))
+
+(defun drupal/flymake-phpcs-create-temp-intemp (file-name &optional prefix)
+  "Return filename in temporary directory for a temporary
+copy of the buffer editing FILE-NAME. This is a replacement for
+`flymake-create-temp-inplace'. The difference is that it gives
+a file name in `temporary-file-directory' instead of the same
+directory as FILE-NAME.
+
+For the use of PREFIX see that function.
+
+Note that not making the temporary file in another directory
+\(like here) will not work if the file you are checking depends
+relative paths to other files \(for the type of checks flymake
+makes).
+
+Note that this function, despite its name, does not actually create a
+copy of the file: it only choses and returns a filename for the temp
+copy."
+  (unless (stringp file-name)
+    (error "Invalid file-name"))
+  (or prefix
+      (setq prefix "flymake"))
+  (let* ((extension (if (string-match "\\.\\(api\\|tpl\\)\\.php\\'" (or 
buffer-file-name (buffer-name)))
+                        (match-string-no-properties 0)
+                      (file-name-extension file-name t)))
+         (base-name (file-name-nondirectory (replace-regexp-in-string (concat 
(regexp-quote extension) "\\'") "" file-name)))
+         (temp-name (file-truename (make-temp-file (concat base-name "._" 
prefix) nil extension))))
+    (flymake-log 3 "create-temp-intemp: file=%s temp=%s" file-name temp-name)
+    temp-name))
 
 (add-hook 'drupal-mode-hook #'drupal/flymake-phpcs-enable)
 
diff --git a/drupal/gtags.el b/drupal/gtags.el
index ee48eb6484..9e67276d75 100644
--- a/drupal/gtags.el
+++ b/drupal/gtags.el
@@ -1,6 +1,6 @@
 ;;; drupal/gtags.el --- Drupal-mode support for gtags
 
-;; Copyright (C) 2012, 2013 Arne Jørgensen
+;; Copyright (C) 2012, 2013, 2014 Arne Jørgensen
 
 ;; Author: Arne Jørgensen <arne@arnested.dk>
 
@@ -35,7 +35,7 @@ Include path to the executable if it is not in your $PATH.")
 
 (defun drupal/gtags-enable ()
   "Setup rootdir for gtags."
-  (let ((dir (locate-dominating-file (buffer-file-name) "GTAGS")))
+  (let ((dir (locate-dominating-file (or buffer-file-name default-directory) 
"GTAGS")))
     (when dir
       (set (make-local-variable 'gtags-rootdir) dir)
 
diff --git a/drupal/phpcs.el b/drupal/phpcs.el
index c9fd848df8..723f9fa32f 100644
--- a/drupal/phpcs.el
+++ b/drupal/phpcs.el
@@ -34,7 +34,7 @@
                          ;; command. Check for both.
                          (call-process (or (and (boundp 
'flymake-phpcs-command) (executable-find flymake-phpcs-command)) 
(executable-find "phpcs")) nil (list t nil) nil "-i")))))
       (when (string-match
-             "\\(Drupal[^, 
+             "\\(Drupal[^,
 ]*\\)"
              standards)
         (match-string-no-properties 1 standards))))
@@ -60,8 +60,6 @@ need to highlight it twice."
 (defun drupal/phpcs-dont-show-trailing-whitespace ()
   "Turn of various trailing white space highlighting."
   (when drupal/phpcs-dont-show-trailing-whitespace
-    (when (boundp 'whitespace-style)
-      (set (make-local-variable 'whitespace-style) (remove 'trailing 
whitespace-style)))
     (setq show-trailing-whitespace nil)))
 
 (provide 'drupal/phpcs)
diff --git a/drush-make-mode.el b/drush-make-mode.el
index 2ccf22d8cd..8c8bd5e5dc 100644
--- a/drush-make-mode.el
+++ b/drush-make-mode.el
@@ -1,6 +1,6 @@
 ;;; drush-make-mode.el --- Major mode for drush make files
 
-;; Copyright (C) 2013  Arne Jørgensen
+;; Copyright (C) 2013, 2014  Arne Jørgensen
 
 ;; Author: Arne Jørgensen <arne@arnested.dk>
 ;; Keywords: languages, tools, extensions
@@ -35,7 +35,7 @@
 
   ;; Use `bug-reference-mode' for linking issues and patches.
   (set (make-local-variable 'bug-reference-url-format) 
"http://drupal.org/node/%s";)
-  (set (make-local-variable 'bug-reference-bug-regexp) 
"\\(?:\\#\\(?2:[0-9]+\\)\\|\\[['\"]?\\(?2:[0-9]+\\)\\(['\"]?\\]\\)\\)")
+  (set (make-local-variable 'bug-reference-bug-regexp) 
"\\(?:\\#\\(?2:[0-9]+\\)\\|\\[['\"]?\\(?2:[0-9]+\\)\\([^0-9].*\\)?\\(['\"]?\\]\\)\\)")
   (bug-reference-mode)
 
   ;; Use `goto-address-mode' for link highlighting.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]