Subject: Re: bug#31446: 26.1; sql-interactive-mode buffer naming is broken

From: Eli Zaretskii <[email-masked]>
Date: Fri, 18 May 2018 15:19:54 +0300

> Date: Fri, 18 May 2018 12:49:28 +0300
> From: Eli Zaretskii <[email-masked]>
> Cc: [email-masked]
> 
> does the patch below give good results?

Sorry, that patch left out an important use case.  Please try the one
below.

(Is it correct to use "*SQL*" when no prefix arg is given?)

diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index e4db6cc..2ced15c 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -4263,9 +4263,18 @@ sql-product-interactive
                 (funcall (sql-get-product-feature product :sqli-comint-func)
                          product
                          (sql-get-product-feature product :sqli-options)
-                         (if (and new-name (string-prefix-p "SQL" new-name t))
-                             new-name
-                           (concat "SQL: " new-name))))
+                         (cond
+                          ((zerop new-name)
+                           "*SQL*")
+                          ((stringp new-name)
+                           (if (string-prefix-p "SQL" new-name t)
+                               new-name
+                             (concat "*SQL: " new-name "*")))
+                          ((eq new-name '(4))
+                           (sql-rename-buffer new-name)
+                           sql-alternate-buffer-name)
+                          (t
+                           (format "*SQL: %s*" new-name)))))
 
               ;; Set SQLi mode.
               (let ((sql-interactive-product product))