changeset 26576:0894b3c8dfd6

(sql-find-sqli-buffer): New function. (sql-set-sqli-buffer-generally): New function. (sql-set-sqli-buffer): Better checking of new-buffer. (sql-copy-column): Add comma after INTO clause, too. (sql-imenu-generic-expression): New, used to set imenu-generic-expression. (sql-mode): Use ?_ and ?. instead of 95 and 46 when setting font-lock-defaults' SYNTAX-ALIST. Set imenu-generic-expression, imenu-case-fold-search, and imenu-syntax-alist. (sql-interactive-mode): Use ?_ and ?. instead of 95 and 46 when setting font-lock-defaults' SYNTAX-ALIST.
author Gerd Moellmann <gerd@gnu.org>
date Wed, 24 Nov 1999 14:57:04 +0000
parents 43e8fbbd472b
children a79d0d3d066f
files lisp/progmodes/sql.el
diffstat 1 files changed, 61 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/sql.el	Wed Nov 24 14:43:14 1999 +0000
+++ b/lisp/progmodes/sql.el	Wed Nov 24 14:57:04 1999 +0000
@@ -4,7 +4,7 @@
 
 ;; Author: Alex Schroeder <alex@gnu.org>
 ;; Maintainer: Alex Schroeder <alex@gnu.org>
-;; Version: 1.4.9
+;; Version: 1.4.10
 ;; Keywords: comm languages processes
 
 ;; This file is part of GNU Emacs.
@@ -721,6 +721,48 @@
 	    (read-from-minibuffer "Database: " sql-database nil nil
 				  sql-database-history))))
 
+(defun sql-find-sqli-buffer ()
+  "Return the current default SQLi buffer or nil.
+In order to qualify, the SQLi buffer must be alive,
+be in `sql-interactive-mode' and have a process."
+  (if (and (buffer-live-p (default-value 'sql-buffer))
+	   (get-buffer-process (default-value 'sql-buffer)))
+      sql-buffer
+    (save-excursion
+      (let ((buflist (buffer-list))
+	    (found))
+	(while (not (or (null buflist)
+			found))
+	  (let ((candidate (car buflist)))
+	    (set-buffer candidate)
+	    (if (and (equal major-mode 'sql-interactive-mode)
+		     (get-buffer-process candidate))
+		(setq found candidate))
+	    (setq buflist (cdr buflist))))
+	found))))
+
+(defun sql-set-sqli-buffer-generally ()
+  "Set SQLi buffer for all SQL buffers that have none.  
+This function checks all SQL buffers for their SQLi buffer.  If their
+SQLi buffer is nonexistent or has no process, it is set to the current
+default SQLi buffer.  The current default SQLi buffer is determined
+using `sql-find-sqli-buffer'.  If `sql-buffer' is set,
+`sql-set-sqli-hook' is run."
+  (interactive)
+  (save-excursion
+    (let ((buflist (buffer-list))
+	  (default-sqli-buffer (sql-find-sqli-buffer)))
+      (setq-default sql-buffer default-sqli-buffer)
+      (while (not (null buflist))
+	(let ((candidate (car buflist)))
+	  (set-buffer candidate)
+	  (if (and (equal major-mode 'sql-mode)
+		   (not (buffer-live-p sql-buffer)))
+	      (progn
+		(setq sql-buffer default-sqli-buffer)
+		(run-hooks 'sql-set-sqli-hook))))
+	(setq buflist (cdr buflist))))))
+
 (defun sql-set-sqli-buffer ()
   "Set the SQLi buffer SQL strings are sent to.
 
@@ -734,11 +776,22 @@
 If you call it from anywhere else, it sets the global copy of
 `sql-buffer'."
   (interactive)
-  (let ((new-buffer (get-buffer (read-buffer "New SQLi buffer: " nil t))))
-    (if new-buffer
-	(progn
-	  (setq sql-buffer new-buffer)
-	  (run-hooks 'sql-set-sqli-hook)))))
+  (let ((default-buffer (sql-find-sqli-buffer)))
+    (if (null default-buffer)
+	(error "There is no suitable SQLi buffer"))
+    (let ((new-buffer
+	   (get-buffer
+	    (read-buffer "New SQLi buffer: " default-buffer t))))
+      (if (null (get-buffer-process new-buffer))
+	  (error "Buffer %s has no process" (buffer-name new-buffer)))
+      (if (null (save-excursion
+		  (set-buffer new-buffer)
+		  (equal major-mode 'sql-interactive-mode)))
+	  (error "Buffer %s is no SQLi buffer" (buffer-name new-buffer)))
+      (if new-buffer
+	  (progn
+	    (setq sql-buffer new-buffer)
+	    (run-hooks 'sql-set-sqli-hook))))))
 
 (defun sql-show-sqli-buffer ()
   "Show the name of current SQLi buffer.
@@ -788,9 +841,9 @@
        ((save-excursion (beginning-of-line)
 			(looking-at (concat comint-prompt-regexp "$")))
 	(insert "SELECT "))
-       ;; else if appending to SELECT or ORDER BY, insert a comma
+       ;; else if appending to INTO .* (, SELECT or ORDER BY, insert a comma
        ((save-excursion
-	  (re-search-backward "\\b\\(select\\|order by\\) .+"
+	  (re-search-backward "\\b\\(\\(into\\s-+\\S-+\\s-+(\\)\\|select\\|order by\\) .+"
 			      (save-excursion (beginning-of-line) (point)) t))
 	(insert ", "))
        ;; else insert a space