aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1999-02-19 04:24:12 +0000
committerRichard M. Stallman1999-02-19 04:24:12 +0000
commitc7055d6660dc1e2d000bd7a3e28f6bd8872630c4 (patch)
tree762fb02092b67c81ddeec209684f462faa37c880
parentb81ea5ef1d8e97d8312c4e6ffdb45f23746dad76 (diff)
downloademacs-c7055d6660dc1e2d000bd7a3e28f6bd8872630c4.tar.gz
emacs-c7055d6660dc1e2d000bd7a3e28f6bd8872630c4.zip
(sql-set-sqli-hook): A hook run when sql-buffer is
changed. This is needed for master.el to work. (sql-set-sqli-buffer): Use the new hook. (sql-make-alternate-buffer-name): Function that sets sql-alternate-buffer-name. (sql-alternate-buffer-name): Possible name of SQLi buffers. (sql-interactive-mode): Set sql-alternate-buffer-name. (sql-rename-buffer): New command. (sql-interactive-mode-menu): Menu for SQLi buffers. (sql-interactive-mode): Doc fix. sql-input-ring-separator and sql-input-ring-file-name are used to temporarily set comint-input-ring-file-name and comint-input-ring-separator when reading and writing input history files. (sql-stop): Use sql-input-ring-separator and sql-input-ring-file-name. (sql-input-ring-file-name): New variable with customization. (sql-input-ring-separator): New variable with customization. (sql-set-sqli-buffer): Renamed from sql-change-sqli-buffer. Callers changed. (sql-show-sqli-buffer): The message for "sql-buffer is not set" now includes the name of the current buffer. (sql-mode): Set paragraph-separate and paragraph-start so that sql-send-paragraph sends the entire SQL statements, even if it contains indented lines.
-rw-r--r--lisp/progmodes/sql.el160
1 files changed, 135 insertions, 25 deletions
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 3a0cb87e861..c8b7a2e62eb 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -4,7 +4,7 @@
4 4
5;; Author: Alex Schroeder <a.schroeder@bsiag.ch> 5;; Author: Alex Schroeder <a.schroeder@bsiag.ch>
6;; Maintainer: Alex Schroeder <a.schroeder@bsiag.ch> 6;; Maintainer: Alex Schroeder <a.schroeder@bsiag.ch>
7;; Version: 1.3.2 7;; Version: 1.4.0
8;; Keywords: comm languages processes 8;; Keywords: comm languages processes
9 9
10;; This file is part of GNU Emacs. 10;; This file is part of GNU Emacs.
@@ -152,6 +152,31 @@ the window is split and the SQLi buffer is shown. If this
152variable is not nil, that buffer's window will be selected 152variable is not nil, that buffer's window will be selected
153by calling `pop-to-buffer'. If this variable is nil, that 153by calling `pop-to-buffer'. If this variable is nil, that
154buffer is shown using `display-buffer'." 154buffer is shown using `display-buffer'."
155 :type 'boolean
156 :group 'SQL)
157
158(defcustom sql-input-ring-file-name nil
159 "*If non-nil, name of the file to read/write input history.
160
161This is used to locally set `comint-input-ring-file-name' when reading
162or writing the input history."
163 :type '(choice (const :tag "none" nil)
164 (file))
165 :group 'SQL)
166
167(defcustom sql-input-ring-separator "\n--\n"
168 "*Separator between commands in the history file.
169
170If set to \"\\n\", each line in the history file will be interpreted as
171one command. Multi-line commands are split into several commands when
172the input ring is initialized from a history file.
173
174This variable used to locally set `comint-input-ring-separator' when
175reading or writing the history file. `comint-input-ring-separator' is
176new in Emacs 20.4; if your Emacs does not have it, setting
177`sql-input-ring-separator' will have no effect. In that case multiline
178commands will be split into several commands when the input history is
179read, as if you had set `sql-input-ring-separator' to \"\\n\"."
155 :type 'string 180 :type 'string
156 :group 'SQL) 181 :group 'SQL)
157 182
@@ -167,6 +192,14 @@ buffer is shown using `display-buffer'."
167 :type 'hook 192 :type 'hook
168 :group 'SQL) 193 :group 'SQL)
169 194
195(defcustom sql-set-sqli-hook '()
196 "*Hook for reacting to changes of `sql-buffer'.
197
198This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
199is changed."
200 :type 'hook
201 :group 'SQL)
202
170;; Customisation for Oracle 203;; Customisation for Oracle
171 204
172(defcustom sql-oracle-program "sqlplus" 205(defcustom sql-oracle-program "sqlplus"
@@ -281,7 +314,7 @@ The global value of sql-buffer is the name of the latest SQLi buffer
281created. Any SQL buffer created will make a local copy of this value. 314created. Any SQL buffer created will make a local copy of this value.
282See `sql-interactive-mode' for more on multiple sessions. If you want 315See `sql-interactive-mode' for more on multiple sessions. If you want
283to change the SQLi buffer a SQL mode sends its SQL strings to, change 316to change the SQLi buffer a SQL mode sends its SQL strings to, change
284the local value of sql-buffer using \\[sql-change-sqli-buffer].") 317the local value of `sql-buffer' using \\[sql-set-sqli-buffer].")
285 318
286(defvar sql-prompt-regexp nil 319(defvar sql-prompt-regexp nil
287 "Prompt used to initialize `comint-prompt-regexp'. 320 "Prompt used to initialize `comint-prompt-regexp'.
@@ -293,6 +326,11 @@ You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.")
293 326
294You can change it on `sql-interactive-mode-hook'.") 327You can change it on `sql-interactive-mode-hook'.")
295 328
329(defvar sql-alternate-buffer-name nil
330 "Buffer-local string used to possibly rename the SQLi buffer.
331
332Used by `sql-rename-buffer'.")
333
296;; Keymap for sql-interactive-mode, based on comint-mode-map. 334;; Keymap for sql-interactive-mode, based on comint-mode-map.
297 335
298(if (not (string-match "XEmacs\\|Lucid" emacs-version)) 336(if (not (string-match "XEmacs\\|Lucid" emacs-version))
@@ -337,12 +375,20 @@ You can change it on `sql-interactive-mode-hook'.")
337 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) 375 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)
338 (get-buffer-process sql-buffer))] 376 (get-buffer-process sql-buffer))]
339 ["Show SQLi buffer" sql-show-sqli-buffer t] 377 ["Show SQLi buffer" sql-show-sqli-buffer t]
340 ["Change SQLi buffer" sql-change-sqli-buffer t] 378 ["Set SQLi buffer" sql-set-sqli-buffer t]
341 ["Pop to SQLi buffer after send" 379 ["Pop to SQLi buffer after send"
342 sql-toggle-pop-to-buffer-after-send-region 380 sql-toggle-pop-to-buffer-after-send-region
343 :style toggle 381 :style toggle
344 :selected sql-pop-to-buffer-after-send-region])) 382 :selected sql-pop-to-buffer-after-send-region]))
345 383
384;; easy menu for sql-interactive-mode.
385
386(easy-menu-define
387 sql-interactive-mode-menu sql-interactive-mode-map
388 "Menu for `sql-interactive-mode'."
389 '("SQL"
390 ["Rename Buffer" sql-rename-buffer t]))
391
346;; Abbreviations -- if you want more of them, define them in your 392;; Abbreviations -- if you want more of them, define them in your
347;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too. 393;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too.
348 394
@@ -647,22 +693,24 @@ function like this: (sql-get-login 'user 'password 'database)."
647 (setq sql-database 693 (setq sql-database
648 (read-from-minibuffer "Database: " sql-database nil nil 694 (read-from-minibuffer "Database: " sql-database nil nil
649 sql-database-history)))) 695 sql-database-history))))
696(defun sql-set-sqli-buffer ()
697 "Set the SQLi buffer SQL strings are sent to.
650 698
651(defun sql-change-sqli-buffer () 699Call this function in a SQL buffer in order to set the SQLi buffer SQL
652 "Change the SQLi buffer SQL strings are sent to. 700strings are sent to. Calling this function sets `sql-buffer' and runs
701`sql-set-sqli-hook'.
653 702
654Call this function in a SQL buffer in order to change the SQLi buffer 703If you call it from a SQL buffer, this sets the local copy of
655SQL strings are sent to. Calling this function sets `sql-buffer'.
656
657If you call it from a SQL buffer, this changes the local copy of
658`sql-buffer'. 704`sql-buffer'.
659 705
660If you call it from anywhere else, it changes the global copy of 706If you call it from anywhere else, it sets the global copy of
661`sql-buffer'." 707`sql-buffer'."
662 (interactive) 708 (interactive)
663 (let ((new-buffer (get-buffer (read-buffer "New SQLi buffer: " nil t)))) 709 (let ((new-buffer (get-buffer (read-buffer "New SQLi buffer: " nil t))))
664 (if new-buffer 710 (if new-buffer
665 (setq sql-buffer new-buffer)))) 711 (progn
712 (setq sql-buffer new-buffer)
713 (run-hooks sql-set-sqli-hook)))))
666 714
667(defun sql-show-sqli-buffer () 715(defun sql-show-sqli-buffer ()
668 "Show the name of current SQLi buffer. 716 "Show the name of current SQLi buffer.
@@ -671,11 +719,32 @@ This is the buffer SQL strings are sent to. It is stored in the
671variable `sql-buffer'. See `sql-help' on how to create such a buffer." 719variable `sql-buffer'. See `sql-help' on how to create such a buffer."
672 (interactive) 720 (interactive)
673 (if (null (buffer-live-p sql-buffer)) 721 (if (null (buffer-live-p sql-buffer))
674 (message "There is no SQLi buffer.") 722 (message "%s has no SQLi buffer set." (buffer-name (current-buffer)))
675 (if (null (get-buffer-process sql-buffer)) 723 (if (null (get-buffer-process sql-buffer))
676 (message "Buffer %s has no process." (buffer-name sql-buffer)) 724 (message "Buffer %s has no process." (buffer-name sql-buffer))
677 (message "Current SQLi buffer is %s." (buffer-name sql-buffer))))) 725 (message "Current SQLi buffer is %s." (buffer-name sql-buffer)))))
678 726
727(defun sql-make-alternate-buffer-name ()
728 "Return a string that can be used to rename a SQLi buffer.
729
730This is used to set `sql-alternate-buffer-name' within
731`sql-interactive-mode'."
732 (concat (if (string= "" sql-user)
733 (if (string= "" user-login-name)
734 ()
735 (concat user-login-name "/"))
736 (concat sql-user "/"))
737 (if (string= "" sql-database)
738 (if (string= "" sql-server)
739 system-name
740 sql-server)
741 sql-database)))
742
743(defun sql-rename-buffer ()
744 "Renames a SQLi buffer."
745 (interactive)
746 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name) t))
747
679(defun sql-copy-column () 748(defun sql-copy-column ()
680 "Copy current column to the end of buffer. 749 "Copy current column to the end of buffer.
681Inserts SELECT or commas if appropriate." 750Inserts SELECT or commas if appropriate."
@@ -735,6 +804,17 @@ Inserts SELECT or commas if appropriate."
735 (point)))) 804 (point))))
736 (sql-send-region start end))) 805 (sql-send-region start end)))
737 806
807(defun sql-send-paragraph ()
808 "Send the current paragraph to the SQL process."
809 (interactive)
810 (let ((start (save-excursion
811 (backward-paragraph)
812 (point)))
813 (end (save-excursion
814 (forward-paragraph)
815 (point))))
816 (sql-send-region start end)))
817
738(defun sql-send-buffer () 818(defun sql-send-buffer ()
739 "Send the buffer contents to the SQL process." 819 "Send the buffer contents to the SQL process."
740 (interactive) 820 (interactive)
@@ -770,8 +850,8 @@ When you put a buffer in SQL mode, the buffer stores the last SQLi
770buffer created as its destination in the variable `sql-buffer'. This 850buffer created as its destination in the variable `sql-buffer'. This
771will be the buffer \\[sql-send-region] sends the region to. If this 851will be the buffer \\[sql-send-region] sends the region to. If this
772SQLi buffer is killed, \\[sql-send-region] is no longer able to 852SQLi buffer is killed, \\[sql-send-region] is no longer able to
773determine where the strings should be sent to. You can change the 853determine where the strings should be sent to. You can set the
774value of `sql-buffer' using \\[sql-change-sqli-buffer]. 854value of `sql-buffer' using \\[sql-set-sqli-buffer].
775 855
776For information on how to create multiple SQLi buffers, see 856For information on how to create multiple SQLi buffers, see
777`sql-interactive-mode'." 857`sql-interactive-mode'."
@@ -786,9 +866,14 @@ For information on how to create multiple SQLi buffers, see
786 nil t ((95 . "w") (46 . "w")))) 866 nil t ((95 . "w") (46 . "w"))))
787 (make-local-variable 'comment-start) 867 (make-local-variable 'comment-start)
788 (setq comment-start "--") 868 (setq comment-start "--")
789 ;; The following will make each buffer in sql-mode remeber the 869 ;; Make each buffer in sql-mode remeber the "current" SQLi buffer.
790 ;; "current" SQLi buffer.
791 (make-local-variable 'sql-buffer) 870 (make-local-variable 'sql-buffer)
871 ;; Make `sql-send-paragraph' work on paragraphs that contain indented
872 ;; lines.
873 (make-local-variable 'paragraph-separate)
874 (make-local-variable 'paragraph-start)
875 (setq paragraph-separate "[\f]*$"
876 paragraph-start "[\n\f]")
792 (setq local-abbrev-table sql-mode-abbrev-table) 877 (setq local-abbrev-table sql-mode-abbrev-table)
793 (setq abbrev-all-caps 1) 878 (setq abbrev-all-caps 1)
794 (run-hooks 'sql-mode-hook)) 879 (run-hooks 'sql-mode-hook))
@@ -844,8 +929,11 @@ hooks on `comint-input-filter-functions' are run. After each SQL
844interpreter output, the hooks on `comint-output-filter-functions' are 929interpreter output, the hooks on `comint-output-filter-functions' are
845run. 930run.
846 931
847Variable `comint-input-ring-file-name' controls the initialisation of 932Variable `sql-input-ring-file-name' controls the initialisation of the
848the input ring history. 933input ring history. `comint-input-ring-file-name' is temporarily bound
934to `sql-input-ring-file-name' and `comint-input-ring-separator' is
935temporarily bound to `sql-input-ring-separator' when reading the input
936history.
849 937
850Variables `comint-output-filter-functions', a hook, and 938Variables `comint-output-filter-functions', a hook, and
851`comint-scroll-to-bottom-on-input' and 939`comint-scroll-to-bottom-on-input' and
@@ -856,11 +944,10 @@ If you want to make SQL buffers limited in length, add the function
856`comint-truncate-buffer' to `comint-output-filter-functions'. 944`comint-truncate-buffer' to `comint-output-filter-functions'.
857 945
858Here is an example for your .emacs file. It keeps the SQLi buffer a 946Here is an example for your .emacs file. It keeps the SQLi buffer a
859certain length and stores all inputs in an input-ring file. 947certain length.
860 948
861\(add-hook 'sql-interactive-mode-hook 949\(add-hook 'sql-interactive-mode-hook
862 \(function (lambda () 950 \(function (lambda ()
863 \(setq comint-input-ring-file-name \"~/.sql_history\")
864 \(setq comint-output-filter-functions 'comint-truncate-buffer)))) 951 \(setq comint-output-filter-functions 'comint-truncate-buffer))))
865 952
866Here is another example. It will always put point back to the statement 953Here is another example. It will always put point back to the statement
@@ -882,25 +969,48 @@ you entered, right above the output it created.
882 ;; is disabled for interactive buffers. 969 ;; is disabled for interactive buffers.
883 (setq font-lock-defaults '(sql-mode-font-lock-keywords 970 (setq font-lock-defaults '(sql-mode-font-lock-keywords
884 t t ((95 . "w") (46 . "w")))) 971 t t ((95 . "w") (46 . "w"))))
972 ;; Enable commenting and uncommenting of the region.
885 (make-local-variable 'comment-start) 973 (make-local-variable 'comment-start)
886 (setq comment-start "--") 974 (setq comment-start "--")
975 ;; Abbreviation table init and case-insensitive. It is not activatet
976 ;; by default.
887 (setq local-abbrev-table sql-mode-abbrev-table) 977 (setq local-abbrev-table sql-mode-abbrev-table)
888 (setq abbrev-all-caps 1) 978 (setq abbrev-all-caps 1)
979 ;; Exiting the process will call sql-stop.
889 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop) 980 (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop)
981 ;; Make input-ring stuff buffer local so that people who want a
982 ;; different history file for each buffer/process/client/whatever can
983 ;; change separator and file-name on the sql-interactive-mode-hook.
984 (make-local-variable 'sql-input-ring-separator)
985 (make-local-variable 'sql-input-ring-file-name)
986 ;; Create a usefull name for renaming this buffer later.
987 (make-local-variable 'sql-alternate-buffer-name)
988 (setq sql-alternate-buffer-name (sql-make-alternate-buffer-name))
989 ;; User stuff.
890 (run-hooks 'sql-interactive-mode-hook) 990 (run-hooks 'sql-interactive-mode-hook)
891 ;; calling the hook before calling comint-read-input-ring allows users 991 ;; Calling the hook before calling comint-read-input-ring allows users
892 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook. 992 ;; to set comint-input-ring-file-name in sql-interactive-mode-hook.
893 (comint-read-input-ring t)) 993 ;; While reading the history, file-name and history are rebound...
994 (let ((comint-input-ring-file-name sql-input-ring-file-name)
995 (comint-input-ring-separator sql-input-ring-separator))
996 (comint-read-input-ring t)))
894 997
895(defun sql-stop (process event) 998(defun sql-stop (process event)
896 "Called when the SQL process is stopped. 999 "Called when the SQL process is stopped.
897 1000
898Writes the input history to a history file using `comint-write-input-ring' 1001Writes the input history to a history file using
899and inserts a short message in the SQL buffer. 1002`comint-write-input-ring' and inserts a short message in the SQL buffer.
1003`comint-comint-input-ring-file-name' is temporarily bound to
1004`sql-input-ring-file-name' and `comint-input-ring-separator' is
1005temporarily bound to `sql-input-ring-separator'.
900 1006
901This function is a sentinel watching the SQL interpreter process. 1007This function is a sentinel watching the SQL interpreter process.
902Sentinels will always get the two parameters PROCESS and EVENT." 1008Sentinels will always get the two parameters PROCESS and EVENT."
903 (comint-write-input-ring) 1009 ;; Write history.
1010 ;; While reading the history, file-name and history are rebound...
1011 (let ((comint-input-ring-file-name sql-input-ring-file-name)
1012 (comint-input-ring-separator sql-input-ring-separator))
1013 (comint-write-input-ring))
904 (if (buffer-live-p sql-buffer) 1014 (if (buffer-live-p sql-buffer)
905 (insert (format "\nProcess %s %s\n" process event)))) 1015 (insert (format "\nProcess %s %s\n" process event))))
906 1016