;;; sql.el --- specialized comint.el for SQL interpreters
-;; Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
;; Author: Alex Schroeder <alex@gnu.org>
;; Maintainer: Alex Schroeder <alex@gnu.org>
-;; Version: 1.4.10
+;; Version: 1.4.13
;; Keywords: comm languages processes
;; This file is part of GNU Emacs.
;; mail to sql.el-request@gnu.org with `subscribe sql.el FIRSTNAME
;; LASTNAME' in the mail body.
-;; You can get the latest version of this file from my homepage
-;; <URL:http://www.geocities.com/TimesSquare/6120/emacs.html>.
-
;; This file provides a sql-mode and a sql-interactive-mode. My goals
;; were two simple modes providing syntactic hilighting. The
;; interactive mode had to provide a command-line history; the other
;; only appear after the process is exited. This makes things
;; somewhat unreliable.
+;; ChangeLog available on request.
+
;;; To Do:
;; Add better hilight support for other brands; there is a bias towards
;; misc customization of sql.el behaviour
+(defcustom sql-electric-stuff nil
+ "Treat some input as electric.
+If set to the symbol `semicolon', then hitting `;' will send current
+input in the SQLi buffer to the process.
+If set to the symbol `go', then hitting `go' on a line by itself will
+send current input in the SQLi buffer to the process.
+If set to nil, then you must use \\[comint-send-input] in order to send
+current input in the SQLi buffer to the process."
+ :type '(choice (const :tag "Nothing" nil)
+ (const :tag "The semikolon `;'" semicolon)
+ (const :tag "The string `go' by itself" go))
+ :version "20.8"
+ :group 'SQL)
+
(defcustom sql-pop-to-buffer-after-send-region nil
"*If t, pop to the buffer SQL statements are sent to.
("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1))
"Define interesting points in the SQL buffer for `imenu'.
-This is used to rebind `imenu-generic-expression'.")
+This is used to set `imenu-generic-expression' when SQL mode is
+entered. Subsequent changes to sql-imenu-generic-expression will not
+affect existing SQL buffers because imenu-generic-expression is a
+local variable.")
;; history file
:type 'file
:group 'SQL)
+(defcustom sql-oracle-options nil
+ "*List of additional options for `sql-oracle-program'."
+ :type '(repeat string)
+ :version "20.8"
+ :group 'SQL)
+
;; Customisation for MySql
(defcustom sql-mysql-program "mysql"
Used by `sql-rename-buffer'.")
-;; Keymap for sql-interactive-mode, based on comint-mode-map.
-
-(if (not (string-match "XEmacs\\|Lucid" emacs-version))
- (defvar sql-interactive-mode-map
- (let ((map (nconc (make-sparse-keymap) comint-mode-map)))
- (define-key map "\C-j" 'sql-accumulate-and-indent)
- (define-key map "\C-c\C-w" 'sql-copy-column)
- map)
- "Mode map used for `sql-interactive-mode'.")
- ;; XEmacs
- (defvar sql-interactive-mode-map nil)
- (if (not sql-interactive-mode-map)
- (let ((map (make-keymap)))
- (set-keymap-parents map (list comint-mode-map))
- (set-keymap-name map 'sql-interactive-mode-map)
- (define-key map "\C-j" 'sql-accumulate-and-indent)
- (define-key map "\C-c\C-w" 'sql-copy-column)
- (setq sql-interactive-mode-map map))))
+;; Keymap for sql-interactive-mode.
+
+(defvar sql-interactive-mode-map
+ (let ((map (make-sparse-keymap)))
+ (if (functionp 'set-keymap-parent)
+ (set-keymap-parent map comint-mode-map); Emacs
+ (set-keymap-parents map (list comint-mode-map))); XEmacs
+ (if (functionp 'set-keymap-name)
+ (set-keymap-name map 'sql-interactive-mode-map)); XEmacs
+ (define-key map (kbd "C-j") 'sql-accumulate-and-indent)
+ (define-key map (kbd "C-c C-w") 'sql-copy-column)
+ (define-key map (kbd "O") 'sql-magic-go)
+ (define-key map (kbd "o") 'sql-magic-go)
+ (define-key map (kbd ";") 'sql-magic-semicolon)
+ map)
+ "Mode map used for `sql-interactive-mode'.
+Based on `comint-mode-map'.")
;; Keymap for sql-mode.
(defvar sql-mode-map
(let ((map (make-sparse-keymap)))
- (define-key map "\C-c\C-c" 'sql-send-paragraph)
- (define-key map "\C-c\C-r" 'sql-send-region)
- (define-key map "\C-c\C-b" 'sql-send-buffer)
- (define-key map "\t" 'indent-relative)
+ (define-key map (kbd "C-c C-c") 'sql-send-paragraph)
+ (define-key map (kbd "C-c C-r") 'sql-send-region)
+ (define-key map (kbd "C-c C-b") 'sql-send-buffer)
+ (define-key map (kbd "<tab>") 'indent-relative)
map)
"Mode map used for `sql-mode'.")
;;; Small functions
+(defun sql-magic-go (arg)
+ "Insert \"o\" and call `comint-send-input'.
+`sql-electric-stuff' must be the symbol `go'."
+ (interactive "P")
+ (self-insert-command (prefix-numeric-value arg))
+ (if (and (equal sql-electric-stuff 'go)
+ (save-excursion
+ (beginning-of-line)
+ (looking-at (concat sql-prompt-regexp "go\\b"))))
+ (comint-send-input)))
+
+(defun sql-magic-semicolon (arg)
+ "Insert semicolon and call `comint-send-input'.
+`sql-electric-stuff' must be the symbol `semicolon'."
+ (interactive "P")
+ (self-insert-command (prefix-numeric-value arg))
+ (if (equal sql-electric-stuff 'semicolon)
+ (comint-send-input)))
+
(defun sql-accumulate-and-indent ()
"Continue SQL statement on the next line."
(interactive)
- (if (fboundp 'comint-accumulate) (comint-accumulate))
+ (if (fboundp 'comint-accumulate)
+ (comint-accumulate)
+ (newline))
(indent-according-to-mode))
;;;###autoload
"Return the current default SQLi buffer or nil.
In order to qualify, the SQLi buffer must be alive,
be in `sql-interactive-mode' and have a process."
- (if (and (buffer-live-p (default-value 'sql-buffer))
- (get-buffer-process (default-value 'sql-buffer)))
- sql-buffer
- (save-excursion
- (let ((buflist (buffer-list))
- (found))
- (while (not (or (null buflist)
- found))
- (let ((candidate (car buflist)))
- (set-buffer candidate)
- (if (and (equal major-mode 'sql-interactive-mode)
- (get-buffer-process candidate))
- (setq found candidate))
- (setq buflist (cdr buflist))))
- found))))
+ (let ((default-buffer (default-value 'sql-buffer)))
+ (if (and (buffer-live-p default-buffer)
+ (get-buffer-process default-buffer))
+ default-buffer
+ (save-excursion
+ (let ((buflist (buffer-list))
+ (found))
+ (while (not (or (null buflist)
+ found))
+ (let ((candidate (car buflist)))
+ (set-buffer candidate)
+ (if (and (equal major-mode 'sql-interactive-mode)
+ (get-buffer-process candidate))
+ (setq found candidate))
+ (setq buflist (cdr buflist))))
+ found)))))
(defun sql-set-sqli-buffer-generally ()
"Set SQLi buffer for all SQL buffers that have none.
This is used to set `sql-alternate-buffer-name' within
`sql-interactive-mode'."
(concat (if (string= "" sql-user)
- (if (string= "" user-login-name)
+ (if (string= "" (user-login-name))
()
- (concat user-login-name "/"))
+ (concat (user-login-name) "/"))
(concat sql-user "/"))
(if (string= "" sql-database)
(if (string= "" sql-server)
- system-name
+ (system-name)
sql-server)
sql-database)))
Interpreter used comes from variable `sql-oracle-program'. Login uses
the variables `sql-user', `sql-password', and `sql-database' as
-defaults, if set.
+defaults, if set. Additional command line parameters can be stored in
+the list `sql-oracle-options'.
The buffer is put in sql-interactive-mode, giving commands for sending
input. See `sql-interactive-mode'.
(if (and parameter (not (string= "" sql-database)))
(setq parameter (concat parameter "@" sql-database)))
(if parameter
- (set-buffer (make-comint "SQL" sql-oracle-program nil parameter))
+ (setq parameter (nconc (list parameter) sql-oracle-options))
+ (setq parameter sql-oracle-options))
+ (if parameter
+ (set-buffer (apply 'make-comint "SQL" sql-oracle-program nil
+ parameter))
(set-buffer (make-comint "SQL" sql-oracle-program nil))))
(setq sql-prompt-regexp "^SQL> ")
(setq sql-prompt-length 5)
;; username and password are ignored.
(if (string= "" sql-database)
(set-buffer (make-comint "SQL" sql-informix-program nil))
- (set-buffer (make-comint "SQL" sql-informix-program nil sql-database)))
+ (set-buffer (make-comint "SQL" sql-informix-program nil sql-database "-")))
(setq sql-prompt-regexp "^SQL> ")
(setq sql-prompt-length 5)
(setq sql-buffer (current-buffer))