diff options
author | Michael R. Mauger <michael@mauger.com> | 2019-04-24 20:59:25 -0400 |
---|---|---|
committer | Michael R. Mauger <michael@mauger.com> | 2019-04-24 20:59:25 -0400 |
commit | a1386fa6a7698c04902354cd5fefb39056b0a901 (patch) | |
tree | 9d4ee7ae5b4d3cc13e0b88a445ec2e1c35e36117 /lisp/progmodes/sql.el | |
parent | 2bf957394cdcb93396966d3289f5e200886cb424 (diff) | |
download | emacs-a1386fa6a7698c04902354cd5fefb39056b0a901.tar.gz |
* lisp/progmodes/sql.el
(sql-is-sqli-buffer-p): New function.
(sql-generate-unique-sqli-buffer-name): Refactor and use it.
(sql-product-interactive): Simplify name logic.
* test/lisp/progmodes/sql-tests.el
(sql-tests-placeholder-filter-harness): New macro.
(sql-tests-placeholder-filter-simple)
(sql-tests-placeholder-filter-ampersand)
(sql-tests-placeholder-filter-period): Refactored tests and use macro.
(sql-tests-buffer-naming-harness): New macro.
(sql-tests-buffer-naming-default)
(sql-tests-buffer-naming-multiple)
(sql-tests-buffer-naming-explicit)
(sql-tests-buffer-naming-universal-argument)
(sql-tests-buffer-naming-existing): New tests.
Diffstat (limited to 'lisp/progmodes/sql.el')
-rw-r--r-- | lisp/progmodes/sql.el | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index 28261ef74b2..2d33b3130cd 100644 --- a/lisp/progmodes/sql.el +++ b/lisp/progmodes/sql.el @@ -1423,6 +1423,15 @@ specified, it's `sql-product' or `sql-connection' must match." (and (stringp connection) (string= connection sql-connection)))))))) +(defun sql-is-sqli-buffer-p (buffer) + "Return non-nil if buffer is a SQLi buffer." + (when buffer + (setq buffer (get-buffer buffer)) + (and buffer + (buffer-live-p buffer) + (with-current-buffer buffer + (derived-mode-p 'sql-interactive-mode))))) + ;; Keymap for sql-interactive-mode. (defvar sql-interactive-mode-map @@ -3550,24 +3559,29 @@ server/database name." "Generate a new, unique buffer name for a SQLi buffer. Append a sequence number until a unique name is found." - (let ((base-name (when (stringp base) - (substring-no-properties - (or base - (sql-get-product-feature product :name) + (let ((base-name (substring-no-properties + (if base + (if (stringp base) + base + (format "%S" base)) + (or (sql-get-product-feature product :name) (symbol-name product))))) - buf-fmt-1st buf-fmt-rest) + buf-fmt-1st + buf-fmt-rest) ;; Calculate buffer format - (if base-name - (setq buf-fmt-1st (format "*SQL: %s*" base-name) - buf-fmt-rest (format "*SQL: %s-%%d*" base-name)) - (setq buf-fmt-1st "*SQL*" - buf-fmt-rest "*SQL-%d*")) + (if (string-blank-p base-name) + (setq buf-fmt-1st "*SQL*" + buf-fmt-rest "*SQL-%d*") + (setq buf-fmt-1st (format "*SQL: %s*" base-name) + buf-fmt-rest (format "*SQL: %s-%%d*" base-name))) ;; See if we can find an unused buffer (let ((buf-name buf-fmt-1st) (i 1)) - (while (sql-buffer-live-p buf-name) + (while (if (sql-is-sqli-buffer-p buf-name) + (comint-check-proc buf-name) + (buffer-live-p (get-buffer buf-name))) ;; Check a sequence number on the BASE (setq buf-name (format buf-fmt-rest i) i (1+ i))) @@ -4670,13 +4684,13 @@ the call to \\[sql-product-interactive] with (read-string "Buffer name (\"*SQL: XXX*\"; enter `XXX'): " (sql-make-alternate-buffer-name product)))) - ((or (string-prefix-p " " new-name) - (string-match-p "\\`[*].*[*]\\'" new-name)) - new-name) ((stringp new-name) - (sql-generate-unique-sqli-buffer-name product new-name)) + (if (or (string-prefix-p " " new-name) + (string-match-p "\\`[*].*[*]\\'" new-name)) + new-name + (sql-generate-unique-sqli-buffer-name product new-name))) (t - (sql-generate-unique-sqli-buffer-name product nil))))) + (sql-generate-unique-sqli-buffer-name product new-name))))) ;; Set SQLi mode. (let ((sql-interactive-product product)) |