diff options
| author | Gerd Moellmann | 2000-06-26 13:09:49 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-06-26 13:09:49 +0000 |
| commit | 9ef3882f5d2816e5bc872031878ff0901b78e432 (patch) | |
| tree | df9f04f9878ef4d4110a3e5efb79e0c266e7b380 | |
| parent | b2df30a65dc2a83779393836f38e8bcd870955a1 (diff) | |
| download | emacs-9ef3882f5d2816e5bc872031878ff0901b78e432.tar.gz emacs-9ef3882f5d2816e5bc872031878ff0901b78e432.zip | |
(sql-interactive-mode-map): Use `kbd' in calls to
`define-key'; instead of checking `(emacs-version)' check for
`set-keymap-parent' and `set-keymap-name' directly. Add entries
for `;' and `o' which might be electric.
(sql-electric-stuff): New user option.
(sql-magic-go): New function which uses `sql-electric-stuff'.
(sql-magic-semicolon): New function which uses
`sql-electric-stuff'.
(sql-accumulate-and-indent): Insert newline if `comint-accumulate'
is not fboundp.
(sql-oracle-options): New variable.
(sql-oracle): Use it.
(sql-imenu-generic-expression): Doc change.
(sql-find-sqli-buffer): Make sure the default-value of sql-buffer
is used.
(sql-informix): Added command line parameter "-" to force
sql-informix-program to use stdout.
| -rw-r--r-- | lisp/progmodes/sql.el | 148 |
1 files changed, 98 insertions, 50 deletions
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index f3a1bb2a772..9cb642aaf18 100644 --- a/lisp/progmodes/sql.el +++ b/lisp/progmodes/sql.el | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | ;;; sql.el --- specialized comint.el for SQL interpreters | 1 | ;;; sql.el --- specialized comint.el for SQL interpreters |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1998, 1999 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Alex Schroeder <alex@gnu.org> | 5 | ;; Author: Alex Schroeder <alex@gnu.org> |
| 6 | ;; Maintainer: Alex Schroeder <alex@gnu.org> | 6 | ;; Maintainer: Alex Schroeder <alex@gnu.org> |
| 7 | ;; Version: 1.4.10 | 7 | ;; Version: 1.4.13 |
| 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. |
| @@ -31,9 +31,6 @@ | |||
| 31 | ;; mail to sql.el-request@gnu.org with `subscribe sql.el FIRSTNAME | 31 | ;; mail to sql.el-request@gnu.org with `subscribe sql.el FIRSTNAME |
| 32 | ;; LASTNAME' in the mail body. | 32 | ;; LASTNAME' in the mail body. |
| 33 | 33 | ||
| 34 | ;; You can get the latest version of this file from my homepage | ||
| 35 | ;; <URL:http://www.geocities.com/TimesSquare/6120/emacs.html>. | ||
| 36 | |||
| 37 | ;; This file provides a sql-mode and a sql-interactive-mode. My goals | 34 | ;; This file provides a sql-mode and a sql-interactive-mode. My goals |
| 38 | ;; were two simple modes providing syntactic hilighting. The | 35 | ;; were two simple modes providing syntactic hilighting. The |
| 39 | ;; interactive mode had to provide a command-line history; the other | 36 | ;; interactive mode had to provide a command-line history; the other |
| @@ -88,6 +85,8 @@ | |||
| 88 | ;; only appear after the process is exited. This makes things | 85 | ;; only appear after the process is exited. This makes things |
| 89 | ;; somewhat unreliable. | 86 | ;; somewhat unreliable. |
| 90 | 87 | ||
| 88 | ;; ChangeLog available on request. | ||
| 89 | |||
| 91 | ;;; To Do: | 90 | ;;; To Do: |
| 92 | 91 | ||
| 93 | ;; Add better hilight support for other brands; there is a bias towards | 92 | ;; Add better hilight support for other brands; there is a bias towards |
| @@ -151,6 +150,20 @@ Customizing your password will store it in your ~/.emacs file." | |||
| 151 | 150 | ||
| 152 | ;; misc customization of sql.el behaviour | 151 | ;; misc customization of sql.el behaviour |
| 153 | 152 | ||
| 153 | (defcustom sql-electric-stuff nil | ||
| 154 | "Treat some input as electric. | ||
| 155 | If set to the symbol `semicolon', then hitting `;' will send current | ||
| 156 | input in the SQLi buffer to the process. | ||
| 157 | If set to the symbol `go', then hitting `go' on a line by itself will | ||
| 158 | send current input in the SQLi buffer to the process. | ||
| 159 | If set to nil, then you must use \\[comint-send-input] in order to send | ||
| 160 | current input in the SQLi buffer to the process." | ||
| 161 | :type '(choice (const :tag "Nothing" nil) | ||
| 162 | (const :tag "The semikolon `;'" semicolon) | ||
| 163 | (const :tag "The string `go' by itself" go)) | ||
| 164 | :version "20.8" | ||
| 165 | :group 'SQL) | ||
| 166 | |||
| 154 | (defcustom sql-pop-to-buffer-after-send-region nil | 167 | (defcustom sql-pop-to-buffer-after-send-region nil |
| 155 | "*If t, pop to the buffer SQL statements are sent to. | 168 | "*If t, pop to the buffer SQL statements are sent to. |
| 156 | 169 | ||
| @@ -169,7 +182,10 @@ buffer is shown using `display-buffer'." | |||
| 169 | ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1)) | 182 | ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1)) |
| 170 | "Define interesting points in the SQL buffer for `imenu'. | 183 | "Define interesting points in the SQL buffer for `imenu'. |
| 171 | 184 | ||
| 172 | This is used to rebind `imenu-generic-expression'.") | 185 | This is used to set `imenu-generic-expression' when SQL mode is |
| 186 | entered. Subsequent changes to sql-imenu-generic-expression will not | ||
| 187 | affect existing SQL buffers because imenu-generic-expression is a | ||
| 188 | local variable.") | ||
| 173 | 189 | ||
| 174 | ;; history file | 190 | ;; history file |
| 175 | 191 | ||
| @@ -242,6 +258,12 @@ The program can also specify a TCP connection. See `make-comint'." | |||
| 242 | :type 'file | 258 | :type 'file |
| 243 | :group 'SQL) | 259 | :group 'SQL) |
| 244 | 260 | ||
| 261 | (defcustom sql-oracle-options nil | ||
| 262 | "*List of additional options for `sql-oracle-program'." | ||
| 263 | :type '(repeat string) | ||
| 264 | :version "20.8" | ||
| 265 | :group 'SQL) | ||
| 266 | |||
| 245 | ;; Customisation for MySql | 267 | ;; Customisation for MySql |
| 246 | 268 | ||
| 247 | (defcustom sql-mysql-program "mysql" | 269 | (defcustom sql-mysql-program "mysql" |
| @@ -358,33 +380,32 @@ You can change it on `sql-interactive-mode-hook'.") | |||
| 358 | 380 | ||
| 359 | Used by `sql-rename-buffer'.") | 381 | Used by `sql-rename-buffer'.") |
| 360 | 382 | ||
| 361 | ;; Keymap for sql-interactive-mode, based on comint-mode-map. | 383 | ;; Keymap for sql-interactive-mode. |
| 362 | 384 | ||
| 363 | (if (not (string-match "XEmacs\\|Lucid" emacs-version)) | 385 | (defvar sql-interactive-mode-map |
| 364 | (defvar sql-interactive-mode-map | 386 | (let ((map (make-sparse-keymap))) |
| 365 | (let ((map (nconc (make-sparse-keymap) comint-mode-map))) | 387 | (if (functionp 'set-keymap-parent) |
| 366 | (define-key map "\C-j" 'sql-accumulate-and-indent) | 388 | (set-keymap-parent map comint-mode-map); Emacs |
| 367 | (define-key map "\C-c\C-w" 'sql-copy-column) | 389 | (set-keymap-parents map (list comint-mode-map))); XEmacs |
| 368 | map) | 390 | (if (functionp 'set-keymap-name) |
| 369 | "Mode map used for `sql-interactive-mode'.") | 391 | (set-keymap-name map 'sql-interactive-mode-map)); XEmacs |
| 370 | ;; XEmacs | 392 | (define-key map (kbd "C-j") 'sql-accumulate-and-indent) |
| 371 | (defvar sql-interactive-mode-map nil) | 393 | (define-key map (kbd "C-c C-w") 'sql-copy-column) |
| 372 | (if (not sql-interactive-mode-map) | 394 | (define-key map (kbd "O") 'sql-magic-go) |
| 373 | (let ((map (make-keymap))) | 395 | (define-key map (kbd "o") 'sql-magic-go) |
| 374 | (set-keymap-parents map (list comint-mode-map)) | 396 | (define-key map (kbd ";") 'sql-magic-semicolon) |
| 375 | (set-keymap-name map 'sql-interactive-mode-map) | 397 | map) |
| 376 | (define-key map "\C-j" 'sql-accumulate-and-indent) | 398 | "Mode map used for `sql-interactive-mode'. |
| 377 | (define-key map "\C-c\C-w" 'sql-copy-column) | 399 | Based on `comint-mode-map'.") |
| 378 | (setq sql-interactive-mode-map map)))) | ||
| 379 | 400 | ||
| 380 | ;; Keymap for sql-mode. | 401 | ;; Keymap for sql-mode. |
| 381 | 402 | ||
| 382 | (defvar sql-mode-map | 403 | (defvar sql-mode-map |
| 383 | (let ((map (make-sparse-keymap))) | 404 | (let ((map (make-sparse-keymap))) |
| 384 | (define-key map "\C-c\C-c" 'sql-send-paragraph) | 405 | (define-key map (kbd "C-c C-c") 'sql-send-paragraph) |
| 385 | (define-key map "\C-c\C-r" 'sql-send-region) | 406 | (define-key map (kbd "C-c C-r") 'sql-send-region) |
| 386 | (define-key map "\C-c\C-b" 'sql-send-buffer) | 407 | (define-key map (kbd "C-c C-b") 'sql-send-buffer) |
| 387 | (define-key map "\t" 'indent-relative) | 408 | (define-key map (kbd "<tab>") 'indent-relative) |
| 388 | map) | 409 | map) |
| 389 | "Mode map used for `sql-mode'.") | 410 | "Mode map used for `sql-mode'.") |
| 390 | 411 | ||
| @@ -625,10 +646,31 @@ can be changed by some entry functions to provide more hilighting.") | |||
| 625 | 646 | ||
| 626 | ;;; Small functions | 647 | ;;; Small functions |
| 627 | 648 | ||
| 649 | (defun sql-magic-go (arg) | ||
| 650 | "Insert \"o\" and call `comint-send-input'. | ||
| 651 | `sql-electric-stuff' must be the symbol `go'." | ||
| 652 | (interactive "P") | ||
| 653 | (self-insert-command (prefix-numeric-value arg)) | ||
| 654 | (if (and (equal sql-electric-stuff 'go) | ||
| 655 | (save-excursion | ||
| 656 | (beginning-of-line) | ||
| 657 | (looking-at (concat sql-prompt-regexp "go\\b")))) | ||
| 658 | (comint-send-input))) | ||
| 659 | |||
| 660 | (defun sql-magic-semicolon (arg) | ||
| 661 | "Insert semicolon and call `comint-send-input'. | ||
| 662 | `sql-electric-stuff' must be the symbol `semicolon'." | ||
| 663 | (interactive "P") | ||
| 664 | (self-insert-command (prefix-numeric-value arg)) | ||
| 665 | (if (equal sql-electric-stuff 'semicolon) | ||
| 666 | (comint-send-input))) | ||
| 667 | |||
| 628 | (defun sql-accumulate-and-indent () | 668 | (defun sql-accumulate-and-indent () |
| 629 | "Continue SQL statement on the next line." | 669 | "Continue SQL statement on the next line." |
| 630 | (interactive) | 670 | (interactive) |
| 631 | (if (fboundp 'comint-accumulate) (comint-accumulate)) | 671 | (if (fboundp 'comint-accumulate) |
| 672 | (comint-accumulate) | ||
| 673 | (newline)) | ||
| 632 | (indent-according-to-mode)) | 674 | (indent-according-to-mode)) |
| 633 | 675 | ||
| 634 | ;;;###autoload | 676 | ;;;###autoload |
| @@ -725,21 +767,22 @@ function like this: (sql-get-login 'user 'password 'database)." | |||
| 725 | "Return the current default SQLi buffer or nil. | 767 | "Return the current default SQLi buffer or nil. |
| 726 | In order to qualify, the SQLi buffer must be alive, | 768 | In order to qualify, the SQLi buffer must be alive, |
| 727 | be in `sql-interactive-mode' and have a process." | 769 | be in `sql-interactive-mode' and have a process." |
| 728 | (if (and (buffer-live-p (default-value 'sql-buffer)) | 770 | (let ((default-buffer (default-value 'sql-buffer))) |
| 729 | (get-buffer-process (default-value 'sql-buffer))) | 771 | (if (and (buffer-live-p default-buffer) |
| 730 | sql-buffer | 772 | (get-buffer-process default-buffer)) |
| 731 | (save-excursion | 773 | default-buffer |
| 732 | (let ((buflist (buffer-list)) | 774 | (save-excursion |
| 733 | (found)) | 775 | (let ((buflist (buffer-list)) |
| 734 | (while (not (or (null buflist) | 776 | (found)) |
| 735 | found)) | 777 | (while (not (or (null buflist) |
| 736 | (let ((candidate (car buflist))) | 778 | found)) |
| 737 | (set-buffer candidate) | 779 | (let ((candidate (car buflist))) |
| 738 | (if (and (equal major-mode 'sql-interactive-mode) | 780 | (set-buffer candidate) |
| 739 | (get-buffer-process candidate)) | 781 | (if (and (equal major-mode 'sql-interactive-mode) |
| 740 | (setq found candidate)) | 782 | (get-buffer-process candidate)) |
| 741 | (setq buflist (cdr buflist)))) | 783 | (setq found candidate)) |
| 742 | found)))) | 784 | (setq buflist (cdr buflist)))) |
| 785 | found))))) | ||
| 743 | 786 | ||
| 744 | (defun sql-set-sqli-buffer-generally () | 787 | (defun sql-set-sqli-buffer-generally () |
| 745 | "Set SQLi buffer for all SQL buffers that have none. | 788 | "Set SQLi buffer for all SQL buffers that have none. |
| @@ -811,13 +854,13 @@ variable `sql-buffer'. See `sql-help' on how to create such a buffer." | |||
| 811 | This is used to set `sql-alternate-buffer-name' within | 854 | This is used to set `sql-alternate-buffer-name' within |
| 812 | `sql-interactive-mode'." | 855 | `sql-interactive-mode'." |
| 813 | (concat (if (string= "" sql-user) | 856 | (concat (if (string= "" sql-user) |
| 814 | (if (string= "" user-login-name) | 857 | (if (string= "" (user-login-name)) |
| 815 | () | 858 | () |
| 816 | (concat user-login-name "/")) | 859 | (concat (user-login-name) "/")) |
| 817 | (concat sql-user "/")) | 860 | (concat sql-user "/")) |
| 818 | (if (string= "" sql-database) | 861 | (if (string= "" sql-database) |
| 819 | (if (string= "" sql-server) | 862 | (if (string= "" sql-server) |
| 820 | system-name | 863 | (system-name) |
| 821 | sql-server) | 864 | sql-server) |
| 822 | sql-database))) | 865 | sql-database))) |
| 823 | 866 | ||
| @@ -1110,7 +1153,8 @@ If buffer exists and a process is running, just switch to buffer | |||
| 1110 | 1153 | ||
| 1111 | Interpreter used comes from variable `sql-oracle-program'. Login uses | 1154 | Interpreter used comes from variable `sql-oracle-program'. Login uses |
| 1112 | the variables `sql-user', `sql-password', and `sql-database' as | 1155 | the variables `sql-user', `sql-password', and `sql-database' as |
| 1113 | defaults, if set. | 1156 | defaults, if set. Additional command line parameters can be stored in |
| 1157 | the list `sql-oracle-options'. | ||
| 1114 | 1158 | ||
| 1115 | The buffer is put in sql-interactive-mode, giving commands for sending | 1159 | The buffer is put in sql-interactive-mode, giving commands for sending |
| 1116 | input. See `sql-interactive-mode'. | 1160 | input. See `sql-interactive-mode'. |
| @@ -1140,7 +1184,11 @@ The default comes from `process-coding-system-alist' and | |||
| 1140 | (if (and parameter (not (string= "" sql-database))) | 1184 | (if (and parameter (not (string= "" sql-database))) |
| 1141 | (setq parameter (concat parameter "@" sql-database))) | 1185 | (setq parameter (concat parameter "@" sql-database))) |
| 1142 | (if parameter | 1186 | (if parameter |
| 1143 | (set-buffer (make-comint "SQL" sql-oracle-program nil parameter)) | 1187 | (setq parameter (nconc (list parameter) sql-oracle-options)) |
| 1188 | (setq parameter sql-oracle-options)) | ||
| 1189 | (if parameter | ||
| 1190 | (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil | ||
| 1191 | parameter)) | ||
| 1144 | (set-buffer (make-comint "SQL" sql-oracle-program nil)))) | 1192 | (set-buffer (make-comint "SQL" sql-oracle-program nil)))) |
| 1145 | (setq sql-prompt-regexp "^SQL> ") | 1193 | (setq sql-prompt-regexp "^SQL> ") |
| 1146 | (setq sql-prompt-length 5) | 1194 | (setq sql-prompt-length 5) |
| @@ -1232,7 +1280,7 @@ The default comes from `process-coding-system-alist' and | |||
| 1232 | ;; username and password are ignored. | 1280 | ;; username and password are ignored. |
| 1233 | (if (string= "" sql-database) | 1281 | (if (string= "" sql-database) |
| 1234 | (set-buffer (make-comint "SQL" sql-informix-program nil)) | 1282 | (set-buffer (make-comint "SQL" sql-informix-program nil)) |
| 1235 | (set-buffer (make-comint "SQL" sql-informix-program nil sql-database))) | 1283 | (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-"))) |
| 1236 | (setq sql-prompt-regexp "^SQL> ") | 1284 | (setq sql-prompt-regexp "^SQL> ") |
| 1237 | (setq sql-prompt-length 5) | 1285 | (setq sql-prompt-length 5) |
| 1238 | (setq sql-buffer (current-buffer)) | 1286 | (setq sql-buffer (current-buffer)) |