aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorGerd Moellmann <[email protected]>2001-04-20 10:03:48 +0000
committerGerd Moellmann <[email protected]>2001-04-20 10:03:48 +0000
commit624ef9b3c207db38614ae91f90e47e89c36817c9 (patch)
treeff6ca800d0792133151eadb6d3c462b09f9e3a37 /lisp/progmodes
parent939d70190345618e4f5300429be1b799106b2b27 (diff)
(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.
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/sql.el123
1 files changed, 120 insertions, 3 deletions
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 189507acbf..932c5b2511 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -4,7 +4,7 @@
;; Author: Alex Schroeder <[email protected]>
;; Maintainer: Alex Schroeder <[email protected]>
-;; Version: 1.5.0
+;; Version: 1.6.1
;; Keywords: comm languages processes
;; This file is part of GNU Emacs.
@@ -381,6 +381,23 @@ The program can also specify a TCP connection. See `make-comint'."
:version "20.8"
:group 'SQL)
+;; Customization for DB2
+
+(defcustom sql-db2-program "db2"
+ "*Command to start db2 by IBM.
+
+Starts `sql-interactive-mode' after doing some setup.
+
+The program can also specify a TCP connection. See `make-comint'."
+ :type 'file
+ :group 'SQL)
+
+(defcustom sql-db2-options nil
+ "*List of additional options for `sql-db2-program'."
+ :type '(repeat string)
+ :version "20.8"
+ :group 'SQL)
+
;;; Variables which do not need customization
@@ -468,7 +485,11 @@ Based on `comint-mode-map'.")
["Pop to SQLi buffer after send"
sql-toggle-pop-to-buffer-after-send-region
:style toggle
- :selected sql-pop-to-buffer-after-send-region]))
+ :selected sql-pop-to-buffer-after-send-region]
+ ("Highlighting"
+ ["ANSI SQL keywords" sql-highlight-ansi-keywords t]
+ ["Oracle keywords" sql-highlight-oracle-keywords t]
+ ["Postgres keywords" sql-highlight-postgres-keywords t])))
;; easy menu for sql-interactive-mode.
@@ -697,6 +718,31 @@ can be changed by some entry functions to provide more hilighting.")
+;;; Functions to switch highlighting
+
+(defun sql-highlight-oracle-keywords ()
+ "Highlight Oracle keywords.
+Basically, this just sets `font-lock-keywords' appropriately."
+ (interactive)
+ (setq font-lock-keywords sql-mode-oracle-font-lock-keywords)
+ (font-lock-fontify-buffer))
+
+(defun sql-highlight-postgres-keywords ()
+ "Highlight Postgres keywords.
+Basically, this just sets `font-lock-keywords' appropriately."
+ (interactive)
+ (setq font-lock-keywords sql-mode-postgres-font-lock-keywords)
+ (font-lock-fontify-buffer))
+
+(defun sql-highlight-ansi-keywords ()
+ "Highlight ANSI SQL keywords.
+Basically, this just sets `font-lock-keywords' appropriately."
+ (interactive)
+ (setq font-lock-keywords sql-mode-ansi-font-lock-keywords)
+ (font-lock-fontify-buffer))
+
+
+
;;; Compatibility functions
(if (not (fboundp 'comint-line-beginning-position))
@@ -758,6 +804,7 @@ Other non-free SQL implementations are also supported:
Sybase: \\[sql-sybase]
Ingres: \\[sql-ingres]
Microsoft: \\[sql-ms]
+ Interbase: \\[sql-interbase]
But we urge you to choose a free implementation instead of these.
@@ -979,6 +1026,24 @@ This function is used for `comint-input-sender' if using `sql-oracle' on NT."
(comint-send-string proc string)
(comint-send-string proc "\n"))
+;; Using DB2 interactively, newlines must be escaped with " \".
+;; The space before the backslash is relevant.
+(defun sql-escape-newlines-and-send (proc string)
+ "Send to PROC input STRING, escaping newlines if necessary.
+Every newline in STRING will be preceded with a space and a backslash."
+ (let ((result "") (start 0) mb me)
+ (while (string-match "\n" string start)
+ (setq mb (match-beginning 0)
+ me (match-end 0))
+ (if (and (> mb 1)
+ (string-equal " \\" (substring string (- mb 2) mb)))
+ (setq result (concat result (substring string start me)))
+ (setq result (concat result (substring string start mb) " \\\n")))
+ (setq start me))
+ (setq result (concat result (substring string start)))
+ (comint-send-string proc result)
+ (comint-send-string proc "\n")))
+
;;; Sending the region to the SQLi buffer.
@@ -1275,7 +1340,9 @@ The default comes from `process-coding-system-alist' and
;; calling sql-interactive-mode.
(setq sql-mode-font-lock-keywords sql-mode-oracle-font-lock-keywords)
(sql-interactive-mode)
- ;; If running on NT, make sure we do placeholder replacement ourselves.
+ ;; If running on NT, make sure we do placeholder replacement
+ ;; ourselves. This must come after sql-interactive-mode because all
+ ;; local variables will be killed, there.
(if (eq window-system 'w32)
(setq comint-input-sender 'sql-query-placeholders-and-send))
(message "Login...done")
@@ -1677,6 +1744,56 @@ The default comes from `process-coding-system-alist' and
(message "Login...done")
(pop-to-buffer sql-buffer)))
+
+
+;;;###autoload
+(defun sql-db2 ()
+ "Run db2 by IBM as an inferior process.
+
+If buffer `*SQL*' exists but no process is running, make a new process.
+If buffer exists and a process is running, just switch to buffer
+`*SQL*'.
+
+Interpreter used comes from variable `sql-db2-program'. There is not
+automatic login.
+
+The buffer is put in sql-interactive-mode, giving commands for sending
+input. See `sql-interactive-mode'.
+
+If you use \\[sql-accumulate-and-indent] to send multiline commands to db2,
+newlines will be escaped if necessary. If you don't want that, use
+
+set `comint-input-sender' back to `comint-simple-send'.
+comint-input-sender's value is
+comint-simple-send
+
+
+To specify a coding system for converting non-ASCII characters
+in the input and output to the process, use \\[universal-coding-system-argument]
+before \\[sql-db2]. You can also specify this with \\[set-buffer-process-coding-system]
+in the SQL buffer, after you start the process.
+The default comes from `process-coding-system-alist' and
+`default-process-coding-system'.
+
+\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
+ (interactive)
+ (if (comint-check-proc "*SQL*")
+ (pop-to-buffer "*SQL*")
+ (message "Login...")
+ ;; Put all parameters to the program (if defined) in a list and call
+ ;; make-comint.
+ (set-buffer (apply 'make-comint "SQL" sql-db2-program
+ nil sql-db2-options))
+ (setq sql-prompt-regexp "^db2 => ")
+ (setq sql-prompt-length 7)
+ (setq sql-buffer (current-buffer))
+ (sql-interactive-mode)
+ ;; Escape newlines. This must come after sql-interactive-mode
+ ;; because all local variables will be killed, there.
+ (setq comint-input-sender 'sql-escape-newlines-and-send)
+ (message "Login...done")
+ (pop-to-buffer sql-buffer)))
+
(provide 'sql)
;;; sql.el ends here