diff options
| author | Miles Bader | 2000-08-07 14:50:09 +0000 |
|---|---|---|
| committer | Miles Bader | 2000-08-07 14:50:09 +0000 |
| commit | 29533923201ac8cf449a41f88fe4264c1d3e0778 (patch) | |
| tree | f12dfd3b0eead8b743bde44276e76d620f0cfc5e | |
| parent | 70fc58b397e82436f081a130c9293e77c7b27207 (diff) | |
| download | emacs-29533923201ac8cf449a41f88fe4264c1d3e0778.tar.gz emacs-29533923201ac8cf449a41f88fe4264c1d3e0778.zip | |
(comint-use-prompt-regexp-instead-of-fields): New variable.
(comint-prompt-regexp, comint-get-old-input): Document dependence on
comint-use-prompt-regexp-instead-of-fields.
(comint-send-input): Add `input' field property to stuff we send to
the process, if comint-use-prompt-regexp-instead-of-fields is nil.
(comint-output-filter): Add `output' field property to process
output, if comint-use-prompt-regexp-instead-of-fields is nil.
(comint-replace-by-expanded-history)
(comint-get-old-input-default, comint-show-output)
(comint-backward-matching-input, comint-forward-matching-input)
(comint-next-prompt, comint-previous-prompt): Use field
properties if comint-use-prompt-regexp-instead-of-fields is nil.
(comint-line-beginning-position): New function.
(comint-bol): Use comint-line-beginning-position. Make ARG optional.
(comint-replace-by-expanded-history-before-point): Use
comint-line-beginning-position and line-end-position.
(comint-last-output-overlay): New variable.
(comint-mode): Make `comint-last-output-overlay' buffer-local.
| -rw-r--r-- | lisp/comint.el | 259 |
1 files changed, 199 insertions, 60 deletions
diff --git a/lisp/comint.el b/lisp/comint.el index 429eb2d11f4..6a0aa2acf0a 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -141,6 +141,7 @@ | |||
| 141 | ;; comint-scroll-to-bottom-on-output symbol ... | 141 | ;; comint-scroll-to-bottom-on-output symbol ... |
| 142 | ;; comint-scroll-show-maximum-output boolean ... | 142 | ;; comint-scroll-show-maximum-output boolean ... |
| 143 | ;; comint-accum-marker maker For comint-accumulate | 143 | ;; comint-accum-marker maker For comint-accumulate |
| 144 | ;; comint-last-output-overlay overlay | ||
| 144 | ;; | 145 | ;; |
| 145 | ;; Comint mode non-buffer local variables: | 146 | ;; Comint mode non-buffer local variables: |
| 146 | ;; comint-completion-addsuffix boolean/cons For file name | 147 | ;; comint-completion-addsuffix boolean/cons For file name |
| @@ -160,11 +161,13 @@ | |||
| 160 | :prefix "comint-" | 161 | :prefix "comint-" |
| 161 | :group 'comint) | 162 | :group 'comint) |
| 162 | 163 | ||
| 163 | |||
| 164 | (defvar comint-prompt-regexp "^" | 164 | (defvar comint-prompt-regexp "^" |
| 165 | "Regexp to recognise prompts in the inferior process. | 165 | "Regexp to recognise prompts in the inferior process. |
| 166 | Defaults to \"^\", the null string at BOL. | 166 | Defaults to \"^\", the null string at BOL. |
| 167 | 167 | ||
| 168 | This variable is only used if the variable | ||
| 169 | `comint-use-prompt-regexp-instead-of-fields' is non-nil. | ||
| 170 | |||
| 168 | Good choices: | 171 | Good choices: |
| 169 | Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp) | 172 | Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp) |
| 170 | Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\" | 173 | Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\" |
| @@ -309,10 +312,12 @@ This is used by `comint-watch-for-password-prompt'." | |||
| 309 | ;; Here are the per-interpreter hooks. | 312 | ;; Here are the per-interpreter hooks. |
| 310 | (defvar comint-get-old-input (function comint-get-old-input-default) | 313 | (defvar comint-get-old-input (function comint-get-old-input-default) |
| 311 | "Function that returns old text in comint mode. | 314 | "Function that returns old text in comint mode. |
| 312 | This function is called when return is typed while the point is in old text. | 315 | This function is called when return is typed while the point is in old |
| 313 | It returns the text to be submitted as process input. The default is | 316 | text. It returns the text to be submitted as process input. The |
| 314 | `comint-get-old-input-default', which grabs the current line, and strips off | 317 | default is `comint-get-old-input-default', which either grabs the |
| 315 | leading text matching `comint-prompt-regexp'.") | 318 | current input field or grabs the current line and strips off leading |
| 319 | text matching `comint-prompt-regexp', depending on the value of | ||
| 320 | `comint-use-prompt-regexp-instead-of-fields'.") | ||
| 316 | 321 | ||
| 317 | (defvar comint-dynamic-complete-functions | 322 | (defvar comint-dynamic-complete-functions |
| 318 | '(comint-replace-by-expanded-history comint-dynamic-complete-filename) | 323 | '(comint-replace-by-expanded-history comint-dynamic-complete-filename) |
| @@ -359,6 +364,18 @@ See `comint-send-input'." | |||
| 359 | :type 'boolean | 364 | :type 'boolean |
| 360 | :group 'comint) | 365 | :group 'comint) |
| 361 | 366 | ||
| 367 | ;; Note: If it is decided to purge comint-prompt-regexp from the source | ||
| 368 | ;; entirely, searching for uses of this variable will help to identify | ||
| 369 | ;; places that need attention. | ||
| 370 | (defcustom comint-use-prompt-regexp-instead-of-fields nil | ||
| 371 | "*If non-nil, use `comint-prompt-regexp' to distinguish prompts from user-input. | ||
| 372 | If nil, then program output and user-input are given different `field' | ||
| 373 | properties, which emacs commands can use to distinguish them (in | ||
| 374 | particular, common movement commands such as begining-of-line respect | ||
| 375 | field boundaries in a natural way)." | ||
| 376 | :type 'boolean | ||
| 377 | :group 'comint) | ||
| 378 | |||
| 362 | (defcustom comint-mode-hook '() | 379 | (defcustom comint-mode-hook '() |
| 363 | "Called upon entry into comint-mode | 380 | "Called upon entry into comint-mode |
| 364 | This is run before the process is cranked up." | 381 | This is run before the process is cranked up." |
| @@ -462,6 +479,7 @@ Entry to this mode runs the hooks on `comint-mode-hook'." | |||
| 462 | (set-marker comint-last-input-end (point-min)) | 479 | (set-marker comint-last-input-end (point-min)) |
| 463 | (make-local-variable 'comint-last-output-start) | 480 | (make-local-variable 'comint-last-output-start) |
| 464 | (setq comint-last-output-start (make-marker)) | 481 | (setq comint-last-output-start (make-marker)) |
| 482 | (make-local-variable 'comint-last-output-overlay) | ||
| 465 | (make-local-variable 'comint-prompt-regexp) ; Don't set; default | 483 | (make-local-variable 'comint-prompt-regexp) ; Don't set; default |
| 466 | (make-local-variable 'comint-input-ring-size) ; ...to global val. | 484 | (make-local-variable 'comint-input-ring-size) ; ...to global val. |
| 467 | (make-local-variable 'comint-input-ring) | 485 | (make-local-variable 'comint-input-ring) |
| @@ -1070,8 +1088,13 @@ Returns t if successful." | |||
| 1070 | (interactive) | 1088 | (interactive) |
| 1071 | (if (and comint-input-autoexpand | 1089 | (if (and comint-input-autoexpand |
| 1072 | (string-match "!\\|^\\^" (funcall comint-get-old-input)) | 1090 | (string-match "!\\|^\\^" (funcall comint-get-old-input)) |
| 1073 | (save-excursion (beginning-of-line) | 1091 | (if comint-use-prompt-regexp-instead-of-fields |
| 1074 | (looking-at comint-prompt-regexp))) | 1092 | ;; Use comint-prompt-regexp |
| 1093 | (save-excursion (beginning-of-line) | ||
| 1094 | (looking-at comint-prompt-regexp)) | ||
| 1095 | ;; Use input fields. User input that hasn't been entered | ||
| 1096 | ;; yet, at the end of the buffer, has a nil `field' property. | ||
| 1097 | (null (get-char-property (point) 'field)))) | ||
| 1075 | ;; Looks like there might be history references in the command. | 1098 | ;; Looks like there might be history references in the command. |
| 1076 | (let ((previous-modified-tick (buffer-modified-tick))) | 1099 | (let ((previous-modified-tick (buffer-modified-tick))) |
| 1077 | (comint-replace-by-expanded-history-before-point silent start) | 1100 | (comint-replace-by-expanded-history-before-point silent start) |
| @@ -1086,15 +1109,11 @@ If the optional argument START is non-nil, that specifies the | |||
| 1086 | start of the text to scan for history references, rather | 1109 | start of the text to scan for history references, rather |
| 1087 | than the logical beginning of line." | 1110 | than the logical beginning of line." |
| 1088 | (save-excursion | 1111 | (save-excursion |
| 1089 | (let ((toend (- (save-excursion (end-of-line nil) (point)) (point))) | 1112 | (let ((toend (- (line-end-position) (point))) |
| 1090 | (start (or start (progn (comint-bol nil) (point))))) | 1113 | (start (comint-line-beginning-position))) |
| 1091 | (while (progn | 1114 | (while (progn |
| 1092 | (skip-chars-forward "^!^" | 1115 | (skip-chars-forward "^!^" (- (line-end-position) toend)) |
| 1093 | (save-excursion | 1116 | (< (point) (- (line-end-position) toend))) |
| 1094 | (end-of-line nil) (- (point) toend))) | ||
| 1095 | (< (point) | ||
| 1096 | (save-excursion | ||
| 1097 | (end-of-line nil) (- (point) toend)))) | ||
| 1098 | ;; This seems a bit complex. We look for references such as !!, !-num, | 1117 | ;; This seems a bit complex. We look for references such as !!, !-num, |
| 1099 | ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^. | 1118 | ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^. |
| 1100 | ;; If that wasn't enough, the plings can be suffixed with argument | 1119 | ;; If that wasn't enough, the plings can be suffixed with argument |
| @@ -1317,8 +1336,10 @@ The values of `comint-get-old-input', `comint-input-filter-functions', and | |||
| 1317 | in the buffer. E.g., | 1336 | in the buffer. E.g., |
| 1318 | 1337 | ||
| 1319 | If the interpreter is the csh, | 1338 | If the interpreter is the csh, |
| 1320 | comint-get-old-input is the default: take the current line, discard any | 1339 | comint-get-old-input is the default: either return the current |
| 1321 | initial string matching regexp comint-prompt-regexp. | 1340 | field, or take the current line and discard any |
| 1341 | initial string matching regexp `comint-prompt-regexp', depending | ||
| 1342 | on the value of `comint-use-prompt-regexp-instead-of-fields'. | ||
| 1322 | comint-input-filter-functions monitors input for \"cd\", \"pushd\", and | 1343 | comint-input-filter-functions monitors input for \"cd\", \"pushd\", and |
| 1323 | \"popd\" commands. When it sees one, it cd's the buffer. | 1344 | \"popd\" commands. When it sees one, it cd's the buffer. |
| 1324 | comint-input-filter is the default: returns t if the input isn't all white | 1345 | comint-input-filter is the default: returns t if the input isn't all white |
| @@ -1360,9 +1381,11 @@ Similarly for Soar, Scheme, etc." | |||
| 1360 | (insert input) | 1381 | (insert input) |
| 1361 | (delete-region pmark start) | 1382 | (delete-region pmark start) |
| 1362 | copy)))) | 1383 | copy)))) |
| 1384 | |||
| 1363 | (if comint-process-echoes | 1385 | (if comint-process-echoes |
| 1364 | (delete-region pmark (point)) | 1386 | (delete-region pmark (point)) |
| 1365 | (insert-before-markers ?\n)) | 1387 | (insert-before-markers ?\n)) |
| 1388 | |||
| 1366 | (if (and (funcall comint-input-filter history) | 1389 | (if (and (funcall comint-input-filter history) |
| 1367 | (or (null comint-input-ignoredups) | 1390 | (or (null comint-input-ignoredups) |
| 1368 | (not (ring-p comint-input-ring)) | 1391 | (not (ring-p comint-input-ring)) |
| @@ -1370,17 +1393,33 @@ Similarly for Soar, Scheme, etc." | |||
| 1370 | (not (string-equal (ring-ref comint-input-ring 0) | 1393 | (not (string-equal (ring-ref comint-input-ring 0) |
| 1371 | history)))) | 1394 | history)))) |
| 1372 | (ring-insert comint-input-ring history)) | 1395 | (ring-insert comint-input-ring history)) |
| 1396 | |||
| 1373 | (run-hook-with-args 'comint-input-filter-functions | 1397 | (run-hook-with-args 'comint-input-filter-functions |
| 1374 | (concat input "\n")) | 1398 | (concat input "\n")) |
| 1399 | |||
| 1375 | (let ((beg (marker-position pmark)) | 1400 | (let ((beg (marker-position pmark)) |
| 1376 | (end (1- (point)))) | 1401 | (end (1- (point)))) |
| 1377 | (when (and comint-highlight-input | 1402 | (when (not (> beg end)) ; handle a special case |
| 1378 | ;; handle a special case | 1403 | ;; Make an overlay for the input field |
| 1379 | (not (> beg end))) | ||
| 1380 | (let ((over (make-overlay beg end))) | 1404 | (let ((over (make-overlay beg end))) |
| 1381 | (overlay-put over 'face comint-highlight-face) | 1405 | (unless comint-use-prompt-regexp-instead-of-fields |
| 1382 | (overlay-put over 'mouse-face 'highlight) | 1406 | ;; Give old user input a field property of `input', to |
| 1407 | ;; distinguish it from both process output and unsent | ||
| 1408 | ;; input. The terminating newline is put into a special | ||
| 1409 | ;; `boundary' field to make cursor movement between input | ||
| 1410 | ;; and output fields smoother. | ||
| 1411 | (overlay-put over 'field 'input) | ||
| 1412 | (overlay-put over 'front-sticky t)) | ||
| 1413 | (when comint-highlight-input | ||
| 1414 | (overlay-put over 'face comint-highlight-face) | ||
| 1415 | (overlay-put over 'mouse-face 'highlight) | ||
| 1416 | (overlay-put over 'evaporate t)))) | ||
| 1417 | (unless comint-use-prompt-regexp-instead-of-fields | ||
| 1418 | ;; Make an overlay for the terminating newline | ||
| 1419 | (let ((over (make-overlay end (1+ end)))) | ||
| 1420 | (overlay-put over 'field 'boundary) | ||
| 1383 | (overlay-put over 'evaporate t)))) | 1421 | (overlay-put over 'evaporate t)))) |
| 1422 | |||
| 1384 | (setq comint-save-input-ring-index comint-input-ring-index) | 1423 | (setq comint-save-input-ring-index comint-input-ring-index) |
| 1385 | (setq comint-input-ring-index nil) | 1424 | (setq comint-input-ring-index nil) |
| 1386 | ;; Update the markers before we send the input | 1425 | ;; Update the markers before we send the input |
| @@ -1409,6 +1448,11 @@ redirection buffer. | |||
| 1409 | 1448 | ||
| 1410 | This variable is permanent-local.") | 1449 | This variable is permanent-local.") |
| 1411 | 1450 | ||
| 1451 | ;; When non-nil, this is the last overlay used for output. | ||
| 1452 | ;; It is kept around so that we can extend it instead of creating | ||
| 1453 | ;; multiple contiguous overlays for multiple contiguous output chunks. | ||
| 1454 | (defvar comint-last-output-overlay nil) | ||
| 1455 | |||
| 1412 | ;; The purpose of using this filter for comint processes | 1456 | ;; The purpose of using this filter for comint processes |
| 1413 | ;; is to keep comint-last-input-end from moving forward | 1457 | ;; is to keep comint-last-input-end from moving forward |
| 1414 | ;; when output is inserted. | 1458 | ;; when output is inserted. |
| @@ -1439,6 +1483,23 @@ This variable is permanent-local.") | |||
| 1439 | (if (<= (point) oend) | 1483 | (if (<= (point) oend) |
| 1440 | (setq oend (+ oend nchars))) | 1484 | (setq oend (+ oend nchars))) |
| 1441 | (insert-before-markers string) | 1485 | (insert-before-markers string) |
| 1486 | |||
| 1487 | (unless comint-use-prompt-regexp-instead-of-fields | ||
| 1488 | ;; We check to see if the last overlay used for output has | ||
| 1489 | ;; already been extended to include STRING (because it was | ||
| 1490 | ;; inserted with insert-before-markers?), and only make | ||
| 1491 | ;; a new overlay if it hasn't. | ||
| 1492 | (unless (and comint-last-output-overlay | ||
| 1493 | (= (overlay-end comint-last-output-overlay) | ||
| 1494 | (point))) | ||
| 1495 | ;; Create a new overlay | ||
| 1496 | (let ((over (make-overlay ostart (point)))) | ||
| 1497 | (overlay-put over 'field 'output) | ||
| 1498 | (overlay-put over 'rear-nonsticky t) | ||
| 1499 | (overlay-put over 'inhibit-line-move-field-capture t) | ||
| 1500 | (overlay-put over 'evaporate t) | ||
| 1501 | (setq comint-last-output-overlay over)))) | ||
| 1502 | |||
| 1442 | ;; Don't insert initial prompt outside the top of the window. | 1503 | ;; Don't insert initial prompt outside the top of the window. |
| 1443 | (if (= (window-start (selected-window)) (point)) | 1504 | (if (= (window-start (selected-window)) (point)) |
| 1444 | (set-window-start (selected-window) (- (point) (length string)))) | 1505 | (set-window-start (selected-window) (- (point) (length string)))) |
| @@ -1552,14 +1613,19 @@ This function could be on `comint-output-filter-functions' or bound to a key." | |||
| 1552 | 1613 | ||
| 1553 | (defun comint-get-old-input-default () | 1614 | (defun comint-get-old-input-default () |
| 1554 | "Default for `comint-get-old-input'. | 1615 | "Default for `comint-get-old-input'. |
| 1555 | Take the current line, and discard any initial text matching | 1616 | Returns either the current field, or the current line with any initial |
| 1556 | `comint-prompt-regexp'." | 1617 | text matching `comint-prompt-regexp' stripped off, depending on the |
| 1557 | (save-excursion | 1618 | value of `comint-use-prompt-regexp-instead-of-fields'." |
| 1558 | (beginning-of-line) | 1619 | (if comint-use-prompt-regexp-instead-of-fields |
| 1559 | (comint-skip-prompt) | 1620 | (save-excursion |
| 1560 | (let ((beg (point))) | 1621 | (beginning-of-line) |
| 1561 | (end-of-line) | 1622 | (comint-skip-prompt) |
| 1562 | (buffer-substring beg (point))))) | 1623 | (let ((beg (point))) |
| 1624 | (end-of-line) | ||
| 1625 | (buffer-substring beg (point)))) | ||
| 1626 | ;; Return the contents of the field at the current point. | ||
| 1627 | (field-string))) | ||
| 1628 | |||
| 1563 | 1629 | ||
| 1564 | (defun comint-copy-old-input () | 1630 | (defun comint-copy-old-input () |
| 1565 | "Insert after prompt old input at point as new input to be edited. | 1631 | "Insert after prompt old input at point as new input to be edited. |
| @@ -1592,15 +1658,38 @@ set the hook `comint-input-sender'." | |||
| 1592 | (comint-send-string proc string) | 1658 | (comint-send-string proc string) |
| 1593 | (comint-send-string proc "\n")) | 1659 | (comint-send-string proc "\n")) |
| 1594 | 1660 | ||
| 1595 | (defun comint-bol (arg) | 1661 | (defun comint-line-beginning-position () |
| 1662 | "Returns the buffer position of the beginning of the line, after any prompt. | ||
| 1663 | If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the | ||
| 1664 | prompt skip is done by skipping text matching the regular expression | ||
| 1665 | `comint-prompt-regexp', a buffer local variable." | ||
| 1666 | (if comint-use-prompt-regexp-instead-of-fields | ||
| 1667 | ;; Use comint-prompt-regexp | ||
| 1668 | (save-excursion | ||
| 1669 | (beginning-of-line) | ||
| 1670 | (comint-skip-prompt) | ||
| 1671 | (point)) | ||
| 1672 | ;; Use input fields. Note that, unlike the behavior of | ||
| 1673 | ;; `line-beginning-position' inside a field, this function will | ||
| 1674 | ;; return the position of the end of a prompt, even if the point is | ||
| 1675 | ;; already inside the prompt. In order to do this, it assumes that | ||
| 1676 | ;; if there are two fields on a line, then the first one is the | ||
| 1677 | ;; prompt, and the second one is an input field, and is front-sticky | ||
| 1678 | ;; (as input fields should be). | ||
| 1679 | (constrain-to-field (line-beginning-position) (line-end-position)))) | ||
| 1680 | |||
| 1681 | (defun comint-bol (&optional arg) | ||
| 1596 | "Goes to the beginning of line, then skips past the prompt, if any. | 1682 | "Goes to the beginning of line, then skips past the prompt, if any. |
| 1597 | If prefix argument is given (\\[universal-argument]) the prompt is not skipped. | 1683 | If prefix argument is given (\\[universal-argument]) the prompt is not skipped. |
| 1598 | 1684 | If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the | |
| 1599 | The prompt skip is done by skipping text matching the regular expression | 1685 | prompt skip is done by skipping text matching the regular expression |
| 1600 | `comint-prompt-regexp', a buffer local variable." | 1686 | `comint-prompt-regexp', a buffer local variable." |
| 1601 | (interactive "P") | 1687 | (interactive "P") |
| 1602 | (beginning-of-line) | 1688 | (if arg |
| 1603 | (if (null arg) (comint-skip-prompt))) | 1689 | ;; Disregard prompt |
| 1690 | (let ((inhibit-field-text-motion t)) | ||
| 1691 | (beginning-of-line)) | ||
| 1692 | (goto-char (comint-line-beginning-position)))) | ||
| 1604 | 1693 | ||
| 1605 | ;; These three functions are for entering text you don't want echoed or | 1694 | ;; These three functions are for entering text you don't want echoed or |
| 1606 | ;; saved -- typically passwords to ftp, telnet, or somesuch. | 1695 | ;; saved -- typically passwords to ftp, telnet, or somesuch. |
| @@ -1721,11 +1810,16 @@ Does not delete the prompt." | |||
| 1721 | Sets mark to the value of point when this command is run." | 1810 | Sets mark to the value of point when this command is run." |
| 1722 | (interactive) | 1811 | (interactive) |
| 1723 | (push-mark) | 1812 | (push-mark) |
| 1724 | (let ((pos (point))) | 1813 | (let ((pos (or (marker-position comint-last-input-end) (point-max)))) |
| 1725 | (goto-char (or (marker-position comint-last-input-end) (point-max))) | 1814 | (cond (comint-use-prompt-regexp-instead-of-fields |
| 1726 | (beginning-of-line 0) | 1815 | (goto-char pos) |
| 1727 | (set-window-start (selected-window) (point)) | 1816 | (beginning-of-line 0) |
| 1728 | (comint-skip-prompt))) | 1817 | (set-window-start (selected-window) (point)) |
| 1818 | (comint-skip-prompt)) | ||
| 1819 | (t | ||
| 1820 | (goto-char (field-beginning pos)) | ||
| 1821 | (set-window-start (selected-window) (point)))))) | ||
| 1822 | |||
| 1729 | 1823 | ||
| 1730 | (defun comint-interrupt-subjob () | 1824 | (defun comint-interrupt-subjob () |
| 1731 | "Interrupt the current subjob. | 1825 | "Interrupt the current subjob. |
| @@ -1793,24 +1887,42 @@ Sends an EOF only if point is at the end of the buffer and there is no input." | |||
| 1793 | 1887 | ||
| 1794 | 1888 | ||
| 1795 | (defun comint-backward-matching-input (regexp arg) | 1889 | (defun comint-backward-matching-input (regexp arg) |
| 1796 | "Search backward through buffer for match for REGEXP. | 1890 | "Search backward through buffer for input fields that match REGEXP. |
| 1797 | Matches are searched for on lines that match `comint-prompt-regexp'. | 1891 | If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then input |
| 1892 | fields are identified by lines that match `comint-prompt-regexp'. | ||
| 1893 | |||
| 1798 | With prefix argument N, search for Nth previous match. | 1894 | With prefix argument N, search for Nth previous match. |
| 1799 | If N is negative, find the next or Nth next match." | 1895 | If N is negative, find the next or Nth next match." |
| 1800 | (interactive (comint-regexp-arg "Backward input matching (regexp): ")) | 1896 | (interactive (comint-regexp-arg "Backward input matching (regexp): ")) |
| 1801 | (let* ((re (concat comint-prompt-regexp ".*" regexp)) | 1897 | (if comint-use-prompt-regexp-instead-of-fields |
| 1802 | (pos (save-excursion (end-of-line (if (> arg 0) 0 1)) | 1898 | ;; Use comint-prompt-regexp |
| 1803 | (if (re-search-backward re nil t arg) | 1899 | (let* ((re (concat comint-prompt-regexp ".*" regexp)) |
| 1804 | (point))))) | 1900 | (pos (save-excursion (end-of-line (if (> arg 0) 0 1)) |
| 1805 | (if (null pos) | 1901 | (if (re-search-backward re nil t arg) |
| 1806 | (progn (message "Not found") | 1902 | (point))))) |
| 1807 | (ding)) | 1903 | (if (null pos) |
| 1808 | (goto-char pos) | 1904 | (progn (message "Not found") |
| 1809 | (comint-bol nil)))) | 1905 | (ding)) |
| 1906 | (goto-char pos) | ||
| 1907 | (comint-bol nil))) | ||
| 1908 | ;; Use input fields | ||
| 1909 | (let* ((dir (if (< arg 0) -1 1)) | ||
| 1910 | (pos | ||
| 1911 | (save-excursion | ||
| 1912 | (while (/= arg 0) | ||
| 1913 | (unless (re-search-backward regexp nil t dir) | ||
| 1914 | (error "Not found")) | ||
| 1915 | (when (eq (get-char-property (point) 'field) 'input) | ||
| 1916 | (setq arg (- arg dir)))) | ||
| 1917 | (field-beginning)))) | ||
| 1918 | (goto-char pos)))) | ||
| 1919 | |||
| 1810 | 1920 | ||
| 1811 | (defun comint-forward-matching-input (regexp arg) | 1921 | (defun comint-forward-matching-input (regexp arg) |
| 1812 | "Search forward through buffer for match for REGEXP. | 1922 | "Search forward through buffer for input fields that match REGEXP. |
| 1813 | Matches are searched for on lines that match `comint-prompt-regexp'. | 1923 | If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then input |
| 1924 | fields are identified by lines that match `comint-prompt-regexp'. | ||
| 1925 | |||
| 1814 | With prefix argument N, search for Nth following match. | 1926 | With prefix argument N, search for Nth following match. |
| 1815 | If N is negative, find the previous or Nth previous match." | 1927 | If N is negative, find the previous or Nth previous match." |
| 1816 | (interactive (comint-regexp-arg "Forward input matching (regexp): ")) | 1928 | (interactive (comint-regexp-arg "Forward input matching (regexp): ")) |
| @@ -1819,16 +1931,39 @@ If N is negative, find the previous or Nth previous match." | |||
| 1819 | 1931 | ||
| 1820 | (defun comint-next-prompt (n) | 1932 | (defun comint-next-prompt (n) |
| 1821 | "Move to end of Nth next prompt in the buffer. | 1933 | "Move to end of Nth next prompt in the buffer. |
| 1822 | See `comint-prompt-regexp'." | 1934 | If `comint-use-prompt-regexp-instead-of-fields' is nil, then this means |
| 1935 | the beginning of the Nth next `input' field, otherwise, it means the Nth | ||
| 1936 | occurance of text matching `comint-prompt-regexp'." | ||
| 1823 | (interactive "p") | 1937 | (interactive "p") |
| 1824 | (let ((paragraph-start comint-prompt-regexp)) | 1938 | (if comint-use-prompt-regexp-instead-of-fields |
| 1825 | (end-of-line (if (> n 0) 1 0)) | 1939 | ;; Use comint-prompt-regexp |
| 1826 | (forward-paragraph n) | 1940 | (let ((paragraph-start comint-prompt-regexp)) |
| 1827 | (comint-skip-prompt))) | 1941 | (end-of-line (if (> n 0) 1 0)) |
| 1942 | (forward-paragraph n) | ||
| 1943 | (comint-skip-prompt)) | ||
| 1944 | ;; Use input fields | ||
| 1945 | (let ((pos (point)) | ||
| 1946 | (input-pos nil)) | ||
| 1947 | (while (/= n 0) | ||
| 1948 | (setq pos | ||
| 1949 | (if (> n 0) | ||
| 1950 | (next-single-char-property-change pos 'field) | ||
| 1951 | (previous-single-char-property-change pos 'field))) | ||
| 1952 | (cond ((null pos) | ||
| 1953 | ;; Ran off the end of the buffer. | ||
| 1954 | (setq n 0)) | ||
| 1955 | ((eq (get-char-property pos 'field) 'input) | ||
| 1956 | (setq n (if (< n 0) (1+ n) (1- n))) | ||
| 1957 | (setq input-pos pos)))) | ||
| 1958 | (when input-pos | ||
| 1959 | (goto-char input-pos))))) | ||
| 1960 | |||
| 1828 | 1961 | ||
| 1829 | (defun comint-previous-prompt (n) | 1962 | (defun comint-previous-prompt (n) |
| 1830 | "Move to end of Nth previous prompt in the buffer. | 1963 | "Move to end of Nth previous prompt in the buffer. |
| 1831 | See `comint-prompt-regexp'." | 1964 | If `comint-use-prompt-regexp-instead-of-fields' is nil, then this means |
| 1965 | the beginning of the Nth previous `input' field, otherwise, it means the Nth | ||
| 1966 | occurance of text matching `comint-prompt-regexp'." | ||
| 1832 | (interactive "p") | 1967 | (interactive "p") |
| 1833 | (comint-next-prompt (- n))) | 1968 | (comint-next-prompt (- n))) |
| 1834 | 1969 | ||
| @@ -2468,6 +2603,10 @@ the process mark is at the beginning of the accumulated input." | |||
| 2468 | ;; a prompt in the comint buffer; however, it is still important to ensure that | 2603 | ;; a prompt in the comint buffer; however, it is still important to ensure that |
| 2469 | ;; this prompt is set correctly. | 2604 | ;; this prompt is set correctly. |
| 2470 | ;; | 2605 | ;; |
| 2606 | ;; XXX: This doesn't work so well unless comint-prompt-regexp is set; | ||
| 2607 | ;; perhaps it should prompt for a terminating string (with an | ||
| 2608 | ;; appropriate magic default by examining what we think is the prompt)? | ||
| 2609 | ;; | ||
| 2471 | 2610 | ||
| 2472 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2611 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2473 | ;; Variables | 2612 | ;; Variables |