diff options
| author | Richard M. Stallman | 1999-02-06 05:09:31 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1999-02-06 05:09:31 +0000 |
| commit | a081a529397af02bd9fc274065fcd982733e1d8b (patch) | |
| tree | b71273e8403b0753521917186fc883f2eae0da9c | |
| parent | f7769aa59edf082f925afdd8226f46cd78f6aa0e (diff) | |
| download | emacs-a081a529397af02bd9fc274065fcd982733e1d8b.tar.gz emacs-a081a529397af02bd9fc274065fcd982733e1d8b.zip | |
Changed version to 1.2.1.
(sql-pop-to-buffer-after-send-region): Improved documentation.
(sql-mysql-program): Added MySQL support.
(sql-prompt-length): Made prompt-length configurable.
(sql-mode-syntax-table): Made apostrophe (') be a string delimiter.
(sql-help): Added MySQL support, changed documentation.
(sql-send-region): A message is displayed if something is sent.
(sql-mode): Added buffer-local comment-start.
(sql-interactive-mode): Use sql-prompt-length to set left-margin.
(sql-interactive-mode): Added buffer-local comment-start.
(sql-oracle): Set sql-prompt-length.
(sql-sybase): Set sql-prompt-length.
(sql-mysql): Added MySQL support.
(sql-ingres): Set sql-prompt-length.
(sql-ms): Set sql-prompt-length.
(sql-postgres): Set sql-prompt-length.
| -rw-r--r-- | lisp/progmodes/sql.el | 104 |
1 files changed, 94 insertions, 10 deletions
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index d3eb2e47d58..5e1e92420f1 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 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1998, 1999 Free Software Foundation, Inc. |
| 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.1.6 | 7 | ;; Version: 1.2.1 |
| 8 | ;; Keywords: processes SQL | 8 | ;; Keywords: processes SQL |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| @@ -99,6 +99,7 @@ | |||
| 99 | ;; <ibalaban@dalet.com> | 99 | ;; <ibalaban@dalet.com> |
| 100 | ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> | 100 | ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> |
| 101 | ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> | 101 | ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> |
| 102 | ;; nino <nino@inform.dk> | ||
| 102 | 103 | ||
| 103 | 104 | ||
| 104 | ;;; Code: | 105 | ;;; Code: |
| @@ -146,7 +147,9 @@ Currently, this is only used by MS isql." | |||
| 146 | 147 | ||
| 147 | After a call to `sql-send-region' or `sql-send-buffer', | 148 | After a call to `sql-send-region' or `sql-send-buffer', |
| 148 | the window is split and the SQLi buffer is shown. If this | 149 | the window is split and the SQLi buffer is shown. If this |
| 149 | variable is not nil, that buffer's window will be selected." | 150 | variable is not nil, that buffer's window will be selected |
| 151 | by calling `pop-to-buffer'. If this variable is nil, that | ||
| 152 | buffer is shown using `display-buffer'." | ||
| 150 | :type 'string | 153 | :type 'string |
| 151 | :group 'SQL) | 154 | :group 'SQL) |
| 152 | 155 | ||
| @@ -177,6 +180,17 @@ The program can also specify a TCP connection. See `make-comint'." | |||
| 177 | :type 'file | 180 | :type 'file |
| 178 | :group 'SQL) | 181 | :group 'SQL) |
| 179 | 182 | ||
| 183 | ;; Customisation for MySql | ||
| 184 | |||
| 185 | (defcustom sql-mysql-program "mysql" | ||
| 186 | "*Command to start mysql by TcX. | ||
| 187 | |||
| 188 | Starts `sql-interactive-mode' after doing some setup. | ||
| 189 | |||
| 190 | The program can also specify a TCP connection. See `make-comint'." | ||
| 191 | :type 'file | ||
| 192 | :group 'SQL) | ||
| 193 | |||
| 180 | ;; Customisation for SyBase | 194 | ;; Customisation for SyBase |
| 181 | 195 | ||
| 182 | (defcustom sql-sybase-program "isql" | 196 | (defcustom sql-sybase-program "isql" |
| @@ -255,6 +269,11 @@ The program can also specify a TCP connection. See `make-comint'." | |||
| 255 | 269 | ||
| 256 | You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.") | 270 | You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.") |
| 257 | 271 | ||
| 272 | (defvar sql-prompt-length 0 | ||
| 273 | "Prompt used to set `left-margin' in `sql-interactive-mode'. | ||
| 274 | |||
| 275 | You can change it on `sql-interactive-mode-hook'.") | ||
| 276 | |||
| 258 | ;; Keymap for sql-interactive-mode, based on comint-mode-map. | 277 | ;; Keymap for sql-interactive-mode, based on comint-mode-map. |
| 259 | 278 | ||
| 260 | (if (not (string-match "XEmacs\\|Lucid" emacs-version)) | 279 | (if (not (string-match "XEmacs\\|Lucid" emacs-version)) |
| @@ -323,6 +342,8 @@ You can change `comint-prompt-regexp' on `sql-interactive-mode-hook'.") | |||
| 323 | ;; newline and formfeed end coments | 342 | ;; newline and formfeed end coments |
| 324 | (modify-syntax-entry ?\n "> b" table) | 343 | (modify-syntax-entry ?\n "> b" table) |
| 325 | (modify-syntax-entry ?\f "> b" table) | 344 | (modify-syntax-entry ?\f "> b" table) |
| 345 | ;; single quotes (') quotes delimit strings | ||
| 346 | (modify-syntax-entry ?' "\"" table) | ||
| 326 | table) | 347 | table) |
| 327 | "Syntax table used in `sql-mode' and `sql-interactive-mode'.") | 348 | "Syntax table used in `sql-mode' and `sql-interactive-mode'.") |
| 328 | 349 | ||
| @@ -520,11 +541,12 @@ usually named *SQL*. The name of the major mode is SQLi. | |||
| 520 | Use the following commands to start a specific SQL interpreter: | 541 | Use the following commands to start a specific SQL interpreter: |
| 521 | 542 | ||
| 522 | psql by PostGres: \\[sql-postgres] | 543 | psql by PostGres: \\[sql-postgres] |
| 523 | SQL*Plus: \\[sql-oracle] | 544 | mysql by TcX: \\[sql-mysql] |
| 524 | dbaccess: \\[sql-informix] | 545 | SQL*Plus by Oracle: \\[sql-oracle] |
| 525 | isql (Sybase): \\[sql-sybase] | 546 | dbaccess by Informix: \\[sql-informix] |
| 526 | sql (Ingres): \\[sql-ingres] | 547 | isql by Sybase: \\[sql-sybase] |
| 527 | isql (Microsoft): \\[sql-ms] | 548 | sql by Ingres: \\[sql-ingres] |
| 549 | isql by Microsoft: \\[sql-ms] | ||
| 528 | 550 | ||
| 529 | Once you have the SQLi buffer, you can enter SQL statements in the | 551 | Once you have the SQLi buffer, you can enter SQL statements in the |
| 530 | buffer. The output generated is appended to the buffer and a new prompt | 552 | buffer. The output generated is appended to the buffer and a new prompt |
| @@ -635,6 +657,7 @@ Inserts SELECT or commas if appropriate." | |||
| 635 | (if (string-match "\n$" (buffer-substring start end)) | 657 | (if (string-match "\n$" (buffer-substring start end)) |
| 636 | () | 658 | () |
| 637 | (comint-send-string sql-buffer "\n")) | 659 | (comint-send-string sql-buffer "\n")) |
| 660 | (message "Sent string to buffer %s." (buffer-name sql-buffer)) | ||
| 638 | (if sql-pop-to-buffer-after-send-region | 661 | (if sql-pop-to-buffer-after-send-region |
| 639 | (pop-to-buffer sql-buffer) | 662 | (pop-to-buffer sql-buffer) |
| 640 | (display-buffer sql-buffer))) | 663 | (display-buffer sql-buffer))) |
| @@ -685,6 +708,8 @@ Here is an example for your .emacs file. It opens every file ending in | |||
| 685 | (make-local-variable 'font-lock-defaults) | 708 | (make-local-variable 'font-lock-defaults) |
| 686 | (setq font-lock-defaults '(sql-mode-font-lock-keywords | 709 | (setq font-lock-defaults '(sql-mode-font-lock-keywords |
| 687 | nil t ((95 . "w") (46 . "w")))) | 710 | nil t ((95 . "w") (46 . "w")))) |
| 711 | (make-local-variable 'comment-start) | ||
| 712 | (setq comment-start "--") | ||
| 688 | (setq local-abbrev-table sql-mode-abbrev-table) | 713 | (setq local-abbrev-table sql-mode-abbrev-table) |
| 689 | (setq abbrev-all-caps 1) | 714 | (setq abbrev-all-caps 1) |
| 690 | (run-hooks 'sql-mode-hook)) | 715 | (run-hooks 'sql-mode-hook)) |
| @@ -748,13 +773,20 @@ you entered, right above the output it created. | |||
| 748 | \(function (lambda (STR) (comint-show-output))))" | 773 | \(function (lambda (STR) (comint-show-output))))" |
| 749 | (comint-mode) | 774 | (comint-mode) |
| 750 | (setq comint-prompt-regexp sql-prompt-regexp) | 775 | (setq comint-prompt-regexp sql-prompt-regexp) |
| 776 | (setq left-margin sql-prompt-length) | ||
| 751 | (setq major-mode 'sql-interactive-mode) | 777 | (setq major-mode 'sql-interactive-mode) |
| 752 | (setq mode-name "SQLi") | 778 | (setq mode-name "SQLi") |
| 753 | (use-local-map sql-interactive-mode-map) | 779 | (use-local-map sql-interactive-mode-map) |
| 754 | (set-syntax-table sql-mode-syntax-table) | 780 | (set-syntax-table sql-mode-syntax-table) |
| 755 | (make-local-variable 'font-lock-defaults) | 781 | (make-local-variable 'font-lock-defaults) |
| 756 | (setq font-lock-defaults '(sql-mode-font-lock-keywords t t ((95 . "w") (46 . "w")))) | 782 | ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try |
| 757 | (setq left-margin 5) | 783 | ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the |
| 784 | ;; column will have just one quote. Therefore syntactic hilighting | ||
| 785 | ;; is disabled for interactive buffers. | ||
| 786 | (setq font-lock-defaults '(sql-mode-font-lock-keywords | ||
| 787 | t t ((95 . "w") (46 . "w")))) | ||
| 788 | (make-local-variable 'comment-start) | ||
| 789 | (setq comment-start "--") | ||
| 758 | (setq local-abbrev-table sql-mode-abbrev-table) | 790 | (setq local-abbrev-table sql-mode-abbrev-table) |
| 759 | (setq abbrev-all-caps 1) | 791 | (setq abbrev-all-caps 1) |
| 760 | (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop) | 792 | (set-process-sentinel (get-buffer-process sql-buffer) 'sql-stop) |
| @@ -821,6 +853,7 @@ The default comes from `process-coding-system-alist' and | |||
| 821 | (set-buffer (make-comint "SQL" sql-oracle-program nil parameter)) | 853 | (set-buffer (make-comint "SQL" sql-oracle-program nil parameter)) |
| 822 | (set-buffer (make-comint "SQL" sql-oracle-program nil)))) | 854 | (set-buffer (make-comint "SQL" sql-oracle-program nil)))) |
| 823 | (setq sql-prompt-regexp "^SQL> ") | 855 | (setq sql-prompt-regexp "^SQL> ") |
| 856 | (setq sql-prompt-length 5) | ||
| 824 | (setq sql-buffer (current-buffer)) | 857 | (setq sql-buffer (current-buffer)) |
| 825 | ;; set sql-mode-font-lock-keywords to something different before | 858 | ;; set sql-mode-font-lock-keywords to something different before |
| 826 | ;; calling sql-interactive-mode. | 859 | ;; calling sql-interactive-mode. |
| @@ -872,6 +905,7 @@ The default comes from `process-coding-system-alist' and | |||
| 872 | (set-buffer (apply 'make-comint "SQL" sql-sybase-program | 905 | (set-buffer (apply 'make-comint "SQL" sql-sybase-program |
| 873 | nil params))) | 906 | nil params))) |
| 874 | (setq sql-prompt-regexp "^SQL> ") | 907 | (setq sql-prompt-regexp "^SQL> ") |
| 908 | (setq sql-prompt-length 5) | ||
| 875 | (setq sql-buffer (current-buffer)) | 909 | (setq sql-buffer (current-buffer)) |
| 876 | (sql-interactive-mode) | 910 | (sql-interactive-mode) |
| 877 | (message "Login...done") | 911 | (message "Login...done") |
| @@ -910,6 +944,53 @@ The default comes from `process-coding-system-alist' and | |||
| 910 | (set-buffer (make-comint "SQL" sql-informix-program nil)) | 944 | (set-buffer (make-comint "SQL" sql-informix-program nil)) |
| 911 | (set-buffer (make-comint "SQL" sql-informix-program nil sql-database))) | 945 | (set-buffer (make-comint "SQL" sql-informix-program nil sql-database))) |
| 912 | (setq sql-prompt-regexp "^SQL> ") | 946 | (setq sql-prompt-regexp "^SQL> ") |
| 947 | (setq sql-prompt-length 5) | ||
| 948 | (setq sql-buffer (current-buffer)) | ||
| 949 | (sql-interactive-mode) | ||
| 950 | (message "Login...done") | ||
| 951 | (pop-to-buffer sql-buffer))) | ||
| 952 | |||
| 953 | |||
| 954 | |||
| 955 | (defun sql-mysql () | ||
| 956 | "Run mysql by TcX as an inferior process. | ||
| 957 | |||
| 958 | If buffer *SQL* exists but no process is running, make a new process. | ||
| 959 | If buffer exists and a process is running, just switch to buffer | ||
| 960 | `*SQL*'. | ||
| 961 | |||
| 962 | Interpreter used comes from variable `sql-mysql-program'. Login uses | ||
| 963 | the variable `sql-database' as default, if set. | ||
| 964 | |||
| 965 | The buffer is put in sql-interactive-mode, giving commands for sending | ||
| 966 | input. See `sql-interactive-mode'. | ||
| 967 | |||
| 968 | To specify a coding system for converting non-ASCII characters | ||
| 969 | in the input and output to the process, use \\[universal-coding-system-argument] | ||
| 970 | before \\[sql-informix]. You can also specify this with \\[set-buffer-process-coding-system] | ||
| 971 | in the SQL buffer, after you start the process. | ||
| 972 | The default comes from `process-coding-system-alist' and | ||
| 973 | `default-process-coding-system'. | ||
| 974 | |||
| 975 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | ||
| 976 | (interactive) | ||
| 977 | (if (comint-check-proc "*SQL*") | ||
| 978 | (pop-to-buffer "*SQL*") | ||
| 979 | (sql-get-login 'user 'password 'database) | ||
| 980 | (message "Login...") | ||
| 981 | ;; Put all parameters to the program (if defined) in a list and call | ||
| 982 | ;; make-comint. | ||
| 983 | (let ((params)) | ||
| 984 | (if (not (string= "" sql-database)) | ||
| 985 | (setq params (append (list (concat "--host=" sql-database)) params))) | ||
| 986 | (if (not (string= "" sql-password)) | ||
| 987 | (setq params (append (list (concat "--password=" sql-password)) params))) | ||
| 988 | (if (not (string= "" sql-user)) | ||
| 989 | (setq params (append (list (concat "--user=" sql-user)) params))) | ||
| 990 | (set-buffer (apply 'make-comint "SQL" sql-mysql-program | ||
| 991 | nil params))) | ||
| 992 | (setq sql-prompt-regexp "^mysql>") | ||
| 993 | (setq sql-prompt-length 6) | ||
| 913 | (setq sql-buffer (current-buffer)) | 994 | (setq sql-buffer (current-buffer)) |
| 914 | (sql-interactive-mode) | 995 | (sql-interactive-mode) |
| 915 | (message "Login...done") | 996 | (message "Login...done") |
| @@ -948,6 +1029,7 @@ The default comes from `process-coding-system-alist' and | |||
| 948 | (set-buffer (make-comint "SQL" sql-ingres-program nil)) | 1029 | (set-buffer (make-comint "SQL" sql-ingres-program nil)) |
| 949 | (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database))) | 1030 | (set-buffer (make-comint "SQL" sql-ingres-program nil sql-database))) |
| 950 | (setq sql-prompt-regexp "^\* ") | 1031 | (setq sql-prompt-regexp "^\* ") |
| 1032 | (setq sql-prompt-length 2) | ||
| 951 | (setq sql-buffer (current-buffer)) | 1033 | (setq sql-buffer (current-buffer)) |
| 952 | (sql-interactive-mode) | 1034 | (sql-interactive-mode) |
| 953 | (message "Login...done") | 1035 | (message "Login...done") |
| @@ -999,6 +1081,7 @@ The default comes from `process-coding-system-alist' and | |||
| 999 | (set-buffer (apply 'make-comint "SQL" sql-ms-program | 1081 | (set-buffer (apply 'make-comint "SQL" sql-ms-program |
| 1000 | nil params))) | 1082 | nil params))) |
| 1001 | (setq sql-prompt-regexp "^[0-9]*>") | 1083 | (setq sql-prompt-regexp "^[0-9]*>") |
| 1084 | (setq sql-prompt-length 5) | ||
| 1002 | (setq sql-buffer (current-buffer)) | 1085 | (setq sql-buffer (current-buffer)) |
| 1003 | (sql-interactive-mode) | 1086 | (sql-interactive-mode) |
| 1004 | (message "Login...done") | 1087 | (message "Login...done") |
| @@ -1044,6 +1127,7 @@ Try to set `comint-output-filter-functions' like this: | |||
| 1044 | (set-buffer (make-comint "SQL" sql-postgres-program nil)) | 1127 | (set-buffer (make-comint "SQL" sql-postgres-program nil)) |
| 1045 | (set-buffer (make-comint "SQL" sql-postgres-program nil sql-database))) | 1128 | (set-buffer (make-comint "SQL" sql-postgres-program nil sql-database))) |
| 1046 | (setq sql-prompt-regexp "^.*> *") | 1129 | (setq sql-prompt-regexp "^.*> *") |
| 1130 | (setq sql-prompt-length 5) | ||
| 1047 | ;; This is a lousy hack to prevent psql from truncating it's output | 1131 | ;; This is a lousy hack to prevent psql from truncating it's output |
| 1048 | ;; and giving stupid warnings. If s.o. knows a way to prevent psql | 1132 | ;; and giving stupid warnings. If s.o. knows a way to prevent psql |
| 1049 | ;; from acting this way, then I would be very thankful to | 1133 | ;; from acting this way, then I would be very thankful to |