;; Author: Alex Schroeder <alex@gnu.org>
;; Maintainer: Alex Schroeder <alex@gnu.org>
-;; Version: 1.4.7
+;; Version: 1.4.9
;; Keywords: comm languages processes
;; This file is part of GNU Emacs.
;;; Commentary:
;; Please send bug reports and bug fixes to the mailing list at
-;; sql.el@gnu.org. If you want to subscribe to the mailing list, send
-;; mail to sql.el-request@gnu.org with 'subscribe sql.el FIRSTNAME
+;; sql.el@gnu.org. If you want to subscribe to the mailing list, send
+;; 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
;; interactive mode had to provide a command-line history; the other
;; mode had to provide "send region/buffer to SQL interpreter"
;; functions. "simple" in this context means easy to use, easy to
-;; maintain and little or no bells and whistles.
+;; maintain and little or no bells and whistles.
;; If anybody feels like extending this sql mode, take a look at the
;; above mentioned modes and write a sqlx-mode on top of this one. If
;; For documentation on the functionality provided by comint mode, and
;; the hooks available for customising it, see the file `comint.el'.
-;; Hint for newbies: take a look at `dabbrev-expand' and `abbrev-mode'.
+;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and
+;; `imenu-add-menubar-index'.
;;; Requirements for Emacs 19.34:
;; Yair Friedman <yfriedma@JohnBryce.Co.Il>
;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
;; nino <nino@inform.dk>
+;; Berend de Boer <berend@pobox.com>
\f
:type 'string
:group 'SQL)
+;; misc customization of sql.el behaviour
+
(defcustom sql-pop-to-buffer-after-send-region nil
"*If t, pop to the buffer SQL statements are sent to.
:type 'boolean
:group 'SQL)
+;; imenu support for sql-mode.
+
+(defvar sql-imenu-generic-expression
+ '(("Tables" "^\\s-*create\\s-+table\\s-+\\(\\w+\\)" 1)
+ ("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'.")
+
+;; history file
+
(defcustom sql-input-ring-file-name nil
"*If non-nil, name of the file to read/write input history.
;; Customisation for SyBase
(defcustom sql-sybase-program "isql"
- "*Command to start isql by SyBase.
+ "*Command to start isql by SyBase.
Starts `sql-interactive-mode' after doing some setup.
;; Customisation for Informix
(defcustom sql-informix-program "dbaccess"
- "*Command to start dbaccess by Informix.
+ "*Command to start dbaccess by Informix.
Starts `sql-interactive-mode' after doing some setup.
;; Customisation for Ingres
(defcustom sql-ingres-program "sql"
- "*Command to start sql by Ingres.
+ "*Command to start sql by Ingres.
Starts `sql-interactive-mode' after doing some setup.
;; Customisation for Microsoft
(defcustom sql-ms-program "isql"
- "*Command to start isql by Microsoft.
+ "*Command to start isql by Microsoft.
Starts `sql-interactive-mode' after doing some setup.
;; Customisation for Postgres
(defcustom sql-postgres-program "psql"
- "Command to start psql by Postgres.
+ "Command to start psql by Postgres.
Starts `sql-interactive-mode' after doing some setup.
;; Keymap for sql-interactive-mode, based on comint-mode-map.
(if (not (string-match "XEmacs\\|Lucid" emacs-version))
- (defvar sql-interactive-mode-map
+ (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)
;; easy menu for sql-mode.
-(easy-menu-define
- sql-mode-menu sql-mode-map
+(easy-menu-define
+ sql-mode-menu sql-mode-map
"Menu for `sql-mode'."
'("SQL"
["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer)
(get-buffer-process sql-buffer))]
- ["Send Region" sql-send-region (and mark-active
+ ["Send Region" sql-send-region (and mark-active
(buffer-live-p sql-buffer)
(get-buffer-process sql-buffer))]
["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer)
(get-buffer-process sql-buffer))]
["Show SQLi buffer" sql-show-sqli-buffer t]
["Set SQLi buffer" sql-set-sqli-buffer t]
- ["Pop to SQLi buffer after send"
+ ["Pop to SQLi buffer after send"
sql-toggle-pop-to-buffer-after-send-region
:style toggle
:selected sql-pop-to-buffer-after-send-region]))
;; easy menu for sql-interactive-mode.
-(easy-menu-define
+(easy-menu-define
sql-interactive-mode-menu sql-interactive-mode-map
"Menu for `sql-interactive-mode'."
'("SQL"
;; Syntax Table
-(defvar sql-mode-syntax-table
+(defvar sql-mode-syntax-table
(let ((table (make-syntax-table)))
;; C-style comments /**/ (see elisp manual "Syntax Flags"))
(modify-syntax-entry ?/ ". 14" table)
(regexp-opt '(
"authorization" "avg" "begin" "close" "cobol" "commit"
"continue" "count" "declare" "double" "end" "escape"
-"exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
+"exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator"
"key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli"
"precision" "primary" "procedure" "references" "rollback"
"schema" "section" "some" "sqlcode" "sqlerror" "sum" "work") t) "\\b")))
(ansi-types (eval-when-compile
(concat "\\b"
(regexp-opt '(
-;; ANSI Keywords that look like types
-"character" "cursor" "dec" "int" "real"
+;; ANSI Keywords that look like types
+"character" "cursor" "dec" "int" "real"
;; ANSI Reserved Word that look like types
"char" "integer" "smallint" ) t) "\\b"))))
(setq sql-mode-ansi-font-lock-keywords
(regexp-opt '(
"language"
) t) "\\b")))
- (postgres-types (eval-when-compile
- (concat "\\b"
- (regexp-opt '(
-"bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date"
-"float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path"
+ (postgres-types (eval-when-compile
+ (concat "\\b"
+ (regexp-opt '(
+"bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date"
+"float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path"
"point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar"
) t)"\\b")))
(postgres-builtin-functions (eval-when-compile
;;;###autoload
(defun sql-help ()
- "Shows short help for the SQL modes.
+ "Show short help for the SQL modes.
Use an entry function to open an interactive SQL buffer. This buffer is
usually named `*SQL*'. The name of the major mode is SQLi.
function like this: (sql-get-login 'user 'password 'database)."
(interactive)
(if (memq 'user what)
- (setq sql-user
+ (setq sql-user
(read-from-minibuffer "User: " sql-user nil nil
sql-user-history)))
(if (memq 'password what)
- (setq sql-password
+ (setq sql-password
(sql-read-passwd "Password: " sql-password)))
(if (memq 'server what)
- (setq sql-server
+ (setq sql-server
(read-from-minibuffer "Server: " sql-server nil nil
sql-server-history)))
(if (memq 'database what)
- (setq sql-database
+ (setq sql-database
(read-from-minibuffer "Database: " sql-database nil nil
sql-database-history))))
`sql-set-sqli-hook'.
If you call it from a SQL buffer, this sets the local copy of
-`sql-buffer'.
+`sql-buffer'.
If you call it from anywhere else, it sets the global copy of
`sql-buffer'."
(interactive)
(let ((new-buffer (get-buffer (read-buffer "New SQLi buffer: " nil t))))
(if new-buffer
- (progn
+ (progn
(setq sql-buffer new-buffer)
(run-hooks 'sql-set-sqli-hook)))))
(goto-char (point-max))
(cond
;; if empty command line, insert SELECT
- ((save-excursion (beginning-of-line)
+ ((save-excursion (beginning-of-line)
(looking-at (concat comint-prompt-regexp "$")))
(insert "SELECT "))
;; else if appending to SELECT or ORDER BY, insert a comma
- ((save-excursion
+ ((save-excursion
(re-search-backward "\\b\\(select\\|order by\\) .+"
(save-excursion (beginning-of-line) (point)) t))
(insert ", "))
()
(comint-send-string sql-buffer "\n"))
(message "Sent string to buffer %s." (buffer-name sql-buffer))
- (if sql-pop-to-buffer-after-send-region
+ (if sql-pop-to-buffer-after-send-region
(pop-to-buffer sql-buffer)
(display-buffer sql-buffer)))
(message "No SQL process started.")))
(interactive "P")
(if value
(setq sql-pop-to-buffer-after-send-region value)
- (setq sql-pop-to-buffer-after-send-region
+ (setq sql-pop-to-buffer-after-send-region
(null sql-pop-to-buffer-after-send-region ))))
\f
\\[sql-send-region]. Such a buffer must exist before you can do this.
See `sql-help' on how to create SQLi buffers.
-\\{sql-mode-map}
+\\{sql-mode-map}
Customization: Entry to this mode runs the `sql-mode-hook'.
When you put a buffer in SQL mode, the buffer stores the last SQLi
(use-local-map sql-mode-map)
(set-syntax-table sql-mode-syntax-table)
(make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults '(sql-mode-font-lock-keywords
- nil t ((95 . "w") (46 . "w"))))
+ ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
+ ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
+ ;; will have just one quote. Therefore syntactic hilighting is
+ ;; disabled for interactive buffers. `_' and `.' are considered part
+ ;; of words.
+ (setq font-lock-defaults '(sql-mode-font-lock-keywords
+ nil t ((?_ . "w") (?. . "w"))))
(make-local-variable 'comment-start)
(setq comment-start "--")
- ;; Make each buffer in sql-mode remeber the "current" SQLi buffer.
+ ;; Make each buffer in sql-mode remember the "current" SQLi buffer.
(make-local-variable 'sql-buffer)
+ ;; Add imenu support for sql-mode. Note that imenu-generic-expression
+ ;; is buffer-local, so we don't need a local-variable for it. SQL is
+ ;; case-insensitive, that's why we have to set imenu-case-fold-search.
+ ;; imenu-syntax-alist makes sure that `_' is considered part of object
+ ;; names.
+ (setq imenu-generic-expression sql-imenu-generic-expression
+ imenu-case-fold-search t
+ imenu-syntax-alist '(("_" . "w")))
;; Make `sql-send-paragraph' work on paragraphs that contain indented
;; lines.
(make-local-variable 'paragraph-separate)
(make-local-variable 'paragraph-start)
(setq paragraph-separate "[\f]*$"
paragraph-start "[\n\f]")
+ ;; Abbrevs
(setq local-abbrev-table sql-mode-abbrev-table)
(setq abbrev-all-caps 1)
+ ;; Run hook
(run-hooks 'sql-mode-hook))
\f
Here is another example. It will always put point back to the statement
you entered, right above the output it created.
-\(setq comint-output-filter-functions
+\(setq comint-output-filter-functions
\(function (lambda (STR) (comint-show-output))))"
(comint-mode)
(setq comint-prompt-regexp sql-prompt-regexp)
(set-syntax-table sql-mode-syntax-table)
(make-local-variable 'font-lock-defaults)
;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
- ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the
- ;; column will have just one quote. Therefore syntactic hilighting
- ;; is disabled for interactive buffers.
- (setq font-lock-defaults '(sql-mode-font-lock-keywords
- t t ((95 . "w") (46 . "w"))))
+ ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
+ ;; will have just one quote. Therefore syntactic hilighting is
+ ;; disabled for interactive buffers. `_' and `.' are considered part
+ ;; of words.
+ (setq font-lock-defaults '(sql-mode-font-lock-keywords
+ t t ((?_ . "w") (?. . "w"))))
;; Enable commenting and uncommenting of the region.
(make-local-variable 'comment-start)
(setq comment-start "--")
(setq params (append (list "-P" sql-password) params)))
(if (not (string= "" sql-user))
(setq params (append (list "-U" sql-user) params)))
- (set-buffer (apply 'make-comint "SQL" sql-sybase-program
+ (set-buffer (apply 'make-comint "SQL" sql-sybase-program
nil params)))
(setq sql-prompt-regexp "^SQL> ")
(setq sql-prompt-length 5)
(setq params (append (list (concat "--password=" sql-password)) params)))
(if (not (string= "" sql-user))
(setq params (append (list (concat "--user=" sql-user)) params)))
- (set-buffer (apply 'make-comint "SQL" sql-mysql-program
+ (set-buffer (apply 'make-comint "SQL" sql-mysql-program
nil params)))
(setq sql-prompt-regexp "^mysql>")
(setq sql-prompt-length 6)
(setq params (append (list sql-user sql-password) params)))
(if (not (string= "" sql-server))
(setq params (append (list sql-server) params)))
- (set-buffer (apply 'make-comint "SQL" sql-solid-program
+ (set-buffer (apply 'make-comint "SQL" sql-solid-program
nil params)))
(setq sql-prompt-regexp "^")
(setq sql-prompt-length 0)
before \\[sql-postgres]. 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'. If your output lines end with ^M,
+`default-process-coding-system'. If your output lines end with ^M,
your might try undecided-dos as a coding system. If this doesn't help,
Try to set `comint-output-filter-functions' like this:
(setq params (append (list sql-database) params)))
(if (not (string= "" sql-server))
(setq params (append (list "-h" sql-server) params)))
- (set-buffer (apply 'make-comint "SQL" sql-postgres-program
+ (set-buffer (apply 'make-comint "SQL" sql-postgres-program
nil params)))
(setq sql-prompt-regexp "^.*> *")
(setq sql-prompt-length 5)
;; This is a lousy hack to prevent psql from truncating it's output
- ;; and giving stupid warnings. If s.o. knows a way to prevent psql
+ ;; and giving stupid warnings. If s.o. knows a way to prevent psql
;; from acting this way, then I would be very thankful to
;; incorporate this (Gregor Zych <zych@pool.informatik.rwth-aachen.de>)
(comint-send-string "*SQL*" "\\o \| cat\n")