diff options
| author | Michael Mauger | 2010-08-10 19:04:32 -0400 |
|---|---|---|
| committer | Michael Mauger | 2010-08-10 19:04:32 -0400 |
| commit | 3bd2cfef67d5eaf65a50ccc54a1f70a5328cc8d1 (patch) | |
| tree | 3b49fcffc39e7f83180e338274c6308f892709c9 | |
| parent | 490b89acab3e759426ede25c31c94268df55e925 (diff) | |
| download | emacs-3bd2cfef67d5eaf65a50ccc54a1f70a5328cc8d1.tar.gz emacs-3bd2cfef67d5eaf65a50ccc54a1f70a5328cc8d1.zip | |
Suppress continuation prompts in SQL interactive mode
* progmodes/sql.el: Version 2.5
(sql-product-alist): Add :prompt-cont-regexp property for several
database products.
(sql-prompt-cont-regexp): New variable.
(sql-output-newline-count, sql-output-by-send): New
variables. Record number of newlines in input text.
(sql-send-string): Handle multiple filters and count newlines.
(sql-send-magic-terminator): Count terminator newline.
(sql-interactive-remove-continuation-prompt): Filters output to
remove continuation prompts; one for each newline.
(sql-interactive-mode): Set up new variables, prompt regexp and
output filter.
(sql-mode-sqlite-font-lock-keywords): Correct some keywords.
(sql-make-alternate-buffer-name): Correct buffer name in edge
cases.
| -rw-r--r-- | etc/NEWS | 11 | ||||
| -rw-r--r-- | lisp/ChangeLog | 18 | ||||
| -rw-r--r-- | lisp/progmodes/sql.el | 187 |
3 files changed, 167 insertions, 49 deletions
| @@ -283,6 +283,14 @@ variables `sql-product', `sql-user', `sql-server', `sql-database' and | |||
| 283 | The custom variable `sql-port' can be specified for connection to | 283 | The custom variable `sql-port' can be specified for connection to |
| 284 | MySQL servers. | 284 | MySQL servers. |
| 285 | 285 | ||
| 286 | *** Command continuation prompts in SQL interactive mode are suppressed. | ||
| 287 | Multiple line commands in SQL interactive mode, generate command | ||
| 288 | continuation prompts which needlessly confuse the output. These | ||
| 289 | prompts are now filtered out from the output. This change impacts | ||
| 290 | multiple line SQL statements entered with C-j between each line, | ||
| 291 | statements yanked into the buffer and statements sent with | ||
| 292 | `sql-send-*' functions. | ||
| 293 | |||
| 286 | *** Custom variables control prompting for login parameters. | 294 | *** Custom variables control prompting for login parameters. |
| 287 | Each supported product has a custom variable `sql-*-login-params' | 295 | Each supported product has a custom variable `sql-*-login-params' |
| 288 | which is a list of the parameters to be prompted for before a | 296 | which is a list of the parameters to be prompted for before a |
| @@ -302,7 +310,8 @@ names (without the directory portion). Generally these strings will | |||
| 302 | be of the form ".+\.SUF" where SUF is the desired file suffix. | 310 | be of the form ".+\.SUF" where SUF is the desired file suffix. |
| 303 | 311 | ||
| 304 | When :completion is specified, the ARG corresponds to the PREDICATE | 312 | When :completion is specified, the ARG corresponds to the PREDICATE |
| 305 | argument to the `completing-read' function. | 313 | argument to the `completing-read' function (a list of possible values |
| 314 | or a function returning such a list). | ||
| 306 | 315 | ||
| 307 | *** Added `sql-connection-alist' to record login parameter values. | 316 | *** Added `sql-connection-alist' to record login parameter values. |
| 308 | An alist for recording different username, database and server | 317 | An alist for recording different username, database and server |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5d005c4e8a2..6f15ae942fc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,21 @@ | |||
| 1 | 2010-08-10 Michael R. Mauger <mmaug@yahoo.com> | ||
| 2 | |||
| 3 | * progmodes/sql.el: Version 2.5 | ||
| 4 | (sql-product-alist): Add :prompt-cont-regexp property for several | ||
| 5 | database products. | ||
| 6 | (sql-prompt-cont-regexp): New variable. | ||
| 7 | (sql-output-newline-count, sql-output-by-send): New | ||
| 8 | variables. Record number of newlines in input text. | ||
| 9 | (sql-send-string): Handle multiple filters and count newlines. | ||
| 10 | (sql-send-magic-terminator): Count terminator newline. | ||
| 11 | (sql-interactive-remove-continuation-prompt): Filters output to | ||
| 12 | remove continuation prompts; one for each newline. | ||
| 13 | (sql-interactive-mode): Set up new variables, prompt regexp and | ||
| 14 | output filter. | ||
| 15 | (sql-mode-sqlite-font-lock-keywords): Correct some keywords. | ||
| 16 | (sql-make-alternate-buffer-name): Correct buffer name in edge | ||
| 17 | cases. | ||
| 18 | |||
| 1 | 2010-08-10 Stefan Monnier <monnier@iro.umontreal.ca> | 19 | 2010-08-10 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 20 | ||
| 3 | * emacs-lisp/pcase.el: New file. | 21 | * emacs-lisp/pcase.el: New file. |
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index ff75d46ff13..e44504688f2 100644 --- a/lisp/progmodes/sql.el +++ b/lisp/progmodes/sql.el | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | ;; Author: Alex Schroeder <alex@gnu.org> | 6 | ;; Author: Alex Schroeder <alex@gnu.org> |
| 7 | ;; Maintainer: Michael Mauger <mmaug@yahoo.com> | 7 | ;; Maintainer: Michael Mauger <mmaug@yahoo.com> |
| 8 | ;; Version: 2.4 | 8 | ;; Version: 2.5 |
| 9 | ;; Keywords: comm languages processes | 9 | ;; Keywords: comm languages processes |
| 10 | ;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el | 10 | ;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el |
| 11 | ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode | 11 | ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode |
| @@ -336,6 +336,7 @@ Customizing your password will store it in your ~/.emacs file." | |||
| 336 | :sqli-comint-func sql-comint-db2 | 336 | :sqli-comint-func sql-comint-db2 |
| 337 | :prompt-regexp "^db2 => " | 337 | :prompt-regexp "^db2 => " |
| 338 | :prompt-length 7 | 338 | :prompt-length 7 |
| 339 | :prompt-cont-regexp "^db2 (cont\.) => " | ||
| 339 | :input-filter sql-escape-newlines-filter) | 340 | :input-filter sql-escape-newlines-filter) |
| 340 | 341 | ||
| 341 | (informix | 342 | (informix |
| @@ -357,7 +358,8 @@ Customizing your password will store it in your ~/.emacs file." | |||
| 357 | :sqli-login sql-ingres-login-params | 358 | :sqli-login sql-ingres-login-params |
| 358 | :sqli-comint-func sql-comint-ingres | 359 | :sqli-comint-func sql-comint-ingres |
| 359 | :prompt-regexp "^\* " | 360 | :prompt-regexp "^\* " |
| 360 | :prompt-length 2) | 361 | :prompt-length 2 |
| 362 | :prompt-cont-regexp "^\* ") | ||
| 361 | 363 | ||
| 362 | (interbase | 364 | (interbase |
| 363 | :name "Interbase" | 365 | :name "Interbase" |
| @@ -401,6 +403,7 @@ Customizing your password will store it in your ~/.emacs file." | |||
| 401 | :sqli-comint-func sql-comint-mysql | 403 | :sqli-comint-func sql-comint-mysql |
| 402 | :prompt-regexp "^mysql> " | 404 | :prompt-regexp "^mysql> " |
| 403 | :prompt-length 6 | 405 | :prompt-length 6 |
| 406 | :prompt-cont-regexp "^ -> " | ||
| 404 | :input-filter sql-remove-tabs-filter) | 407 | :input-filter sql-remove-tabs-filter) |
| 405 | 408 | ||
| 406 | (oracle | 409 | (oracle |
| @@ -412,6 +415,7 @@ Customizing your password will store it in your ~/.emacs file." | |||
| 412 | :sqli-comint-func sql-comint-oracle | 415 | :sqli-comint-func sql-comint-oracle |
| 413 | :prompt-regexp "^SQL> " | 416 | :prompt-regexp "^SQL> " |
| 414 | :prompt-length 5 | 417 | :prompt-length 5 |
| 418 | :prompt-cont-regexp "^\\s-*\\d+> " | ||
| 415 | :syntax-alist ((?$ . "w") (?# . "w")) | 419 | :syntax-alist ((?$ . "w") (?# . "w")) |
| 416 | :terminator ("\\(^/\\|;\\)" . "/") | 420 | :terminator ("\\(^/\\|;\\)" . "/") |
| 417 | :input-filter sql-placeholders-filter) | 421 | :input-filter sql-placeholders-filter) |
| @@ -424,8 +428,9 @@ Customizing your password will store it in your ~/.emacs file." | |||
| 424 | :sqli-options sql-postgres-options | 428 | :sqli-options sql-postgres-options |
| 425 | :sqli-login sql-postgres-login-params | 429 | :sqli-login sql-postgres-login-params |
| 426 | :sqli-comint-func sql-comint-postgres | 430 | :sqli-comint-func sql-comint-postgres |
| 427 | :prompt-regexp "^.*[#>] *" | 431 | :prompt-regexp "^.*=[#>] " |
| 428 | :prompt-length 5 | 432 | :prompt-length 5 |
| 433 | :prompt-cont-regexp "^.*-[#>] " | ||
| 429 | :input-filter sql-remove-tabs-filter | 434 | :input-filter sql-remove-tabs-filter |
| 430 | :terminator ("\\(^[\\]g\\|;\\)" . ";")) | 435 | :terminator ("\\(^[\\]g\\|;\\)" . ";")) |
| 431 | 436 | ||
| @@ -448,7 +453,9 @@ Customizing your password will store it in your ~/.emacs file." | |||
| 448 | :sqli-login sql-sqlite-login-params | 453 | :sqli-login sql-sqlite-login-params |
| 449 | :sqli-comint-func sql-comint-sqlite | 454 | :sqli-comint-func sql-comint-sqlite |
| 450 | :prompt-regexp "^sqlite> " | 455 | :prompt-regexp "^sqlite> " |
| 451 | :prompt-length 8) | 456 | :prompt-length 8 |
| 457 | :prompt-cont-regexp "^ ...> " | ||
| 458 | :terminator ";") | ||
| 452 | 459 | ||
| 453 | (sybase | 460 | (sybase |
| 454 | :name "Sybase" | 461 | :name "Sybase" |
| @@ -509,6 +516,10 @@ may be any one of the following: | |||
| 509 | 516 | ||
| 510 | :prompt-length length of the prompt on the line. | 517 | :prompt-length length of the prompt on the line. |
| 511 | 518 | ||
| 519 | :prompt-cont-regexp regular expression string that matches | ||
| 520 | the continuation prompt issued by the | ||
| 521 | product interpreter. | ||
| 522 | |||
| 512 | :input-filter function which can filter strings sent to | 523 | :input-filter function which can filter strings sent to |
| 513 | the command interpreter. It is also used | 524 | the command interpreter. It is also used |
| 514 | by the `sql-send-string', | 525 | by the `sql-send-string', |
| @@ -516,7 +527,8 @@ may be any one of the following: | |||
| 516 | and `sql-send-buffer' functions. The | 527 | and `sql-send-buffer' functions. The |
| 517 | function is passed the string sent to the | 528 | function is passed the string sent to the |
| 518 | command interpreter and must return the | 529 | command interpreter and must return the |
| 519 | filtered string. | 530 | filtered string. May also be a list of |
| 531 | such functions. | ||
| 520 | 532 | ||
| 521 | :terminator the terminator to be sent after a | 533 | :terminator the terminator to be sent after a |
| 522 | `sql-send-string', `sql-send-region', | 534 | `sql-send-string', `sql-send-region', |
| @@ -1034,6 +1046,9 @@ You can change `sql-prompt-regexp' on `sql-interactive-mode-hook'.") | |||
| 1034 | 1046 | ||
| 1035 | You can change `sql-prompt-length' on `sql-interactive-mode-hook'.") | 1047 | You can change `sql-prompt-length' on `sql-interactive-mode-hook'.") |
| 1036 | 1048 | ||
| 1049 | (defvar sql-prompt-cont-regexp nil | ||
| 1050 | "Prompt pattern of statement continuation prompts.") | ||
| 1051 | |||
| 1037 | (defvar sql-alternate-buffer-name nil | 1052 | (defvar sql-alternate-buffer-name nil |
| 1038 | "Buffer-local string used to possibly rename the SQLi buffer. | 1053 | "Buffer-local string used to possibly rename the SQLi buffer. |
| 1039 | 1054 | ||
| @@ -1969,10 +1984,9 @@ you define your own `sql-mode-mysql-font-lock-keywords'.") | |||
| 1969 | "abort" "action" "add" "after" "all" "alter" "analyze" "and" "as" | 1984 | "abort" "action" "add" "after" "all" "alter" "analyze" "and" "as" |
| 1970 | "asc" "attach" "autoincrement" "before" "begin" "between" "by" | 1985 | "asc" "attach" "autoincrement" "before" "begin" "between" "by" |
| 1971 | "cascade" "case" "cast" "check" "collate" "column" "commit" "conflict" | 1986 | "cascade" "case" "cast" "check" "collate" "column" "commit" "conflict" |
| 1972 | "constraint" "create" "cross" "current_date" "current_time" | 1987 | "constraint" "create" "cross" "database" "default" "deferrable" |
| 1973 | "current_timestamp" "database" "default" "deferrable" "deferred" | 1988 | "deferred" "delete" "desc" "detach" "distinct" "drop" "each" "else" |
| 1974 | "delete" "desc" "detach" "distinct" "drop" "each" "else" "end" | 1989 | "end" "escape" "except" "exclusive" "exists" "explain" "fail" "for" |
| 1975 | "escape" "except" "exclusive" "exists" "explain" "fail" "for" | ||
| 1976 | "foreign" "from" "full" "glob" "group" "having" "if" "ignore" | 1990 | "foreign" "from" "full" "glob" "group" "having" "if" "ignore" |
| 1977 | "immediate" "in" "index" "indexed" "initially" "inner" "insert" | 1991 | "immediate" "in" "index" "indexed" "initially" "inner" "insert" |
| 1978 | "instead" "intersect" "into" "is" "isnull" "join" "key" "left" "like" | 1992 | "instead" "intersect" "into" "is" "isnull" "join" "key" "left" "like" |
| @@ -1987,9 +2001,9 @@ you define your own `sql-mode-mysql-font-lock-keywords'.") | |||
| 1987 | ;; SQLite Data types | 2001 | ;; SQLite Data types |
| 1988 | (sql-font-lock-keywords-builder 'font-lock-type-face nil | 2002 | (sql-font-lock-keywords-builder 'font-lock-type-face nil |
| 1989 | "int" "integer" "tinyint" "smallint" "mediumint" "bigint" "unsigned" | 2003 | "int" "integer" "tinyint" "smallint" "mediumint" "bigint" "unsigned" |
| 1990 | "big" "int2" "int8" "character" "varchar" "varying" "nchar" "native " | 2004 | "big" "int2" "int8" "character" "varchar" "varying" "nchar" "native" |
| 1991 | "nvarchar" "text" "clob" "blob" "real" "double" "precision" "float" | 2005 | "nvarchar" "text" "clob" "blob" "real" "double" "precision" "float" |
| 1992 | "numeric" "decimal" "boolean" "date" "datetime" | 2006 | "numeric" "number" "decimal" "boolean" "date" "datetime" |
| 1993 | ) | 2007 | ) |
| 1994 | ;; SQLite Functions | 2008 | ;; SQLite Functions |
| 1995 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil | 2009 | (sql-font-lock-keywords-builder 'font-lock-builtin-face nil |
| @@ -2002,6 +2016,7 @@ you define your own `sql-mode-mysql-font-lock-keywords'.") | |||
| 2002 | "typeof" "upper" "zeroblob" | 2016 | "typeof" "upper" "zeroblob" |
| 2003 | ;; Date/time functions | 2017 | ;; Date/time functions |
| 2004 | "time" "julianday" "strftime" | 2018 | "time" "julianday" "strftime" |
| 2019 | "current_date" "current_time" "current_timestamp" | ||
| 2005 | ;; Aggregate functions | 2020 | ;; Aggregate functions |
| 2006 | "avg" "count" "group_concat" "max" "min" "sum" "total" | 2021 | "avg" "count" "group_concat" "max" "min" "sum" "total" |
| 2007 | ))) | 2022 | ))) |
| @@ -2585,25 +2600,33 @@ server/database name." | |||
| 2585 | ;; Build a name using the :sqli-login setting | 2600 | ;; Build a name using the :sqli-login setting |
| 2586 | (setq name | 2601 | (setq name |
| 2587 | (apply 'concat | 2602 | (apply 'concat |
| 2588 | (apply 'append nil | 2603 | (cdr |
| 2589 | (sql-for-each-login | 2604 | (apply 'append nil |
| 2590 | (sql-get-product-feature sql-product :sqli-login) | 2605 | (sql-for-each-login |
| 2591 | (lambda (token type arg) | 2606 | (sql-get-product-feature sql-product :sqli-login) |
| 2592 | (cond | 2607 | (lambda (token type arg) |
| 2593 | ((eq token 'user) (list "/" sql-user)) | 2608 | (cond |
| 2594 | ((eq token 'port) (list ":" sql-port)) | 2609 | ((eq token 'user) |
| 2595 | ((eq token 'server) | 2610 | (unless (string= "" sql-user) |
| 2596 | (list "." (if (eq type :file) | 2611 | (list "/" sql-user))) |
| 2597 | (file-name-nondirectory sql-server) | 2612 | ((eq token 'port) |
| 2598 | sql-server))) | 2613 | (unless (= 0 sql-port) |
| 2599 | ((eq token 'database) | 2614 | (list ":" sql-port))) |
| 2600 | (list "@" (if (eq type :file) | 2615 | ((eq token 'server) |
| 2601 | (file-name-nondirectory sql-database) | 2616 | (unless (string= "" sql-server) |
| 2602 | sql-database))) | 2617 | (list "." |
| 2603 | 2618 | (if (eq type :file) | |
| 2604 | ((eq token 'password) nil) | 2619 | (file-name-nondirectory sql-server) |
| 2605 | (t nil))))))) | 2620 | sql-server)))) |
| 2606 | 2621 | ((eq token 'database) | |
| 2622 | (when (string= "" sql-database) | ||
| 2623 | (list "@" | ||
| 2624 | (if (eq type :file) | ||
| 2625 | (file-name-nondirectory sql-database) | ||
| 2626 | sql-database)))) | ||
| 2627 | |||
| 2628 | ((eq token 'password) nil) | ||
| 2629 | (t nil)))))))) | ||
| 2607 | 2630 | ||
| 2608 | ;; If there's a connection, use it and the name thus far | 2631 | ;; If there's a connection, use it and the name thus far |
| 2609 | (if sql-connection | 2632 | (if sql-connection |
| @@ -2623,8 +2646,8 @@ server/database name." | |||
| 2623 | sql-server) | 2646 | sql-server) |
| 2624 | sql-database)) | 2647 | sql-database)) |
| 2625 | 2648 | ||
| 2626 | ;; We've got a name, go with it (without the first punctuation char) | 2649 | ;; Use the name we've got |
| 2627 | (substring name 1))))) | 2650 | name)))) |
| 2628 | 2651 | ||
| 2629 | (defun sql-rename-buffer () | 2652 | (defun sql-rename-buffer () |
| 2630 | "Rename a SQLi buffer." | 2653 | "Rename a SQLi buffer." |
| @@ -2702,14 +2725,73 @@ Every newline in STRING will be preceded with a space and a backslash." | |||
| 2702 | 2725 | ||
| 2703 | ;;; Input sender for SQLi buffers | 2726 | ;;; Input sender for SQLi buffers |
| 2704 | 2727 | ||
| 2728 | (defvar sql-output-newline-count 0 | ||
| 2729 | "Number of newlines in the input string. | ||
| 2730 | |||
| 2731 | Allows the suppression of continuation prompts.") | ||
| 2732 | |||
| 2733 | (defvar sql-output-by-send nil | ||
| 2734 | "Non-nil if the command in the input was generated by `sql-send-string'.") | ||
| 2735 | |||
| 2705 | (defun sql-input-sender (proc string) | 2736 | (defun sql-input-sender (proc string) |
| 2706 | "Send STRING to PROC after applying filters." | 2737 | "Send STRING to PROC after applying filters." |
| 2707 | 2738 | ||
| 2708 | (let* ((product (with-current-buffer (process-buffer proc) sql-product)) | 2739 | (let* ((product (with-current-buffer (process-buffer proc) sql-product)) |
| 2709 | (filter (sql-get-product-feature product :input-filter))) | 2740 | (filter (sql-get-product-feature product :input-filter))) |
| 2710 | 2741 | ||
| 2742 | ;; Apply filter(s) | ||
| 2743 | (cond | ||
| 2744 | ((not filter) | ||
| 2745 | nil) | ||
| 2746 | ((functionp filter) | ||
| 2747 | (setq string (funcall filter string))) | ||
| 2748 | ((listp filter) | ||
| 2749 | (mapc (lambda (f) (setq string (funcall f string))) filter)) | ||
| 2750 | (t nil)) | ||
| 2751 | |||
| 2752 | ;; Count how many newlines in the string | ||
| 2753 | (setq sql-output-newline-count 0) | ||
| 2754 | (mapc (lambda (ch) | ||
| 2755 | (when (eq ch ?\n) | ||
| 2756 | (setq sql-output-newline-count (1+ sql-output-newline-count)))) | ||
| 2757 | string) | ||
| 2758 | |||
| 2711 | ;; Send the string | 2759 | ;; Send the string |
| 2712 | (comint-simple-send proc (if filter (funcall filter string) string)))) | 2760 | (comint-simple-send proc string))) |
| 2761 | |||
| 2762 | ;;; Strip out continuation prompts | ||
| 2763 | |||
| 2764 | (defun sql-interactive-remove-continuation-prompt (oline) | ||
| 2765 | "Strip out continuation prompts out of the OLINE. | ||
| 2766 | |||
| 2767 | Added to the `comint-preoutput-filter-functions' hook in a SQL | ||
| 2768 | interactive buffer. If `sql-outut-newline-count' is greater than | ||
| 2769 | zero, then an output line matching the continuation prompt is filtered | ||
| 2770 | out. If the count is one, then the prompt is replaced with a newline | ||
| 2771 | to force the output from the query to appear on a new line." | ||
| 2772 | (if (and sql-prompt-cont-regexp | ||
| 2773 | sql-output-newline-count | ||
| 2774 | (numberp sql-output-newline-count) | ||
| 2775 | (>= sql-output-newline-count 1)) | ||
| 2776 | (progn | ||
| 2777 | (while (and oline | ||
| 2778 | sql-output-newline-count | ||
| 2779 | (> sql-output-newline-count 0) | ||
| 2780 | (string-match sql-prompt-cont-regexp oline)) | ||
| 2781 | |||
| 2782 | (setq oline | ||
| 2783 | (replace-match (if (and | ||
| 2784 | (= 1 sql-output-newline-count) | ||
| 2785 | sql-output-by-send) | ||
| 2786 | "\n" "") | ||
| 2787 | nil nil oline) | ||
| 2788 | sql-output-newline-count | ||
| 2789 | (1- sql-output-newline-count))) | ||
| 2790 | (if (= sql-output-newline-count 0) | ||
| 2791 | (setq sql-output-newline-count nil)) | ||
| 2792 | (setq sql-output-by-send nil)) | ||
| 2793 | (setq sql-output-newline-count nil)) | ||
| 2794 | oline) | ||
| 2713 | 2795 | ||
| 2714 | ;;; Sending the region to the SQLi buffer. | 2796 | ;;; Sending the region to the SQLi buffer. |
| 2715 | 2797 | ||
| @@ -2717,26 +2799,20 @@ Every newline in STRING will be preceded with a space and a backslash." | |||
| 2717 | "Send the string STR to the SQL process." | 2799 | "Send the string STR to the SQL process." |
| 2718 | (interactive "sSQL Text: ") | 2800 | (interactive "sSQL Text: ") |
| 2719 | 2801 | ||
| 2720 | (let (comint-input-sender-no-newline proc) | 2802 | (let ((comint-input-sender-no-newline nil) |
| 2803 | (s (replace-regexp-in-string "[[:space:]\n\r]+\\'" "" str))) | ||
| 2721 | (if (buffer-live-p sql-buffer) | 2804 | (if (buffer-live-p sql-buffer) |
| 2722 | (progn | 2805 | (progn |
| 2723 | ;; Ignore the hoping around... | 2806 | ;; Ignore the hoping around... |
| 2724 | (save-excursion | 2807 | (save-excursion |
| 2725 | ;; Get the process | ||
| 2726 | (setq proc (get-buffer-process sql-buffer)) | ||
| 2727 | |||
| 2728 | ;; Set product context | 2808 | ;; Set product context |
| 2729 | (with-current-buffer sql-buffer | 2809 | (with-current-buffer sql-buffer |
| 2730 | ;; Send the string | 2810 | ;; Send the string (trim the trailing whitespace) |
| 2731 | (sql-input-sender proc str) | 2811 | (sql-input-sender (get-buffer-process sql-buffer) s) |
| 2732 | |||
| 2733 | ;; Send a newline if there wasn't one on the end of the string | ||
| 2734 | (unless (string-equal "\n" (substring str (1- (length str)))) | ||
| 2735 | (comint-send-string proc "\n")) | ||
| 2736 | 2812 | ||
| 2737 | ;; Send a command terminator if we must | 2813 | ;; Send a command terminator if we must |
| 2738 | (if sql-send-terminator | 2814 | (if sql-send-terminator |
| 2739 | (sql-send-magic-terminator sql-buffer str sql-send-terminator)) | 2815 | (sql-send-magic-terminator sql-buffer s sql-send-terminator)) |
| 2740 | 2816 | ||
| 2741 | (message "Sent string to buffer %s." (buffer-name sql-buffer)))) | 2817 | (message "Sent string to buffer %s." (buffer-name sql-buffer)))) |
| 2742 | 2818 | ||
| @@ -2771,7 +2847,7 @@ Every newline in STRING will be preceded with a space and a backslash." | |||
| 2771 | 2847 | ||
| 2772 | (defun sql-send-magic-terminator (buf str terminator) | 2848 | (defun sql-send-magic-terminator (buf str terminator) |
| 2773 | "Send TERMINATOR to buffer BUF if its not present in STR." | 2849 | "Send TERMINATOR to buffer BUF if its not present in STR." |
| 2774 | (let (pat term) | 2850 | (let (comint-input-sender-no-newline pat term) |
| 2775 | ;; If flag is merely on(t), get product-specific terminator | 2851 | ;; If flag is merely on(t), get product-specific terminator |
| 2776 | (if (eq terminator t) | 2852 | (if (eq terminator t) |
| 2777 | (setq terminator (sql-get-product-feature sql-product :terminator))) | 2853 | (setq terminator (sql-get-product-feature sql-product :terminator))) |
| @@ -2792,8 +2868,13 @@ Every newline in STRING will be preceded with a space and a backslash." | |||
| 2792 | 2868 | ||
| 2793 | ;; Check to see if the pattern is present in the str already sent | 2869 | ;; Check to see if the pattern is present in the str already sent |
| 2794 | (unless (and pat term | 2870 | (unless (and pat term |
| 2795 | (string-match (concat pat "\n?\\'") str)) | 2871 | (string-match (concat pat "\\'") str)) |
| 2796 | (comint-send-string buf (concat term "\n"))))) | 2872 | (comint-simple-send (get-buffer-process buf) term) |
| 2873 | (setq sql-output-newline-count | ||
| 2874 | (if sql-output-newline-count | ||
| 2875 | (1+ sql-output-newline-count) | ||
| 2876 | 1))) | ||
| 2877 | (setq sql-output-by-send t))) | ||
| 2797 | 2878 | ||
| 2798 | (defun sql-remove-tabs-filter (str) | 2879 | (defun sql-remove-tabs-filter (str) |
| 2799 | "Replace tab characters with spaces." | 2880 | "Replace tab characters with spaces." |
| @@ -2993,12 +3074,22 @@ you entered, right above the output it created. | |||
| 2993 | (sql-get-product-feature sql-product :prompt-regexp)) | 3074 | (sql-get-product-feature sql-product :prompt-regexp)) |
| 2994 | (set (make-local-variable 'sql-prompt-length) | 3075 | (set (make-local-variable 'sql-prompt-length) |
| 2995 | (sql-get-product-feature sql-product :prompt-length)) | 3076 | (sql-get-product-feature sql-product :prompt-length)) |
| 3077 | (set (make-local-variable 'sql-prompt-cont-regexp) | ||
| 3078 | (sql-get-product-feature sql-product :prompt-cont-regexp)) | ||
| 3079 | (make-local-variable 'sql-output-newline-count) | ||
| 3080 | (make-local-variable 'sql-output-by-send) | ||
| 3081 | (add-hook 'comint-preoutput-filter-functions | ||
| 3082 | 'sql-interactive-remove-continuation-prompt nil t) | ||
| 2996 | (make-local-variable 'sql-input-ring-separator) | 3083 | (make-local-variable 'sql-input-ring-separator) |
| 2997 | (make-local-variable 'sql-input-ring-file-name) | 3084 | (make-local-variable 'sql-input-ring-file-name) |
| 2998 | ;; Run the mode hook (along with comint's hooks). | 3085 | ;; Run the mode hook (along with comint's hooks). |
| 2999 | (run-mode-hooks 'sql-interactive-mode-hook) | 3086 | (run-mode-hooks 'sql-interactive-mode-hook) |
| 3000 | ;; Set comint based on user overrides. | 3087 | ;; Set comint based on user overrides. |
| 3001 | (setq comint-prompt-regexp sql-prompt-regexp) | 3088 | (setq comint-prompt-regexp |
| 3089 | (if sql-prompt-cont-regexp | ||
| 3090 | (concat "\\(" sql-prompt-regexp | ||
| 3091 | "\\|" sql-prompt-cont-regexp "\\)") | ||
| 3092 | sql-prompt-regexp)) | ||
| 3002 | (setq left-margin sql-prompt-length) | 3093 | (setq left-margin sql-prompt-length) |
| 3003 | ;; Install input sender | 3094 | ;; Install input sender |
| 3004 | (set (make-local-variable 'comint-input-sender) 'sql-input-sender) | 3095 | (set (make-local-variable 'comint-input-sender) 'sql-input-sender) |