Skip to content

Commit d920370

Browse files
committed
Merge branch 'release/0.7.0'
2 parents cf0364c + f604ace commit d920370

File tree

7 files changed

+215
-18
lines changed

7 files changed

+215
-18
lines changed

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: emacs-lisp
2+
before_install:
3+
- curl -fsSkL https://gist.githubusercontent.com/rejeep/7736123/raw | sh
4+
- export PATH="/home/travis/.cask/bin:$PATH"
5+
- export PATH="/home/travis/.evm/bin:$PATH"
6+
- evm install $EVM_EMACS --use
7+
- cask
8+
env:
9+
- EVM_EMACS=emacs-24.1-bin
10+
- EVM_EMACS=emacs-24.2-bin
11+
- EVM_EMACS=emacs-24.4-bin
12+
- EVM_EMACS=emacs-24.5-bin
13+
script:
14+
- emacs --version
15+
- make test

drupal-mode.el

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
;;; drupal-mode.el --- Advanced minor mode for Drupal development
22

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

55
;; Author: Arne Jørgensen <[email protected]>
66
;; URL: https://github.com/arnested/drupal-mode
77
;; Created: January 17, 2012
8-
;; Version: 0.6.1
8+
;; Version: 0.7.0
99
;; Package-Requires: ((php-mode "1.5.0"))
1010
;; Keywords: programming, php, drupal
1111

