diff options
| author | Gerd Moellmann | 2001-04-20 10:03:48 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2001-04-20 10:03:48 +0000 |
| commit | 624ef9b3c207db38614ae91f90e47e89c36817c9 (patch) | |
| tree | ff6ca800d0792133151eadb6d3c462b09f9e3a37 | |
| parent | 939d70190345618e4f5300429be1b799106b2b27 (diff) | |
| download | emacs-624ef9b3c207db38614ae91f90e47e89c36817c9.tar.gz emacs-624ef9b3c207db38614ae91f90e47e89c36817c9.zip | |
(sql-escape-newlines-and-send): New function.
(sql-db2): Set comint-input-sender to
sql-escape-newlines-and-send.
(sql-db2-program): New option.
(sql-db2-options): New option.
(sql-db2): New function.
(sql-mode-menu): Added highlighting entries.
(sql-highlight-oracle-keywords): New function.
(sql-highlight-postgres-keywords): New function.
(sql-highlight-ansi-keywords): New function.
(sql-help): Doc change.
| -rw-r--r-- | lisp/ChangeLog | 23 | ||||
| -rw-r--r-- | lisp/progmodes/sql.el | 123 |
2 files changed, 143 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0e8294dcc19..77744ca37eb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,26 @@ | |||
| 1 | 2001-04-20 Alex Schroeder <alex@gnu.org> | ||
| 2 | |||
| 3 | * sql.el (sql-escape-newlines-and-send): New function. | ||
| 4 | (sql-db2): Set comint-input-sender to | ||
| 5 | sql-escape-newlines-and-send. | ||
| 6 | |||
| 7 | 2001-04-20 Alex Schroeder <alex@gnu.org> | ||
| 8 | |||
| 9 | * sql.el (sql-db2-program): New option. | ||
| 10 | (sql-db2-options): New option. | ||
| 11 | (sql-db2): New function. | ||
| 12 | |||
| 13 | 2001-04-20 Alex Schroeder <alex@gnu.org> | ||
| 14 | |||
| 15 | * sql.el (sql-mode-menu): Added highlighting entries. | ||
| 16 | (sql-highlight-oracle-keywords): New function. | ||
| 17 | (sql-highlight-postgres-keywords): New function. | ||
| 18 | (sql-highlight-ansi-keywords): New function. | ||
| 19 | |||
| 20 | 2001-04-20 Alex Schroeder <alex@gnu.org> | ||
| 21 | |||
| 22 | * sql.el (sql-help): Doc change. | ||
| 23 | |||
| 1 | 2001-04-19 Stefan Monnier <monnier@cs.yale.edu> | 24 | 2001-04-19 Stefan Monnier <monnier@cs.yale.edu> |
| 2 | 25 | ||
| 3 | * emacs-lisp/easy-mmode.el (easy-mmode-defsyntax): Unquote `doc'. | 26 | * emacs-lisp/easy-mmode.el (easy-mmode-defsyntax): Unquote `doc'. |
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index 189507acbfc..932c5b2511b 100644 --- a/lisp/progmodes/sql.el +++ b/lisp/progmodes/sql.el | |||
| @@ -4,7 +4,7 @@ | |||
| 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.5.0 | 7 | ;; Version: 1.6.1 |
| 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. |
| @@ -381,6 +381,23 @@ The program can also specify a TCP connection. See `make-comint'." | |||
| 381 | :version "20.8" | 381 | :version "20.8" |
| 382 | :group 'SQL) | 382 | :group 'SQL) |
| 383 | 383 | ||
| 384 | ;; Customization for DB2 | ||
| 385 | |||
| 386 | (defcustom sql-db2-program "db2" | ||
| 387 | "*Command to start db2 by IBM. | ||
| 388 | |||
| 389 | Starts `sql-interactive-mode' after doing some setup. | ||
| 390 | |||
| 391 | The program can also specify a TCP connection. See `make-comint'." | ||
| 392 | :type 'file | ||
| 393 | :group 'SQL) | ||
| 394 | |||
| 395 | (defcustom sql-db2-options nil | ||
| 396 | "*List of additional options for `sql-db2-program'." | ||
| 397 | :type '(repeat string) | ||
| 398 | :version "20.8" | ||
| 399 | :group 'SQL) | ||
| 400 | |||
| 384 | 401 | ||
| 385 | 402 | ||
| 386 | ;;; Variables which do not need customization | 403 | ;;; Variables which do not need customization |
| @@ -468,7 +485,11 @@ Based on `comint-mode-map'.") | |||
| 468 | ["Pop to SQLi buffer after send" | 485 | ["Pop to SQLi buffer after send" |
| 469 | sql-toggle-pop-to-buffer-after-send-region | 486 | sql-toggle-pop-to-buffer-after-send-region |
| 470 | :style toggle | 487 | :style toggle |
| 471 | :selected sql-pop-to-buffer-after-send-region])) | 488 | :selected sql-pop-to-buffer-after-send-region] |
| 489 | ("Highlighting" | ||
| 490 | ["ANSI SQL keywords" sql-highlight-ansi-keywords t] | ||
| 491 | ["Oracle keywords" sql-highlight-oracle-keywords t] | ||
| 492 | ["Postgres keywords" sql-highlight-postgres-keywords t]))) | ||
| 472 | 493 | ||
| 473 | ;; easy menu for sql-interactive-mode. | 494 | ;; easy menu for sql-interactive-mode. |
| 474 | 495 | ||
| @@ -697,6 +718,31 @@ can be changed by some entry functions to provide more hilighting.") | |||
| 697 | 718 | ||
| 698 | 719 | ||
| 699 | 720 | ||
| 721 | ;;; Functions to switch highlighting | ||
| 722 | |||
| 723 | (defun sql-highlight-oracle-keywords () | ||
| 724 | "Highlight Oracle keywords. | ||
| 725 | Basically, this just sets `font-lock-keywords' appropriately." | ||
| 726 | (interactive) | ||
| 727 | (setq font-lock-keywords sql-mode-oracle-font-lock-keywords) | ||
| 728 | (font-lock-fontify-buffer)) | ||
| 729 | |||
| 730 | (defun sql-highlight-postgres-keywords () | ||
| 731 | "Highlight Postgres keywords. | ||
| 732 | Basically, this just sets `font-lock-keywords' appropriately." | ||
| 733 | (interactive) | ||
| 734 | (setq font-lock-keywords sql-mode-postgres-font-lock-keywords) | ||
| 735 | (font-lock-fontify-buffer)) | ||
| 736 | |||
| 737 | (defun sql-highlight-ansi-keywords () | ||
| 738 | "Highlight ANSI SQL keywords. | ||
| 739 | Basically, this just sets `font-lock-keywords' appropriately." | ||
| 740 | (interactive) | ||
| 741 | (setq font-lock-keywords sql-mode-ansi-font-lock-keywords) | ||
| 742 | (font-lock-fontify-buffer)) | ||
| 743 | |||
| 744 | |||
| 745 | |||
| 700 | ;;; Compatibility functions | 746 | ;;; Compatibility functions |
| 701 | 747 | ||
| 702 | (if (not (fboundp 'comint-line-beginning-position)) | 748 | (if (not (fboundp 'comint-line-beginning-position)) |
| @@ -758,6 +804,7 @@ Other non-free SQL implementations are also supported: | |||
| 758 | Sybase: \\[sql-sybase] | 804 | Sybase: \\[sql-sybase] |
| 759 | Ingres: \\[sql-ingres] | 805 | Ingres: \\[sql-ingres] |
| 760 | Microsoft: \\[sql-ms] | 806 | Microsoft: \\[sql-ms] |
| 807 | Interbase: \\[sql-interbase] | ||
| 761 | 808 | ||
| 762 | But we urge you to choose a free implementation instead of these. | 809 | But we urge you to choose a free implementation instead of these. |
| 763 | 810 | ||
| @@ -979,6 +1026,24 @@ This function is used for `comint-input-sender' if using `sql-oracle' on NT." | |||
| 979 | (comint-send-string proc string) | 1026 | (comint-send-string proc string) |
| 980 | (comint-send-string proc "\n")) | 1027 | (comint-send-string proc "\n")) |
| 981 | 1028 | ||
| 1029 | ;; Using DB2 interactively, newlines must be escaped with " \". | ||
| 1030 | ;; The space before the backslash is relevant. | ||
| 1031 | (defun sql-escape-newlines-and-send (proc string) | ||
| 1032 | "Send to PROC input STRING, escaping newlines if necessary. | ||
| 1033 | Every newline in STRING will be preceded with a space and a backslash." | ||
| 1034 | (let ((result "") (start 0) mb me) | ||
| 1035 | (while (string-match "\n" string start) | ||
| 1036 | (setq mb (match-beginning 0) | ||
| 1037 | me (match-end 0)) | ||
| 1038 | (if (and (> mb 1) | ||
| 1039 | (string-equal " \\" (substring string (- mb 2) mb))) | ||
| 1040 | (setq result (concat result (substring string start me))) | ||
| 1041 | (setq result (concat result (substring string start mb) " \\\n"))) | ||
| 1042 | (setq start me)) | ||
| 1043 | (setq result (concat result (substring string start))) | ||
| 1044 | (comint-send-string proc result) | ||
| 1045 | (comint-send-string proc "\n"))) | ||
| 1046 | |||
| 982 | 1047 | ||
| 983 | 1048 | ||
| 984 | ;;; Sending the region to the SQLi buffer. | 1049 | ;;; Sending the region to the SQLi buffer. |
| @@ -1275,7 +1340,9 @@ The default comes from `process-coding-system-alist' and | |||
| 1275 | ;; calling sql-interactive-mode. | 1340 | ;; calling sql-interactive-mode. |
| 1276 | (setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords) | 1341 | (setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords) |
| 1277 | (sql-interactive-mode) | 1342 | (sql-interactive-mode) |
| 1278 | ;; If running on NT, make sure we do placeholder replacement ourselves. | 1343 | ;; If running on NT, make sure we do placeholder replacement |
| 1344 | ;; ourselves. This must come after sql-interactive-mode because all | ||
| 1345 | ;; local variables will be killed, there. | ||
| 1279 | (if (eq window-system 'w32) | 1346 | (if (eq window-system 'w32) |
| 1280 | (setq comint-input-sender 'sql-query-placeholders-and-send)) | 1347 | (setq comint-input-sender 'sql-query-placeholders-and-send)) |
| 1281 | (message "Login...done") | 1348 | (message "Login...done") |
| @@ -1677,6 +1744,56 @@ The default comes from `process-coding-system-alist' and | |||
| 1677 | (message "Login...done") | 1744 | (message "Login...done") |
| 1678 | (pop-to-buffer sql-buffer))) | 1745 | (pop-to-buffer sql-buffer))) |
| 1679 | 1746 | ||
| 1747 | |||
| 1748 | |||
| 1749 | ;;;###autoload | ||
| 1750 | (defun sql-db2 () | ||
| 1751 | "Run db2 by IBM as an inferior process. | ||
| 1752 | |||
| 1753 | If buffer `*SQL*' exists but no process is running, make a new process. | ||
| 1754 | If buffer exists and a process is running, just switch to buffer | ||
| 1755 | `*SQL*'. | ||
| 1756 | |||
| 1757 | Interpreter used comes from variable `sql-db2-program'. There is not | ||
| 1758 | automatic login. | ||
| 1759 | |||
| 1760 | The buffer is put in sql-interactive-mode, giving commands for sending | ||
| 1761 | input. See `sql-interactive-mode'. | ||
| 1762 | |||
| 1763 | If you use \\[sql-accumulate-and-indent] to send multiline commands to db2, | ||
| 1764 | newlines will be escaped if necessary. If you don't want that, use | ||
| 1765 | |||
| 1766 | set `comint-input-sender' back to `comint-simple-send'. | ||
| 1767 | comint-input-sender's value is | ||
| 1768 | comint-simple-send | ||
| 1769 | |||
| 1770 | |||
| 1771 | To specify a coding system for converting non-ASCII characters | ||
| 1772 | in the input and output to the process, use \\[universal-coding-system-argument] | ||
| 1773 | before \\[sql-db2]. You can also specify this with \\[set-buffer-process-coding-system] | ||
| 1774 | in the SQL buffer, after you start the process. | ||
| 1775 | The default comes from `process-coding-system-alist' and | ||
| 1776 | `default-process-coding-system'. | ||
| 1777 | |||
| 1778 | \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" | ||
| 1779 | (interactive) | ||
| 1780 | (if (comint-check-proc "*SQL*") | ||
| 1781 | (pop-to-buffer "*SQL*") | ||
| 1782 | (message "Login...") | ||
| 1783 | ;; Put all parameters to the program (if defined) in a list and call | ||
| 1784 | ;; make-comint. | ||
| 1785 | (set-buffer (apply 'make-comint "SQL" sql-db2-program | ||
| 1786 | nil sql-db2-options)) | ||
| 1787 | (setq sql-prompt-regexp "^db2 => ") | ||
| 1788 | (setq sql-prompt-length 7) | ||
| 1789 | (setq sql-buffer (current-buffer)) | ||
| 1790 | (sql-interactive-mode) | ||
| 1791 | ;; Escape newlines. This must come after sql-interactive-mode | ||
| 1792 | ;; because all local variables will be killed, there. | ||
| 1793 | (setq comint-input-sender 'sql-escape-newlines-and-send) | ||
| 1794 | (message "Login...done") | ||
| 1795 | (pop-to-buffer sql-buffer))) | ||
| 1796 | |||
| 1680 | (provide 'sql) | 1797 | (provide 'sql) |
| 1681 | 1798 | ||
| 1682 | ;;; sql.el ends here | 1799 | ;;; sql.el ends here |