|
1 | 1 | ;;; drupal-mode.el --- Advanced minor mode for Drupal development |
2 | 2 |
|
3 | | -;; Copyright (C) 2012, 2013, 2014, 2015 Arne Jørgensen |
| 3 | +;; Copyright (C) 2012, 2013, 2014, 2015, 2016 Arne Jørgensen |
4 | 4 |
|
5 | 5 | ;; Author: Arne Jørgensen <[email protected]> |
6 | 6 | ;; URL: https://github.com/arnested/drupal-mode |
7 | 7 | ;; Created: January 17, 2012 |
8 | | -;; Version: 0.6.1 |
| 8 | +;; Version: 0.7.0 |
9 | 9 | ;; Package-Requires: ((php-mode "1.5.0")) |
10 | 10 | ;; Keywords: programming, php, drupal |
11 | 11 |
|
|
36 | 36 | (require 'cl) |
37 | 37 | (require 'php-mode) |
38 | 38 | (require 'format-spec) |
| 39 | +(require 'json) |
| 40 | +(require 'sql) |
39 | 41 |
|
40 | 42 | ;; Silence byte compiler. |
41 | 43 | (defvar css-indent-level) |
@@ -239,7 +241,8 @@ get better filling in Doxygen comments." |
239 | 241 | (?f . drupal-insert-function) |
240 | 242 | (?m . drupal-module-name) |
241 | 243 | (?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)) |
243 | 246 | "Map of mnemonic keys and functions for keyboard shortcuts. |
244 | 247 | See `drupal-mode-map'.") |
245 | 248 |
|
@@ -428,6 +431,10 @@ of the project)." |
428 | 431 | [menu-bar drupal cache-clear] |
429 | 432 | '(menu-item "Clear all caches" drupal-drush-cache-clear |
430 | 433 | :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))) |
431 | 438 |
|
432 | 439 | (define-key drupal-mode-map |
433 | 440 | [menu-bar drupal drupal-project drupal-project-bugs] |
@@ -519,6 +526,48 @@ buffer." |
519 | 526 | (search-forward-regexp "\\(\"\\|'\\)") |
520 | 527 | (insert ")"))))) |
521 | 528 |
|
| 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 | + |
522 | 571 |
|
523 | 572 |
|
524 | 573 | (defvar drupal-form-id-history nil |
@@ -556,7 +605,8 @@ buffer." |
556 | 605 | (user-error "%s already exists in file." (replace-regexp-in-string "^hook" (drupal-module-name) v2))) |
557 | 606 | ;; User error if the hook is already inserted elsewhere. |
558 | 607 | (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)))) |
560 | 610 | (user-error "%s already exists elsewhere." (replace-regexp-in-string "^hook" (drupal-module-name) v2))) |
561 | 611 | (drupal-ensure-newline) |
562 | 612 | "/**\n" |
@@ -872,6 +922,7 @@ mode-hook." |
872 | 922 | (eval-after-load 'eldoc '(require 'drupal/eldoc)) |
873 | 923 | (eval-after-load 'etags '(require 'drupal/etags)) |
874 | 924 | (eval-after-load 'gtags '(require 'drupal/gtags)) |
| 925 | +(eval-after-load 'helm-gtags '(require 'drupal/helm-gtags)) |
875 | 926 | (eval-after-load 'ggtags '(require 'drupal/ggtags)) |
876 | 927 | (eval-after-load 'ispell '(require 'drupal/ispell)) |
877 | 928 | (eval-after-load 'flymake-phpcs '(require 'drupal/flymake-phpcs)) |
|
0 commit comments