@@ -36,6 +36,8 @@
3636
(require 'cl)
3737
(require 'php-mode)
3838
(require 'format-spec)
39+
(require 'json)
40+
(require 'sql)
3941

4042
;; Silence byte compiler.
4143
(defvar css-indent-level)
@@ -239,7 +241,8 @@ get better filling in Doxygen comments."
239241
(?f . drupal-insert-function)
240242
(?m . drupal-module-name)
241243
(?e . drupal-drush-php-eval)
242-
(?t . drupal-wrap-string-in-t-function))
244+
(?t . drupal-wrap-string-in-t-function)
245+
(?s . drupal-drush-sql-cli))
243246
"Map of mnemonic keys and functions for keyboard shortcuts.
244247
See `drupal-mode-map'.")
245248

@@ -428,6 +431,10 @@ of the project)."
428431
[menu-bar drupal cache-clear]
429432
'(menu-item "Clear all caches" drupal-drush-cache-clear
430433
:enable (and drupal-rootdir drupal-drush-program)))
434+
(define-key drupal-mode-map
435+
[menu-bar drupal sql-cli]
436+
'(menu-item "Open SQL shell" drupal-drush-sql-cli
437+
:enable (and drupal-rootdir drupal-drush-program)))
431438

432439
(define-key drupal-mode-map
433440
[menu-bar drupal drupal-project drupal-project-bugs]
@@ -519,6 +526,48 @@ buffer."
519526
(search-forward-regexp "\\(\"\\|'\\)")
520527
(insert ")")))))
521528

529+
(defun drupal-drush-sql-cli ()
530+
"Run a SQL shell using \"drush sql-cli\" in a SQL-mode comint buffer."
531+
(interactive)
532+
(let* ((json-object-type 'plist)
533+
(config
534+
(json-read-from-string
535+
(with-temp-buffer
536+
(call-process drupal-drush-program nil t nil
537+
"sql-conf" "--format=json")
538+
(buffer-string)))))
539+
(when (not config)
540+
(error "No Drupal SQL configuration found."))
541+
(destructuring-bind (&key database driver &allow-other-keys) config
542+
(let ((sql-interactive-product
543+
(drupal--db-driver-to-sql-product driver))
544+
(start-buffer (current-buffer))
545+
(sqli-buffer
546+
(make-comint (format "SQL (%s)" database)
547+
drupal-drush-program nil "sql-cli")))
548+
(with-current-buffer sqli-buffer
549+
(sql-interactive-mode)
550+
(set (make-local-variable 'sql-buffer)
551+
(buffer-name (current-buffer)))
552+
553+
;; Set `sql-buffer' in the start buffer
554+
(with-current-buffer start-buffer
555+
(when (derived-mode-p 'sql-mode)
556+
(setq sql-buffer (buffer-name sqli-buffer))
557+
(run-hooks 'sql-set-sqli-hook)))
558+
559+
;; All done.
560+
(run-hooks 'sql-login-hook)
561+
(pop-to-buffer sqli-buffer))))))
562+
563+
(defun drupal--db-driver-to-sql-product (driver)
564+
"Translate a Drupal DB driver name into a sql-mode symbol."
565+
(let ((driver (intern driver)))
566+
(cond
567+
((eq driver 'pgsql) 'postgres)
568+
((assq driver sql-product-alist) driver)
569+
(t 'ansi))))
570+
522571

523572

524573
(defvar drupal-form-id-history nil
@@ -556,7 +605,8 @@ buffer."
556605
(user-error "%s already exists in file." (replace-regexp-in-string "^hook" (drupal-module-name) v2)))
557606
;; User error if the hook is already inserted elsewhere.
558607
(when (and drupal-get-function-args
559-
(funcall drupal-get-function-args (replace-regexp-in-string "^hook" (drupal-module-name) v2)))
608+
(ignore-errors
609+
(funcall drupal-get-function-args (replace-regexp-in-string "^hook" (drupal-module-name) v2))))
560610
(user-error "%s already exists elsewhere." (replace-regexp-in-string "^hook" (drupal-module-name) v2)))
561611
(drupal-ensure-newline)
562612
"/**\n"
@@ -872,6 +922,7 @@ mode-hook."
872922
(eval-after-load 'eldoc '(require 'drupal/eldoc))
873923
(eval-after-load 'etags '(require 'drupal/etags))
874924
(eval-after-load 'gtags '(require 'drupal/gtags))
925+
(eval-after-load 'helm-gtags '(require 'drupal/helm-gtags))
875926
(eval-after-load 'ggtags '(require 'drupal/ggtags))
876927
(eval-after-load 'ispell '(require 'drupal/ispell))
877928
(eval-after-load 'flymake-phpcs '(require 'drupal/flymake-phpcs))

drupal/autoinsert.el

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;; drupal/autoinsert.el --- Drupal-mode support for `auto-insert-mode'
22

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

55
;; Author: Arne Jørgensen <[email protected]>
66
;; Keywords:
@@ -30,6 +30,8 @@
3030
(define-auto-insert '("\\.module" . "Drupal module file") 'drupal/autoinsert-insert-module-skeleton)
3131
(define-auto-insert '("\\.install" . "Drupal install file") 'drupal/autoinsert-insert-install-skeleton)
3232
(define-auto-insert '("\\.test" . "Drupal test file") 'drupal/autoinsert-insert-test-skeleton)
33+
(define-auto-insert '("\\.api.php" . "Drupal API file") 'drupal/autoinsert-insert-api-skeleton)
34+
(define-auto-insert '("\\.variable.inc" . "Drupal variable module support file") 'drupal/autoinsert-insert-variable-module-skeleton)
3335

3436
(define-skeleton drupal/autoinsert-insert-info-skeleton
3537
"Drupal info file skeleton."
@@ -95,6 +97,73 @@
9597
@ - "\n"
9698
"}\n")
9799

100+
(define-skeleton drupal/autoinsert-insert-api-skeleton
101+
"Drupal api.php file skeleton."
102+
nil
103+
"<?php\n"
104+
"\n"
105+
"/**\n"
106+
" * @file\n"
107+
" * Hooks provided by the " (drupal-module-name) " module.\n"
108+
" */\n"
109+
"\n"
110+
"/**\n"
111+
" * @addtogroup hooks\n"
112+
" * @{\n"
113+
" */\n"
114+
"\n"
115+
@ - "\n"
116+
"\n"
117+
"/**\n"
118+
" * @} End of \"addtogroup hooks\".\n"
119+
" */\n")
120+
121+
(define-skeleton drupal/autoinsert-insert-variable-module-skeleton
122+
"Drupal variable module support file."
123+
nil
124+
"<?php\n"
125+
"\n"
126+
"/**\n"
127+
" * @file\n"
128+
" * Variable module support for the " (drupal-module-name) " module.\n"
129+
" */\n"
130+
"\n"
131+
"/**\n"
132+
" * @addtogroup variables\n"
133+
" * @{\n"
134+
" */\n"
135+
"\n"
136+
"/**\n"
137+
" * Implements hook_variable_info().\n"
138+
" */\n"
139+
"function " (drupal-module-name) "_variable_info($options) {\n"
140+
" $variables['" @ - (drupal-module-name) "_some_variable'] = array(\n"
141+
" 'type' => 'string',\n"
142+
" 'title' => t('Some variable title', array(), $options),\n"
143+
" 'default' => 'uid',\n"
144+
" 'description' => t('Some variable description', array(), $options),\n"
145+
" 'group' => '" (drupal-module-name) "',\n"
146+
" );\n"
147+
"\n"
148+
" return $variables;\n"
149+
"}\n"
150+
"\n"
151+
"/**\n"
152+
" * Implements hook_variable_group_info().\n"
153+
" */\n"
154+
"function " (drupal-module-name) "_variable_group_info() {\n"
155+
" $groups['" (drupal-module-name) "'] = array(\n"
156+
" 'title' => t('Some group title'),\n"
157+
" 'description' => t('Some group description.'),\n"
158+
" );\n"
159+
"\n"
160+
" return $groups;\n"
161+
"}\n"
162+
"\n"
163+
"/**\n"
164+
" * @} End of \"addtogroup variables\".\n"
165+
" */\n")
166+
98167

99168

100169
(provide 'drupal/autoinsert)

drupal/etags.el

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@
4747
"Get function arguments from etags TAGS."
4848
(when (and (boundp 'drupal/etags-rootdir)
4949
(file-exists-p (concat drupal/etags-rootdir "TAGS")))
50-
(with-current-buffer (find-tag-noselect symbol nil nil)
51-
(goto-char (point-min))
52-
(when (re-search-forward
53-
(format "function\\s-+%s\\s-*(\\([^{]*\\))" symbol)
54-
nil t)
55-
(match-string-no-properties 1)))))
50+
(save-excursion
51+
(with-current-buffer (find-tag-noselect symbol nil nil)
52+
(goto-char (point-min))
53+
(when (re-search-forward
54+
(format "function\\s-+%s\\s-*(\\([^{]*\\))" symbol)
55+
nil t)
56+
(match-string-no-properties 1))))))
5657

5758
(add-hook 'drupal-mode-hook #'drupal/etags-enable)
5859

drupal/flycheck.el

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ checker runs those.
5050
5151
See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
5252
:command ("phpcs" "--report=emacs"
53-
(option "--standard=" flycheck-phpcs-standard concat)
53+
(option "--standard=" drupal/phpcs-standard concat)
5454
source-inplace)
5555
;; Though phpcs supports Checkstyle output which we could feed to
5656
;; `flycheck-parse-checkstyle', we are still using error patterns here,
@@ -64,17 +64,15 @@ See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
6464
(warning line-start
6565
(file-name) ":" line ":" column ": warning - " (message)
6666
line-end))
67-
;; We'd prefer to just check drupal-mode, but flycheck global mode
68-
;; finds the checker before we get a chance to set drupal-mode.
6967
:predicate (lambda ()
70-
(apply 'derived-mode-p (append drupal-css-modes drupal-js-modes drupal-info-modes))))
68+
(and drupal-mode drupal/phpcs-standard)))
7169

7270
;; Append our custom checker.
7371
(add-to-list 'flycheck-checkers 'drupal-phpcs t)
7472
;; Add our checker as next-checker to checkers of all supported modes.
7573
(let ((modes (append drupal-css-modes drupal-js-modes drupal-info-modes)))
7674
(dolist (checker (flycheck-defined-checkers))
77-
(dolist (mode (flycheck-checker-modes checker))
75+
(dolist (mode (flycheck-checker-get checker 'modes))
7876
(if (memq mode modes)
7977
(flycheck-add-next-checker checker 'drupal-phpcs)))))
8078

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

drupal/phpcs.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;; drupal/phpcs.el --- Drupal-mode common support for flymake-phpcs and flycheck
22

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

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

@@ -34,7 +34,7 @@
3434
;; command. Check for both.
3535
(call-process (or (and (boundp 'flymake-phpcs-command) (executable-find flymake-phpcs-command)) (executable-find "phpcs")) nil (list t nil) nil "-i")))))
3636
(when (string-match
37-
"\\(Drupal[^,
37+
"\\(Drupal[^ ,
3838
]*\\)"
3939
standards)
4040
(match-string-no-properties 1 standards))))

0 commit comments

Comments
 (0)