diff options
| author | Alex Schroeder | 1999-09-29 09:51:59 +0000 |
|---|---|---|
| committer | Alex Schroeder | 1999-09-29 09:51:59 +0000 |
| commit | 801d1cb0e4fedf1747a58654174f69e654f07dd7 (patch) | |
| tree | 5be7f6ccb0c268641b6947894bae3c614c9ee5d1 | |
| parent | 76d4fa66d1e423e2c52f32962adcbd12dc82f298 (diff) | |
| download | emacs-801d1cb0e4fedf1747a58654174f69e654f07dd7.tar.gz emacs-801d1cb0e4fedf1747a58654174f69e654f07dd7.zip | |
(sql-imenu-generic-expression): new, used to set
imenu-generic-expression.
(sql-mode): Use ?_ and ?. instead of 95 and 46 when setting
font-lock-defaults' SYNTAX-ALIST. Set imenu-generic-expression,
imenu-case-fold-search, and imenu-syntax-alist.
(sql-interactive-mode): Use ?_ and ?. instead of 95 and 46 when
setting font-lock-defaults' SYNTAX-ALIST.
| -rw-r--r-- | lisp/progmodes/sql.el | 135 |
1 files changed, 83 insertions, 52 deletions
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index 096628944f4..f7defaf54e2 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.4.7 | 7 | ;; Version: 1.4.9 |
| 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. |
| @@ -27,8 +27,8 @@ | |||
| 27 | ;;; Commentary: | 27 | ;;; Commentary: |
| 28 | 28 | ||
| 29 | ;; Please send bug reports and bug fixes to the mailing list at | 29 | ;; Please send bug reports and bug fixes to the mailing list at |
| 30 | ;; sql.el@gnu.org. If you want to subscribe to the mailing list, send | 30 | ;; sql.el@gnu.org. If you want to subscribe to the mailing list, send |
| 31 | ;; mail to sql.el-request@gnu.org with 'subscribe sql.el FIRSTNAME | 31 | ;; mail to sql.el-request@gnu.org with `subscribe sql.el FIRSTNAME |
| 32 | ;; LASTNAME' in the mail body. | 32 | ;; LASTNAME' in the mail body. |
| 33 | 33 | ||
| 34 | ;; You can get the latest version of this file from my homepage | 34 | ;; You can get the latest version of this file from my homepage |
| @@ -39,7 +39,7 @@ | |||
| 39 | ;; interactive mode had to provide a command-line history; the other | 39 | ;; interactive mode had to provide a command-line history; the other |
| 40 | ;; mode had to provide "send region/buffer to SQL interpreter" | 40 | ;; mode had to provide "send region/buffer to SQL interpreter" |
| 41 | ;; functions. "simple" in this context means easy to use, easy to | 41 | ;; functions. "simple" in this context means easy to use, easy to |
| 42 | ;; maintain and little or no bells and whistles. | 42 | ;; maintain and little or no bells and whistles. |
| 43 | 43 | ||
| 44 | ;; If anybody feels like extending this sql mode, take a look at the | 44 | ;; If anybody feels like extending this sql mode, take a look at the |
| 45 | ;; above mentioned modes and write a sqlx-mode on top of this one. If | 45 | ;; above mentioned modes and write a sqlx-mode on top of this one. If |
| @@ -69,7 +69,8 @@ | |||
| 69 | ;; For documentation on the functionality provided by comint mode, and | 69 | ;; For documentation on the functionality provided by comint mode, and |
| 70 | ;; the hooks available for customising it, see the file `comint.el'. | 70 | ;; the hooks available for customising it, see the file `comint.el'. |
| 71 | 71 | ||
| 72 | ;; Hint for newbies: take a look at `dabbrev-expand' and `abbrev-mode'. | 72 | ;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and |
| 73 | ;; `imenu-add-menubar-index'. | ||
| 73 | 74 | ||
| 74 | ;;; Requirements for Emacs 19.34: | 75 | ;;; Requirements for Emacs 19.34: |
| 75 | 76 | ||
| @@ -105,6 +106,7 @@ | |||
| 105 | ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> | 106 | ;; Yair Friedman <yfriedma@JohnBryce.Co.Il> |
| 106 | ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> | 107 | ;; Gregor Zych <zych@pool.informatik.rwth-aachen.de> |
| 107 | ;; nino <nino@inform.dk> | 108 | ;; nino <nino@inform.dk> |
| 109 | ;; Berend de Boer <berend@pobox.com> | ||
| 108 | 110 | ||
| 109 | 111 | ||
| 110 | 112 | ||
| @@ -147,6 +149,8 @@ Customizing your password will store it in your ~/.emacs file." | |||
| 147 | :type 'string | 149 | :type 'string |
| 148 | :group 'SQL) | 150 | :group 'SQL) |
| 149 | 151 | ||
| 152 | ;; misc customization of sql.el behaviour | ||
| 153 | |||
| 150 | (defcustom sql-pop-to-buffer-after-send-region nil | 154 | (defcustom sql-pop-to-buffer-after-send-region nil |
| 151 | "*If t, pop to the buffer SQL statements are sent to. | 155 | "*If t, pop to the buffer SQL statements are sent to. |
| 152 | 156 | ||
| @@ -158,6 +162,17 @@ buffer is shown using `display-buffer'." | |||
| 158 | :type 'boolean | 162 | :type 'boolean |
| 159 | :group 'SQL) | 163 | :group 'SQL) |
| 160 | 164 | ||
| 165 | ;; imenu support for sql-mode. | ||
| 166 | |||
| 167 | (defvar sql-imenu-generic-expression | ||
| 168 | '(("Tables" "^\\s-*create\\s-+table\\s-+\\(\\w+\\)" 1) | ||
| 169 | ("Indexes" "^\\s-*create\\s-+index\\s-+\\(\\w+\\)" 1)) | ||
| 170 | "Define interesting points in the SQL buffer for `imenu'. | ||
| 171 | |||
| 172 | This is used to rebind `imenu-generic-expression'.") | ||
| 173 | |||
| 174 | ;; history file | ||
| 175 | |||
| 161 | (defcustom sql-input-ring-file-name nil | 176 | (defcustom sql-input-ring-file-name nil |
| 162 | "*If non-nil, name of the file to read/write input history. | 177 | "*If non-nil, name of the file to read/write input history. |
| 163 | 178 | ||
| @@ -252,7 +267,7 @@ The program can also specify a TCP connection. See `make-comint'." | |||
| 252 | ;; Customisation for SyBase | 267 | ;; Customisation for SyBase |
| 253 | 268 | ||
| 254 | (defcustom sql-sybase-program "isql" | 269 | (defcustom sql-sybase-program "isql" |
| 255 | "*Command to start isql by SyBase. | 270 | "*Command to start isql by SyBase. |
| 256 | 271 | ||
| 257 | Starts `sql-interactive-mode' after doing some setup. | 272 | Starts `sql-interactive-mode' after doing some setup. |
| 258 | 273 | ||
| @@ -263,7 +278,7 @@ The program can also specify a TCP connection. See `make-comint'." | |||
| 263 | ;; Customisation for Informix | 278 | ;; Customisation for Informix |
| 264 | 279 | ||
| 265 | (defcustom sql-informix-program "dbaccess" | 280 | (defcustom sql-informix-program "dbaccess" |
| 266 | "*Command to start dbaccess by Informix. | 281 | "*Command to start dbaccess by Informix. |
| 267 | 282 | ||
| 268 | Starts `sql-interactive-mode' after doing some setup. | 283 | Starts `sql-interactive-mode' after doing some setup. |
| 269 | 284 | ||
| @@ -274,7 +289,7 @@ The program can also specify a TCP connection. See `make-comint'." | |||
| 274 | ;; Customisation for Ingres | 289 | ;; Customisation for Ingres |
| 275 | 290 | ||
| 276 | (defcustom sql-ingres-program "sql" | 291 | (defcustom sql-ingres-program "sql" |
| 277 | "*Command to start sql by Ingres. | 292 | "*Command to start sql by Ingres. |
| 278 | 293 | ||
| 279 | Starts `sql-interactive-mode' after doing some setup. | 294 | Starts `sql-interactive-mode' after doing some setup. |
| 280 | 295 | ||
| @@ -285,7 +300,7 @@ The program can also specify a TCP connection. See `make-comint'." | |||
| 285 | ;; Customisation for Microsoft | 300 | ;; Customisation for Microsoft |
| 286 | 301 | ||
| 287 | (defcustom sql-ms-program "isql" | 302 | (defcustom sql-ms-program "isql" |
| 288 | "*Command to start isql by Microsoft. | 303 | "*Command to start isql by Microsoft. |
| 289 | 304 | ||
| 290 | Starts `sql-interactive-mode' after doing some setup. | 305 | Starts `sql-interactive-mode' after doing some setup. |
| 291 | 306 | ||
| @@ -296,7 +311,7 @@ The program can also specify a TCP connection. See `make-comint'." | |||
| 296 | ;; Customisation for Postgres | 311 | ;; Customisation for Postgres |
| 297 | 312 | ||
| 298 | (defcustom sql-postgres-program "psql" | 313 | (defcustom sql-postgres-program "psql" |
| 299 | "Command to start psql by Postgres. | 314 | "Command to start psql by Postgres. |
| 300 | 315 | ||
| 301 | Starts `sql-interactive-mode' after doing some setup. | 316 | Starts `sql-interactive-mode' after doing some setup. |
| 302 | 317 | ||
| @@ -346,7 +361,7 @@ Used by `sql-rename-buffer'.") | |||
| 346 | ;; Keymap for sql-interactive-mode, based on comint-mode-map. | 361 | ;; Keymap for sql-interactive-mode, based on comint-mode-map. |
| 347 | 362 | ||
| 348 | (if (not (string-match "XEmacs\\|Lucid" emacs-version)) | 363 | (if (not (string-match "XEmacs\\|Lucid" emacs-version)) |
| 349 | (defvar sql-interactive-mode-map | 364 | (defvar sql-interactive-mode-map |
| 350 | (let ((map (nconc (make-sparse-keymap) comint-mode-map))) | 365 | (let ((map (nconc (make-sparse-keymap) comint-mode-map))) |
| 351 | (define-key map "\C-j" 'sql-accumulate-and-indent) | 366 | (define-key map "\C-j" 'sql-accumulate-and-indent) |
| 352 | (define-key map "\C-c\C-w" 'sql-copy-column) | 367 | (define-key map "\C-c\C-w" 'sql-copy-column) |
| @@ -375,27 +390,27 @@ Used by `sql-rename-buffer'.") | |||
| 375 | 390 | ||
| 376 | ;; easy menu for sql-mode. | 391 | ;; easy menu for sql-mode. |
| 377 | 392 | ||
| 378 | (easy-menu-define | 393 | (easy-menu-define |
| 379 | sql-mode-menu sql-mode-map | 394 | sql-mode-menu sql-mode-map |
| 380 | "Menu for `sql-mode'." | 395 | "Menu for `sql-mode'." |
| 381 | '("SQL" | 396 | '("SQL" |
| 382 | ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer) | 397 | ["Send Paragraph" sql-send-paragraph (and (buffer-live-p sql-buffer) |
| 383 | (get-buffer-process sql-buffer))] | 398 | (get-buffer-process sql-buffer))] |
| 384 | ["Send Region" sql-send-region (and mark-active | 399 | ["Send Region" sql-send-region (and mark-active |
| 385 | (buffer-live-p sql-buffer) | 400 | (buffer-live-p sql-buffer) |
| 386 | (get-buffer-process sql-buffer))] | 401 | (get-buffer-process sql-buffer))] |
| 387 | ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) | 402 | ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) |
| 388 | (get-buffer-process sql-buffer))] | 403 | (get-buffer-process sql-buffer))] |
| 389 | ["Show SQLi buffer" sql-show-sqli-buffer t] | 404 | ["Show SQLi buffer" sql-show-sqli-buffer t] |
| 390 | ["Set SQLi buffer" sql-set-sqli-buffer t] | 405 | ["Set SQLi buffer" sql-set-sqli-buffer t] |
| 391 | ["Pop to SQLi buffer after send" | 406 | ["Pop to SQLi buffer after send" |
| 392 | sql-toggle-pop-to-buffer-after-send-region | 407 | sql-toggle-pop-to-buffer-after-send-region |
| 393 | :style toggle | 408 | :style toggle |
| 394 | :selected sql-pop-to-buffer-after-send-region])) | 409 | :selected sql-pop-to-buffer-after-send-region])) |
| 395 | 410 | ||
| 396 | ;; easy menu for sql-interactive-mode. | 411 | ;; easy menu for sql-interactive-mode. |
| 397 | 412 | ||
| 398 | (easy-menu-define | 413 | (easy-menu-define |
| 399 | sql-interactive-mode-menu sql-interactive-mode-map | 414 | sql-interactive-mode-menu sql-interactive-mode-map |
| 400 | "Menu for `sql-interactive-mode'." | 415 | "Menu for `sql-interactive-mode'." |
| 401 | '("SQL" | 416 | '("SQL" |
| @@ -417,7 +432,7 @@ Used by `sql-rename-buffer'.") | |||
| 417 | 432 | ||
| 418 | ;; Syntax Table | 433 | ;; Syntax Table |
| 419 | 434 | ||
| 420 | (defvar sql-mode-syntax-table | 435 | (defvar sql-mode-syntax-table |
| 421 | (let ((table (make-syntax-table))) | 436 | (let ((table (make-syntax-table))) |
| 422 | ;; C-style comments /**/ (see elisp manual "Syntax Flags")) | 437 | ;; C-style comments /**/ (see elisp manual "Syntax Flags")) |
| 423 | (modify-syntax-entry ?/ ". 14" table) | 438 | (modify-syntax-entry ?/ ". 14" table) |
| @@ -451,7 +466,7 @@ add functions and PL/SQL keywords.") | |||
| 451 | (regexp-opt '( | 466 | (regexp-opt '( |
| 452 | "authorization" "avg" "begin" "close" "cobol" "commit" | 467 | "authorization" "avg" "begin" "close" "cobol" "commit" |
| 453 | "continue" "count" "declare" "double" "end" "escape" | 468 | "continue" "count" "declare" "double" "end" "escape" |
| 454 | "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator" | 469 | "exec" "fetch" "foreign" "fortran" "found" "go" "goto" "indicator" |
| 455 | "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli" | 470 | "key" "language" "max" "min" "module" "numeric" "open" "pascal" "pli" |
| 456 | "precision" "primary" "procedure" "references" "rollback" | 471 | "precision" "primary" "procedure" "references" "rollback" |
| 457 | "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work") t) "\\b"))) | 472 | "schema" "section" "some" "sqlcode" "sqlerror" "sum" "work") t) "\\b"))) |
| @@ -467,8 +482,8 @@ add functions and PL/SQL keywords.") | |||
| 467 | (ansi-types (eval-when-compile | 482 | (ansi-types (eval-when-compile |
| 468 | (concat "\\b" | 483 | (concat "\\b" |
| 469 | (regexp-opt '( | 484 | (regexp-opt '( |
| 470 | ;; ANSI Keywords that look like types | 485 | ;; ANSI Keywords that look like types |
| 471 | "character" "cursor" "dec" "int" "real" | 486 | "character" "cursor" "dec" "int" "real" |
| 472 | ;; ANSI Reserved Word that look like types | 487 | ;; ANSI Reserved Word that look like types |
| 473 | "char" "integer" "smallint" ) t) "\\b")))) | 488 | "char" "integer" "smallint" ) t) "\\b")))) |
| 474 | (setq sql-mode-ansi-font-lock-keywords | 489 | (setq sql-mode-ansi-font-lock-keywords |
| @@ -569,11 +584,11 @@ you define your own sql-mode-postgres-font-lock-keywords.") | |||
| 569 | (regexp-opt '( | 584 | (regexp-opt '( |
| 570 | "language" | 585 | "language" |
| 571 | ) t) "\\b"))) | 586 | ) t) "\\b"))) |
| 572 | (postgres-types (eval-when-compile | 587 | (postgres-types (eval-when-compile |
| 573 | (concat "\\b" | 588 | (concat "\\b" |
| 574 | (regexp-opt '( | 589 | (regexp-opt '( |
| 575 | "bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date" | 590 | "bool" "box" "circle" "char" "char2" "char4" "char8" "char16" "date" |
| 576 | "float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path" | 591 | "float4" "float8" "int2" "int4" "int8" "line" "lseg" "money" "path" |
| 577 | "point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar" | 592 | "point" "polygon" "serial" "text" "time" "timespan" "timestamp" "varchar" |
| 578 | ) t)"\\b"))) | 593 | ) t)"\\b"))) |
| 579 | (postgres-builtin-functions (eval-when-compile | 594 | (postgres-builtin-functions (eval-when-compile |
| @@ -618,7 +633,7 @@ can be changed by some entry functions to provide more hilighting.") | |||
| 618 | 633 | ||
| 619 | ;;;###autoload | 634 | ;;;###autoload |
| 620 | (defun sql-help () | 635 | (defun sql-help () |
| 621 | "Shows short help for the SQL modes. | 636 | "Show short help for the SQL modes. |
| 622 | 637 | ||
| 623 | Use an entry function to open an interactive SQL buffer. This buffer is | 638 | Use an entry function to open an interactive SQL buffer. This buffer is |
| 624 | usually named `*SQL*'. The name of the major mode is SQLi. | 639 | usually named `*SQL*'. The name of the major mode is SQLi. |
| @@ -691,18 +706,18 @@ In order to ask the user for username, password and database, call the | |||
| 691 | function like this: (sql-get-login 'user 'password 'database)." | 706 | function like this: (sql-get-login 'user 'password 'database)." |
| 692 | (interactive) | 707 | (interactive) |
| 693 | (if (memq 'user what) | 708 | (if (memq 'user what) |
| 694 | (setq sql-user | 709 | (setq sql-user |
| 695 | (read-from-minibuffer "User: " sql-user nil nil | 710 | (read-from-minibuffer "User: " sql-user nil nil |
| 696 | sql-user-history))) | 711 | sql-user-history))) |
| 697 | (if (memq 'password what) | 712 | (if (memq 'password what) |
| 698 | (setq sql-password | 713 | (setq sql-password |
| 699 | (sql-read-passwd "Password: " sql-password))) | 714 | (sql-read-passwd "Password: " sql-password))) |
| 700 | (if (memq 'server what) | 715 | (if (memq 'server what) |
| 701 | (setq sql-server | 716 | (setq sql-server |
| 702 | (read-from-minibuffer "Server: " sql-server nil nil | 717 | (read-from-minibuffer "Server: " sql-server nil nil |
| 703 | sql-server-history))) | 718 | sql-server-history))) |
| 704 | (if (memq 'database what) | 719 | (if (memq 'database what) |
| 705 | (setq sql-database | 720 | (setq sql-database |
| 706 | (read-from-minibuffer "Database: " sql-database nil nil | 721 | (read-from-minibuffer "Database: " sql-database nil nil |
| 707 | sql-database-history)))) | 722 | sql-database-history)))) |
| 708 | 723 | ||
| @@ -714,14 +729,14 @@ strings are sent to. Calling this function sets `sql-buffer' and runs | |||
| 714 | `sql-set-sqli-hook'. | 729 | `sql-set-sqli-hook'. |
| 715 | 730 | ||
| 716 | If you call it from a SQL buffer, this sets the local copy of | 731 | If you call it from a SQL buffer, this sets the local copy of |
| 717 | `sql-buffer'. | 732 | `sql-buffer'. |
| 718 | 733 | ||
| 719 | If you call it from anywhere else, it sets the global copy of | 734 | If you call it from anywhere else, it sets the global copy of |
| 720 | `sql-buffer'." | 735 | `sql-buffer'." |
| 721 | (interactive) | 736 | (interactive) |
| 722 | (let ((new-buffer (get-buffer (read-buffer "New SQLi buffer: " nil t)))) | 737 | (let ((new-buffer (get-buffer (read-buffer "New SQLi buffer: " nil t)))) |
| 723 | (if new-buffer | 738 | (if new-buffer |
| 724 | (progn | 739 | (progn |
| 725 | (setq sql-buffer new-buffer) | 740 | (setq sql-buffer new-buffer) |
| 726 | (run-hooks 'sql-set-sqli-hook))))) | 741 | (run-hooks 'sql-set-sqli-hook))))) |
| 727 | 742 | ||
| @@ -770,11 +785,11 @@ Inserts SELECT or commas if appropriate." | |||
| 770 | (goto-char (point-max)) | 785 | (goto-char (point-max)) |
| 771 | (cond | 786 | (cond |
| 772 | ;; if empty command line, insert SELECT | 787 | ;; if empty command line, insert SELECT |
| 773 | ((save-excursion (beginning-of-line) | 788 | ((save-excursion (beginning-of-line) |
| 774 | (looking-at (concat comint-prompt-regexp "$"))) | 789 | (looking-at (concat comint-prompt-regexp "$"))) |
| 775 | (insert "SELECT ")) | 790 | (insert "SELECT ")) |
| 776 | ;; else if appending to SELECT or ORDER BY, insert a comma | 791 | ;; else if appending to SELECT or ORDER BY, insert a comma |
| 777 | ((save-excursion | 792 | ((save-excursion |
| 778 | (re-search-backward "\\b\\(select\\|order by\\) .+" | 793 | (re-search-backward "\\b\\(select\\|order by\\) .+" |
| 779 | (save-excursion (beginning-of-line) (point)) t)) | 794 | (save-excursion (beginning-of-line) (point)) t)) |
| 780 | (insert ", ")) | 795 | (insert ", ")) |
| @@ -801,7 +816,7 @@ Inserts SELECT or commas if appropriate." | |||
| 801 | () | 816 | () |
| 802 | (comint-send-string sql-buffer "\n")) | 817 | (comint-send-string sql-buffer "\n")) |
| 803 | (message "Sent string to buffer %s." (buffer-name sql-buffer)) | 818 | (message "Sent string to buffer %s." (buffer-name sql-buffer)) |
| 804 | (if sql-pop-to-buffer-after-send-region | 819 | (if sql-pop-to-buffer-after-send-region |
| 805 | (pop-to-buffer sql-buffer) | 820 | (pop-to-buffer sql-buffer) |
| 806 | (display-buffer sql-buffer))) | 821 | (display-buffer sql-buffer))) |
| 807 | (message "No SQL process started."))) | 822 | (message "No SQL process started."))) |
| @@ -830,7 +845,7 @@ sql-toggle-pop-to-buffer-after-send-region to VALUE." | |||
| 830 | (interactive "P") | 845 | (interactive "P") |
| 831 | (if value | 846 | (if value |
| 832 | (setq sql-pop-to-buffer-after-send-region value) | 847 | (setq sql-pop-to-buffer-after-send-region value) |
| 833 | (setq sql-pop-to-buffer-after-send-region | 848 | (setq sql-pop-to-buffer-after-send-region |
| 834 | (null sql-pop-to-buffer-after-send-region )))) | 849 | (null sql-pop-to-buffer-after-send-region )))) |
| 835 | 850 | ||
| 836 | 851 | ||
| @@ -845,7 +860,7 @@ You can send SQL statements to the SQLi buffer using | |||
| 845 | \\[sql-send-region]. Such a buffer must exist before you can do this. | 860 | \\[sql-send-region]. Such a buffer must exist before you can do this. |
| 846 | See `sql-help' on how to create SQLi buffers. | 861 | See `sql-help' on how to create SQLi buffers. |
| 847 | 862 | ||
| 848 | \\{sql-mode-map} | 863 | \\{sql-mode-map} |
| 849 | Customization: Entry to this mode runs the `sql-mode-hook'. | 864 | Customization: Entry to this mode runs the `sql-mode-hook'. |
| 850 | 865 | ||
| 851 | When you put a buffer in SQL mode, the buffer stores the last SQLi | 866 | When you put a buffer in SQL mode, the buffer stores the last SQLi |
| @@ -864,20 +879,35 @@ For information on how to create multiple SQLi buffers, see | |||
| 864 | (use-local-map sql-mode-map) | 879 | (use-local-map sql-mode-map) |
| 865 | (set-syntax-table sql-mode-syntax-table) | 880 | (set-syntax-table sql-mode-syntax-table) |
| 866 | (make-local-variable 'font-lock-defaults) | 881 | (make-local-variable 'font-lock-defaults) |
| 867 | (setq font-lock-defaults '(sql-mode-font-lock-keywords | 882 | ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try |
| 868 | nil t ((95 . "w") (46 . "w")))) | 883 | ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column |
| 884 | ;; will have just one quote. Therefore syntactic hilighting is | ||
| 885 | ;; disabled for interactive buffers. `_' and `.' are considered part | ||
| 886 | ;; of words. | ||
| 887 | (setq font-lock-defaults '(sql-mode-font-lock-keywords | ||
| 888 | nil t ((?_ . "w") (?. . "w")))) | ||
| 869 | (make-local-variable 'comment-start) | 889 | (make-local-variable 'comment-start) |
| 870 | (setq comment-start "--") | 890 | (setq comment-start "--") |
| 871 | ;; Make each buffer in sql-mode remeber the "current" SQLi buffer. | 891 | ;; Make each buffer in sql-mode remember the "current" SQLi buffer. |
| 872 | (make-local-variable 'sql-buffer) | 892 | (make-local-variable 'sql-buffer) |
| 893 | ;; Add imenu support for sql-mode. Note that imenu-generic-expression | ||
| 894 | ;; is buffer-local, so we don't need a local-variable for it. SQL is | ||
| 895 | ;; case-insensitive, that's why we have to set imenu-case-fold-search. | ||
| 896 | ;; imenu-syntax-alist makes sure that `_' is considered part of object | ||
| 897 | ;; names. | ||
| 898 | (setq imenu-generic-expression sql-imenu-generic-expression | ||
| 899 | imenu-case-fold-search t | ||
| 900 | imenu-syntax-alist '(("_" . "w"))) | ||
| 873 | ;; Make `sql-send-paragraph' work on paragraphs that contain indented | 901 | ;; Make `sql-send-paragraph' work on paragraphs that contain indented |
| 874 | ;; lines. | 902 | ;; lines. |
| 875 | (make-local-variable 'paragraph-separate) | 903 | (make-local-variable 'paragraph-separate) |
| 876 | (make-local-variable 'paragraph-start) | 904 | (make-local-variable 'paragraph-start) |
| 877 | (setq paragraph-separate "[\f]*$" | 905 | (setq paragraph-separate "[\f]*$" |
| 878 | paragraph-start "[\n\f]") | 906 | paragraph-start "[\n\f]") |
| 907 | ;; Abbrevs | ||
| 879 | (setq local-abbrev-table sql-mode-abbrev-table) | 908 | (setq local-abbrev-table sql-mode-abbrev-table) |
| 880 | (setq abbrev-all-caps 1) | 909 | (setq abbrev-all-caps 1) |
| 910 | ;; Run hook | ||
| 881 | (run-hooks 'sql-mode-hook)) | 911 | (run-hooks 'sql-mode-hook)) |
| 882 | 912 | ||
| 883 | 913 | ||
| @@ -953,7 +983,7 @@ certain length. | |||
| 953 | Here is another example. It will always put point back to the statement | 983 | Here is another example. It will always put point back to the statement |
| 954 | you entered, right above the output it created. | 984 | you entered, right above the output it created. |
| 955 | 985 | ||
| 956 | \(setq comint-output-filter-functions | 986 | \(setq comint-output-filter-functions |
| 957 | \(function (lambda (STR) (comint-show-output))))" | 987 | \(function (lambda (STR) (comint-show-output))))" |
| 958 | (comint-mode) | 988 | (comint-mode) |
| 959 | (setq comint-prompt-regexp sql-prompt-regexp) | 989 | (setq comint-prompt-regexp sql-prompt-regexp) |
| @@ -964,11 +994,12 @@ you entered, right above the output it created. | |||
| 964 | (set-syntax-table sql-mode-syntax-table) | 994 | (set-syntax-table sql-mode-syntax-table) |
| 965 | (make-local-variable 'font-lock-defaults) | 995 | (make-local-variable 'font-lock-defaults) |
| 966 | ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try | 996 | ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try |
| 967 | ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the | 997 | ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column |
| 968 | ;; column will have just one quote. Therefore syntactic hilighting | 998 | ;; will have just one quote. Therefore syntactic hilighting is |
| 969 | ;; is disabled for interactive buffers. | 999 | ;; disabled for interactive buffers. `_' and `.' are considered part |
| 970 | (setq font-lock-defaults '(sql-mode-font-lock-keywords | 1000 | ;; of words. |
| 971 | t t ((95 . "w") (46 . "w")))) | 1001 | (setq font-lock-defaults '(sql-mode-font-lock-keywords |
| 1002 | t t ((?_ . "w") (?. . "w")))) | ||
| 972 | ;; Enable commenting and uncommenting of the region. | 1003 | ;; Enable commenting and uncommenting of the region. |
| 973 | (make-local-variable 'comment-start) | 1004 | (make-local-variable 'comment-start) |
| 974 | (setq comment-start "--") | 1005 | (setq comment-start "--") |
| @@ -1108,7 +1139,7 @@ The default comes from `process-coding-system-alist' and | |||
| 1108 | (setq params (append (list "-P" sql-password) params))) | 1139 | (setq params (append (list "-P" sql-password) params))) |
| 1109 | (if (not (string= "" sql-user)) | 1140 | (if (not (string= "" sql-user)) |
| 1110 | (setq params (append (list "-U" sql-user) params))) | 1141 | (setq params (append (list "-U" sql-user) params))) |
| 1111 | (set-buffer (apply 'make-comint "SQL" sql-sybase-program | 1142 | (set-buffer (apply 'make-comint "SQL" sql-sybase-program |
| 1112 | nil params))) | 1143 | nil params))) |
| 1113 | (setq sql-prompt-regexp "^SQL> ") | 1144 | (setq sql-prompt-regexp "^SQL> ") |
| 1114 | (setq sql-prompt-length 5) | 1145 | (setq sql-prompt-length 5) |
| @@ -1199,7 +1230,7 @@ The default comes from `process-coding-system-alist' and | |||
| 1199 | (setq params (append (list (concat "--password=" sql-password)) params))) | 1230 | (setq params (append (list (concat "--password=" sql-password)) params))) |
| 1200 | (if (not (string= "" sql-user)) | 1231 | (if (not (string= "" sql-user)) |
| 1201 | (setq params (append (list (concat "--user=" sql-user)) params))) | 1232 | (setq params (append (list (concat "--user=" sql-user)) params))) |
| 1202 | (set-buffer (apply 'make-comint "SQL" sql-mysql-program | 1233 | (set-buffer (apply 'make-comint "SQL" sql-mysql-program |
| 1203 | nil params))) | 1234 | nil params))) |
| 1204 | (setq sql-prompt-regexp "^mysql>") | 1235 | (setq sql-prompt-regexp "^mysql>") |
| 1205 | (setq sql-prompt-length 6) | 1236 | (setq sql-prompt-length 6) |
| @@ -1246,7 +1277,7 @@ The default comes from `process-coding-system-alist' and | |||
| 1246 | (setq params (append (list sql-user sql-password) params))) | 1277 | (setq params (append (list sql-user sql-password) params))) |
| 1247 | (if (not (string= "" sql-server)) | 1278 | (if (not (string= "" sql-server)) |
| 1248 | (setq params (append (list sql-server) params))) | 1279 | (setq params (append (list sql-server) params))) |
| 1249 | (set-buffer (apply 'make-comint "SQL" sql-solid-program | 1280 | (set-buffer (apply 'make-comint "SQL" sql-solid-program |
| 1250 | nil params))) | 1281 | nil params))) |
| 1251 | (setq sql-prompt-regexp "^") | 1282 | (setq sql-prompt-regexp "^") |
| 1252 | (setq sql-prompt-length 0) | 1283 | (setq sql-prompt-length 0) |
| @@ -1368,7 +1399,7 @@ in the input and output to the process, use \\[universal-coding-system-argument] | |||
| 1368 | before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system] | 1399 | before \\[sql-postgres]. You can also specify this with \\[set-buffer-process-coding-system] |
| 1369 | in the SQL buffer, after you start the process. | 1400 | in the SQL buffer, after you start the process. |
| 1370 | The default comes from `process-coding-system-alist' and | 1401 | The default comes from `process-coding-system-alist' and |
| 1371 | `default-process-coding-system'. If your output lines end with ^M, | 1402 | `default-process-coding-system'. If your output lines end with ^M, |
| 1372 | your might try undecided-dos as a coding system. If this doesn't help, | 1403 | your might try undecided-dos as a coding system. If this doesn't help, |
| 1373 | Try to set `comint-output-filter-functions' like this: | 1404 | Try to set `comint-output-filter-functions' like this: |
| 1374 | 1405 | ||
| @@ -1387,12 +1418,12 @@ Try to set `comint-output-filter-functions' like this: | |||
| 1387 | (setq params (append (list sql-database) params))) | 1418 | (setq params (append (list sql-database) params))) |
| 1388 | (if (not (string= "" sql-server)) | 1419 | (if (not (string= "" sql-server)) |
| 1389 | (setq params (append (list "-h" sql-server) params))) | 1420 | (setq params (append (list "-h" sql-server) params))) |
| 1390 | (set-buffer (apply 'make-comint "SQL" sql-postgres-program | 1421 | (set-buffer (apply 'make-comint "SQL" sql-postgres-program |
| 1391 | nil params))) | 1422 | nil params))) |
| 1392 | (setq sql-prompt-regexp "^.*> *") | 1423 | (setq sql-prompt-regexp "^.*> *") |
| 1393 | (setq sql-prompt-length 5) | 1424 | (setq sql-prompt-length 5) |
| 1394 | ;; This is a lousy hack to prevent psql from truncating it's output | 1425 | ;; This is a lousy hack to prevent psql from truncating it's output |
| 1395 | ;; and giving stupid warnings. If s.o. knows a way to prevent psql | 1426 | ;; and giving stupid warnings. If s.o. knows a way to prevent psql |
| 1396 | ;; from acting this way, then I would be very thankful to | 1427 | ;; from acting this way, then I would be very thankful to |
| 1397 | ;; incorporate this (Gregor Zych <zych@pool.informatik.rwth-aachen.de>) | 1428 | ;; incorporate this (Gregor Zych <zych@pool.informatik.rwth-aachen.de>) |
| 1398 | (comint-send-string "*SQL*" "\\o \| cat\n") | 1429 | (comint-send-string "*SQL*" "\\o \| cat\n") |