[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/drupal-mode 36ea4003da 259/308: Merge pull request #65 fro
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/drupal-mode 36ea4003da 259/308: Merge pull request #65 from joddie/feature/sql-cli |
Date: |
Tue, 25 Jan 2022 10:59:52 -0500 (EST) |
branch: elpa/drupal-mode
commit 36ea4003dafdaea75d3ccf802c2b0ec19b44b11d
Merge: b59ad24b6e 72c533c619
Author: Arne Jørgensen <arne@arnested.dk>
Commit: Arne Jørgensen <arne@arnested.dk>
Merge pull request #65 from joddie/feature/sql-cli
Add `drupal-drush-sql-cli` command
---
drupal-mode.el | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
diff --git a/drupal-mode.el b/drupal-mode.el
index 63d32732ef..8ddda9b6b4 100644
--- a/drupal-mode.el
+++ b/drupal-mode.el
@@ -36,6 +36,8 @@
(require 'cl)
(require 'php-mode)
(require 'format-spec)
+(require 'json)
+(require 'sql)
;; Silence byte compiler.
(defvar css-indent-level)
@@ -239,7 +241,8 @@ get better filling in Doxygen comments."
(?f . drupal-insert-function)
(?m . drupal-module-name)
(?e . drupal-drush-php-eval)
- (?t . drupal-wrap-string-in-t-function))
+ (?t . drupal-wrap-string-in-t-function)
+ (?s . drupal-drush-sql-cli))
"Map of mnemonic keys and functions for keyboard shortcuts.
See `drupal-mode-map'.")
@@ -428,6 +431,10 @@ of the project)."
[menu-bar drupal cache-clear]
'(menu-item "Clear all caches" drupal-drush-cache-clear
:enable (and drupal-rootdir drupal-drush-program)))
+(define-key drupal-mode-map
+ [menu-bar drupal sql-cli]
+ '(menu-item "Open SQL shell" drupal-drush-sql-cli
+ :enable (and drupal-rootdir drupal-drush-program)))
(define-key drupal-mode-map
[menu-bar drupal drupal-project drupal-project-bugs]
@@ -519,6 +526,48 @@ buffer."
(search-forward-regexp "\\(\"\\|'\\)")
(insert ")")))))
+(defun drupal-drush-sql-cli ()
+ "Run a SQL shell using \"drush sql-cli\" in a SQL-mode comint buffer."
+ (interactive)
+ (let* ((json-object-type 'plist)
+ (config
+ (json-read-from-string
+ (with-temp-buffer
+ (call-process drupal-drush-program nil t nil
+ "sql-conf" "--format=json")
+ (buffer-string)))))
+ (when (not config)
+ (error "No Drupal SQL configuration found."))
+ (destructuring-bind (&key database driver &allow-other-keys) config
+ (let ((sql-interactive-product
+ (drupal--db-driver-to-sql-product driver))
+ (start-buffer (current-buffer))
+ (sqli-buffer
+ (make-comint (format "SQL (%s)" database)
+ drupal-drush-program nil "sql-cli")))
+ (with-current-buffer sqli-buffer
+ (sql-interactive-mode)
+ (set (make-local-variable 'sql-buffer)
+ (buffer-name (current-buffer)))
+
+ ;; Set `sql-buffer' in the start buffer
+ (with-current-buffer start-buffer
+ (when (derived-mode-p 'sql-mode)
+ (setq sql-buffer (buffer-name sqli-buffer))
+ (run-hooks 'sql-set-sqli-hook)))
+
+ ;; All done.
+ (run-hooks 'sql-login-hook)
+ (pop-to-buffer sqli-buffer))))))
+
+(defun drupal--db-driver-to-sql-product (driver)
+ "Translate a Drupal DB driver name into a sql-mode symbol."
+ (let ((driver (intern driver)))
+ (cond
+ ((eq driver 'pgsql) 'postgres)
+ ((assq driver sql-product-alist) driver)
+ (t 'ansi))))
+
(defvar drupal-form-id-history nil
- [nongnu] elpa/drupal-mode 319acd5761 240/308: Moved eldoc stuff to separate file., (continued)
- [nongnu] elpa/drupal-mode 319acd5761 240/308: Moved eldoc stuff to separate file., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode d09cdf8781 236/308: User error if the hook is already inserted in the file., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 4bd52836b3 238/308: Inherit drupal-style from php style., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 2e51a209df 223/308: Properly concat phpcs option in newer flycheck., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 914d2df539 222/308: Fixed URL of Drupalcontrib.org API., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 5ad113d48f 255/308: Add `drupal-drush-sql-cli` command, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode b62d89c177 251/308: Fix up for latest flycheck., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode c2d7bc42e3 252/308: Merge pull request #63 from arnested/feature/flycheck-update, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 59bbaaf4f1 249/308: Merge branch 'release/0.6.1' into develop, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 0cd2412756 257/308: Avoid "no tags containing" error in hook skeleton, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 36ea4003da 259/308: Merge pull request #65 from joddie/feature/sql-cli,
ELPA Syncer <=
- [nongnu] elpa/drupal-mode 2cca689e26 268/308: Better gtags-helm support., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode a02e1dde00 271/308: Merge pull request #72 from arnested/fix-phpcs-output-parsing, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode f425ba445a 276/308: Merge branch 'release/0.7.1' into develop, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode eec2e557d7 277/308: Updated to the latest flycheck., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 643c7538b0 279/308: Merge pull request #78 from arnested/continuation-style, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode dea5a8da78 280/308: Fix thinko, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode ca569eaa62 281/308: Update obsoleted comment, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 47fda0a38a 287/308: Ignore errors in `drupal/gxref-get-function-args`, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 95bf73b4b6 288/308: Create SECURITY.md, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode ee53f9e12b 289/308: Create CODE_OF_CONDUCT.md, ELPA Syncer, 2022/01/25