diff options
| author | Michael Mauger | 2013-07-23 20:25:53 -0400 |
|---|---|---|
| committer | Michael Mauger | 2013-07-23 20:25:53 -0400 |
| commit | 3d012865be24995904525eb1b12f51f4d95afcfc (patch) | |
| tree | 6eb9aba3c7bfd50a02949fa1926fd196121a58e2 | |
| parent | da77a2e2ebfd09f70d6b91d868ae9195a9981206 (diff) | |
| download | emacs-3d012865be24995904525eb1b12f51f4d95afcfc.tar.gz emacs-3d012865be24995904525eb1b12f51f4d95afcfc.zip | |
* progmodes/sql.el Version 3.3
(sql-product-alist): Improve oracle :prompt-cont-regexp.
(sql-starts-with-prompt-re, sql-ends-with-prompt-re): New functions.
(sql-interactive-remove-continuation-prompt): Rewrite, use
functions above. Fix continuation prompt and complete output line
handling.
(sql-redirect-one, sql-execute): Use `read-only-mode' on
redirected output buffer.
(sql-mode): Restore deleted code (Bug#13591).
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/progmodes/sql.el | 91 |
2 files changed, 72 insertions, 31 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 424b175f6f8..60880a23f9a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2013-07-23 Michael R. Mauger <michael@mauger.com> | ||
| 2 | |||
| 3 | * progmodes/sql.el Version 3.3 | ||
| 4 | (sql-product-alist): Improve oracle :prompt-cont-regexp. | ||
| 5 | (sql-starts-with-prompt-re, sql-ends-with-prompt-re): New functions. | ||
| 6 | (sql-interactive-remove-continuation-prompt): Rewrite, use | ||
| 7 | functions above. Fix continuation prompt and complete output line | ||
| 8 | handling. | ||
| 9 | (sql-redirect-one, sql-execute): Use `read-only-mode' on | ||
| 10 | redirected output buffer. | ||
| 11 | (sql-mode): Restore deleted code (Bug#13591). | ||
| 12 | |||
| 1 | 2013-07-23 Juanma Barranquero <lekktu@gmail.com> | 13 | 2013-07-23 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 14 | ||
| 3 | * desktop.el (desktop-clear, desktop-list*): Fix previous change. | 15 | * desktop.el (desktop-clear, desktop-list*): Fix previous change. |
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index 940afc3d5f4..56a6f155f31 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: Michael Mauger <michael@mauger.com> | 6 | ;; Maintainer: Michael Mauger <michael@mauger.com> |
| 7 | ;; Version: 3.2 | 7 | ;; Version: 3.3 |
| 8 | ;; Keywords: comm languages processes | 8 | ;; Keywords: comm languages processes |
| 9 | ;; URL: http://savannah.gnu.org/projects/emacs/ | 9 | ;; URL: http://savannah.gnu.org/projects/emacs/ |
| 10 | 10 | ||
| @@ -233,6 +233,7 @@ | |||
| 233 | (require 'regexp-opt)) | 233 | (require 'regexp-opt)) |
| 234 | (require 'custom) | 234 | (require 'custom) |
| 235 | (require 'thingatpt) | 235 | (require 'thingatpt) |
| 236 | (require 'view) | ||
| 236 | 237 | ||
| 237 | (defvar font-lock-keyword-face) | 238 | (defvar font-lock-keyword-face) |
| 238 | (defvar font-lock-set-defaults) | 239 | (defvar font-lock-set-defaults) |
| @@ -246,7 +247,7 @@ | |||
| 246 | :group 'languages | 247 | :group 'languages |
| 247 | :group 'processes) | 248 | :group 'processes) |
| 248 | 249 | ||
| 249 | ;; These four variables will be used as defaults, if set. | 250 | ;; These five variables will be used as defaults, if set. |
| 250 | 251 | ||
| 251 | (defcustom sql-user "" | 252 | (defcustom sql-user "" |
| 252 | "Default username." | 253 | "Default username." |
| @@ -437,7 +438,7 @@ file. Since that is a plaintext file, this could be dangerous." | |||
| 437 | :completion-object sql-oracle-completion-object | 438 | :completion-object sql-oracle-completion-object |
| 438 | :prompt-regexp "^SQL> " | 439 | :prompt-regexp "^SQL> " |
| 439 | :prompt-length 5 | 440 | :prompt-length 5 |
| 440 | :prompt-cont-regexp "^\\s-*[[:digit:]]+ " | 441 | :prompt-cont-regexp "^\\(?:[ ][ ][1-9]\\|[ ][1-9][0-9]\\|[1-9][0-9]\\{2\\}\\)[ ]\\{2\\}" |
| 441 | :statement sql-oracle-statement-starters | 442 | :statement sql-oracle-statement-starters |
| 442 | :syntax-alist ((?$ . "_") (?# . "_")) | 443 | :syntax-alist ((?$ . "_") (?# . "_")) |
| 443 | :terminator ("\\(^/\\|;\\)$" . "/") | 444 | :terminator ("\\(^/\\|;\\)$" . "/") |
| @@ -3276,6 +3277,17 @@ Allows the suppression of continuation prompts.") | |||
| 3276 | 3277 | ||
| 3277 | (defvar sql-preoutput-hold nil) | 3278 | (defvar sql-preoutput-hold nil) |
| 3278 | 3279 | ||
| 3280 | (defun sql-starts-with-prompt-re () | ||
| 3281 | "Anchor the prompt expression at the beginning of the output line. | ||
| 3282 | Remove the start of line regexp." | ||
| 3283 | (replace-regexp-in-string "\\^" "\\\\`" comint-prompt-regexp)) | ||
| 3284 | |||
| 3285 | (defun sql-ends-with-prompt-re () | ||
| 3286 | "Anchor the prompt expression at the end of the output line. | ||
| 3287 | Remove the start of line regexp from the prompt expression since | ||
| 3288 | it may not follow newline characters in the output line." | ||
| 3289 | (concat (replace-regexp-in-string "\\^" "" sql-prompt-regexp) "\\'")) | ||
| 3290 | |||
| 3279 | (defun sql-interactive-remove-continuation-prompt (oline) | 3291 | (defun sql-interactive-remove-continuation-prompt (oline) |
| 3280 | "Strip out continuation prompts out of the OLINE. | 3292 | "Strip out continuation prompts out of the OLINE. |
| 3281 | 3293 | ||
| @@ -3293,38 +3305,52 @@ to the next chunk to properly match the broken-up prompt. | |||
| 3293 | If the filter gets confused, it should reset and stop filtering | 3305 | If the filter gets confused, it should reset and stop filtering |
| 3294 | to avoid deleting non-prompt output." | 3306 | to avoid deleting non-prompt output." |
| 3295 | 3307 | ||
| 3296 | (let (did-filter) | 3308 | (when comint-prompt-regexp |
| 3297 | (setq oline (concat (or sql-preoutput-hold "") oline) | 3309 | (save-match-data |
| 3298 | sql-preoutput-hold nil) | 3310 | (let (prompt-found last-nl) |
| 3299 | |||
| 3300 | (if (and comint-prompt-regexp | ||
| 3301 | (integerp sql-output-newline-count) | ||
| 3302 | (>= sql-output-newline-count 1)) | ||
| 3303 | (progn | ||
| 3304 | (while (and (not (string= oline "")) | ||
| 3305 | (> sql-output-newline-count 0) | ||
| 3306 | (string-match comint-prompt-regexp oline) | ||
| 3307 | (= (match-beginning 0) 0)) | ||
| 3308 | 3311 | ||
| 3309 | (setq oline (replace-match "" nil nil oline) | 3312 | ;; Add this text to what's left from the last pass |
| 3310 | sql-output-newline-count (1- sql-output-newline-count) | 3313 | (setq oline (concat sql-preoutput-hold oline) |
| 3311 | did-filter t)) | 3314 | sql-preoutput-hold "") |
| 3312 | 3315 | ||
| 3316 | ;; If we are looking for multiple prompts | ||
| 3317 | (when (and (integerp sql-output-newline-count) | ||
| 3318 | (>= sql-output-newline-count 1)) | ||
| 3319 | ;; Loop thru each starting prompt and remove it | ||
| 3320 | (let ((start-re (sql-starts-with-prompt-re))) | ||
| 3321 | (while (and (not (string= oline "")) | ||
| 3322 | (> sql-output-newline-count 0) | ||
| 3323 | (string-match start-re oline)) | ||
| 3324 | (setq oline (replace-match "" nil nil oline) | ||
| 3325 | sql-output-newline-count (1- sql-output-newline-count) | ||
| 3326 | prompt-found t))) | ||
| 3327 | |||
| 3328 | ;; If we've found all the expected prompts, stop looking | ||
| 3313 | (if (= sql-output-newline-count 0) | 3329 | (if (= sql-output-newline-count 0) |
| 3314 | (setq sql-output-newline-count nil | 3330 | (setq sql-output-newline-count nil |
| 3315 | oline (concat "\n" oline)) | 3331 | oline (concat "\n" oline)) |
| 3316 | 3332 | ||
| 3333 | ;; Still more possible prompts, leave them for the next pass | ||
| 3317 | (setq sql-preoutput-hold oline | 3334 | (setq sql-preoutput-hold oline |
| 3318 | oline "")) | 3335 | oline ""))) |
| 3319 | 3336 | ||
| 3320 | (unless did-filter | 3337 | ;; If no prompts were found, stop looking |
| 3321 | (setq oline (or sql-preoutput-hold "") | 3338 | (unless prompt-found |
| 3322 | sql-preoutput-hold nil | 3339 | (setq sql-output-newline-count nil |
| 3323 | sql-output-newline-count nil))) | 3340 | oline (concat oline sql-preoutput-hold) |
| 3324 | 3341 | sql-preoutput-hold "")) | |
| 3325 | (setq sql-output-newline-count nil)) | 3342 | |
| 3326 | 3343 | ;; Break up output by physical lines if we haven't hit the final prompt | |
| 3327 | oline)) | 3344 | (unless (and (not (string= oline "")) |
| 3345 | (string-match (sql-ends-with-prompt-re) oline) | ||
| 3346 | (>= (match-end 0) (length oline))) | ||
| 3347 | (setq last-nl 0) | ||
| 3348 | (while (string-match "\n" oline last-nl) | ||
| 3349 | (setq last-nl (match-end 0))) | ||
| 3350 | (setq sql-preoutput-hold (concat (substring oline last-nl) | ||
| 3351 | sql-preoutput-hold) | ||
| 3352 | oline (substring oline 0 last-nl)))))) | ||
| 3353 | oline) | ||
| 3328 | 3354 | ||
| 3329 | ;;; Sending the region to the SQLi buffer. | 3355 | ;;; Sending the region to the SQLi buffer. |
| 3330 | 3356 | ||
| @@ -3462,7 +3488,8 @@ list of SQLi command strings." | |||
| 3462 | :prompt-regexp)) | 3488 | :prompt-regexp)) |
| 3463 | (start nil)) | 3489 | (start nil)) |
| 3464 | (with-current-buffer buf | 3490 | (with-current-buffer buf |
| 3465 | (setq view-read-only nil) | 3491 | (setq-local view-no-disable-on-exit t) |
| 3492 | (read-only-mode -1) | ||
| 3466 | (unless save-prior | 3493 | (unless save-prior |
| 3467 | (erase-buffer)) | 3494 | (erase-buffer)) |
| 3468 | (goto-char (point-max)) | 3495 | (goto-char (point-max)) |
| @@ -3571,8 +3598,8 @@ buffer is popped into a view window." | |||
| 3571 | (get-lru-window)))) | 3598 | (get-lru-window)))) |
| 3572 | (with-current-buffer outbuf | 3599 | (with-current-buffer outbuf |
| 3573 | (set-buffer-modified-p nil) | 3600 | (set-buffer-modified-p nil) |
| 3574 | (setq view-read-only t)) | 3601 | (read-only-mode +1)) |
| 3575 | (view-buffer-other-window outbuf) | 3602 | (pop-to-buffer outbuf) |
| 3576 | (when one-win | 3603 | (when one-win |
| 3577 | (shrink-window-if-larger-than-buffer))))) | 3604 | (shrink-window-if-larger-than-buffer))))) |
| 3578 | 3605 | ||
| @@ -3747,7 +3774,9 @@ must tell Emacs. Here's how to do that in your init file: | |||
| 3747 | (setq-local abbrev-all-caps 1) | 3774 | (setq-local abbrev-all-caps 1) |
| 3748 | ;; Contains the name of database objects | 3775 | ;; Contains the name of database objects |
| 3749 | (set (make-local-variable 'sql-contains-names) t) | 3776 | (set (make-local-variable 'sql-contains-names) t) |
| 3777 | ;; Set syntax and font-face highlighting | ||
| 3750 | ;; Catch changes to sql-product and highlight accordingly | 3778 | ;; Catch changes to sql-product and highlight accordingly |
| 3779 | (sql-set-product (or sql-product 'ansi)) ; Fixes bug#13591 | ||
| 3751 | (add-hook 'hack-local-variables-hook 'sql-highlight-product t t)) | 3780 | (add-hook 'hack-local-variables-hook 'sql-highlight-product t t)) |
| 3752 | 3781 | ||
| 3753 | 3782 | ||