diff options
| author | Miles Bader | 2002-08-19 05:03:21 +0000 |
|---|---|---|
| committer | Miles Bader | 2002-08-19 05:03:21 +0000 |
| commit | 8cda277d9fc7814cb7f6720a2dd79582814ef724 (patch) | |
| tree | d622ebad2597b53b84b6c5d699a21783c75b6a11 | |
| parent | 775b3d2d87ef566e43f56b7dee53b5036d7eba02 (diff) | |
| download | emacs-8cda277d9fc7814cb7f6720a2dd79582814ef724.tar.gz emacs-8cda277d9fc7814cb7f6720a2dd79582814ef724.zip | |
[original idea from Luc Teirlinck <teirllm@mail.auburn.edu>]
(comint-inhibit-carriage-motion): New variable.
(comint-carriage-motion): Argument STRING removed. New arguments
START and END; interpret characters between START and END rather
than using special comint state.
(comint-output-filter): Call `comint-carriage-motion'.
(comint-output-filter-functions): Don't add `comint-carriage-motion'.
| -rw-r--r-- | lisp/comint.el | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/lisp/comint.el b/lisp/comint.el index e7d038e668d..31524572a51 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -1525,6 +1525,10 @@ redirection buffer. | |||
| 1525 | You can use `add-hook' to add functions to this list | 1525 | You can use `add-hook' to add functions to this list |
| 1526 | either globally or locally.") | 1526 | either globally or locally.") |
| 1527 | 1527 | ||
| 1528 | (defvar comint-inhibit-carriage-motion nil | ||
| 1529 | "If nil, comint will interpret `carriage control' characters in output. | ||
| 1530 | See `comint-carriage-motion' for details.") | ||
| 1531 | |||
| 1528 | ;; When non-nil, this is an overlay over the last recognized prompt in | 1532 | ;; When non-nil, this is an overlay over the last recognized prompt in |
| 1529 | ;; the buffer; it is used when highlighting the prompt. | 1533 | ;; the buffer; it is used when highlighting the prompt. |
| 1530 | (defvar comint-last-prompt-overlay nil) | 1534 | (defvar comint-last-prompt-overlay nil) |
| @@ -1539,43 +1543,38 @@ either globally or locally.") | |||
| 1539 | (overlay-end comint-last-prompt-overlay) | 1543 | (overlay-end comint-last-prompt-overlay) |
| 1540 | (overlay-properties comint-last-prompt-overlay))))) | 1544 | (overlay-properties comint-last-prompt-overlay))))) |
| 1541 | 1545 | ||
| 1542 | (defun comint-carriage-motion (string) | 1546 | (defun comint-carriage-motion (start end) |
| 1543 | "Handle carriage control characters in comint output. | 1547 | "Interpret carriage control characters in the region from START to END. |
| 1544 | Translate carriage return/linefeed sequences to linefeeds. | 1548 | Translate carriage return/linefeed sequences to linefeeds. |
| 1545 | Make single carriage returns delete to the beginning of the line. | 1549 | Make single carriage returns delete to the beginning of the line. |
| 1546 | Make backspaces delete the previous character. | 1550 | Make backspaces delete the previous character." |
| 1547 | 1551 | (save-excursion | |
| 1548 | This function should be in the list `comint-output-filter-functions'." | 1552 | ;; First do a quick check to see if there are any applicable |
| 1549 | (save-match-data | 1553 | ;; characters, so we can avoid calling save-match-data and |
| 1550 | ;; We first check to see if STRING contains any magic characters, to | 1554 | ;; save-restriction if not. |
| 1551 | ;; avoid overhead in the common case where it does not | 1555 | (when (< (skip-chars-forward "^\b\r" end) (- end start)) |
| 1552 | (when (string-match "[\r\b]" string) | 1556 | (save-match-data |
| 1553 | (let ((pmark (process-mark (get-buffer-process (current-buffer))))) | 1557 | (save-restriction |
| 1554 | (save-excursion | 1558 | (widen) |
| 1555 | (save-restriction | 1559 | (let ((inhibit-field-text-motion t) |
| 1556 | (widen) | 1560 | (buffer-read-only nil)) |
| 1557 | (let ((inhibit-field-text-motion t) | 1561 | ;; CR LF -> LF |
| 1558 | (buffer-read-only nil)) | 1562 | ;; Note that this won't work properly when the CR and LF |
| 1559 | ;; CR LF -> LF | 1563 | ;; are in different output chunks, but this is probably an |
| 1560 | ;; Note that this won't work properly when the CR and LF | 1564 | ;; exceedingly rare case (because they are generally |
| 1561 | ;; are in different output chunks, but this is probably an | 1565 | ;; written as a unit), and to delay interpretation of a |
| 1562 | ;; exceedingly rare case (because they are generally | 1566 | ;; trailing CR in a chunk would result in odd interactive |
| 1563 | ;; written as a unit), and to delay interpretation of a | 1567 | ;; behavior (and this case is probably far more common). |
| 1564 | ;; trailing CR in a chunk would result in odd interactive | 1568 | (while (re-search-forward "\r$" end t) |
| 1565 | ;; behavior (and this case is probably far more common). | 1569 | (delete-char -1)) |
| 1566 | (goto-char comint-last-output-start) | 1570 | ;; bare CR -> delete preceding line |
| 1567 | (while (re-search-forward "\r$" pmark t) | 1571 | (goto-char start) |
| 1568 | (delete-char -1)) | 1572 | (while (search-forward "\r" end t) |
| 1569 | ;; bare CR -> delete preceding line | 1573 | (delete-region (point) (line-beginning-position))) |
| 1570 | (goto-char comint-last-output-start) | 1574 | ;; BS -> delete preceding character |
| 1571 | (while (search-forward "\r" pmark t) | 1575 | (goto-char start) |
| 1572 | (delete-region (point) (line-beginning-position))) | 1576 | (while (search-forward "\b" end t) |
| 1573 | ;; BS -> delete preceding character | 1577 | (delete-char -2)))))))) |
| 1574 | (goto-char comint-last-output-start) | ||
| 1575 | (while (search-forward "\b" pmark t) | ||
| 1576 | (delete-char -2))))))))) | ||
| 1577 | |||
| 1578 | (add-hook 'comint-output-filter-functions 'comint-carriage-motion) | ||
| 1579 | 1578 | ||
| 1580 | ;; The purpose of using this filter for comint processes | 1579 | ;; The purpose of using this filter for comint processes |
| 1581 | ;; is to keep comint-last-input-end from moving forward | 1580 | ;; is to keep comint-last-input-end from moving forward |
| @@ -1660,7 +1659,12 @@ This function should be in the list `comint-output-filter-functions'." | |||
| 1660 | ;; Advance process-mark | 1659 | ;; Advance process-mark |
| 1661 | (set-marker (process-mark process) (point)) | 1660 | (set-marker (process-mark process) (point)) |
| 1662 | 1661 | ||
| 1662 | (unless comint-inhibit-carriage-motion | ||
| 1663 | ;; Interpret any carriage motion characters (newline, backspace) | ||
| 1664 | (comint-carriage-motion comint-last-output-start (point))) | ||
| 1665 | |||
| 1663 | (run-hook-with-args 'comint-output-filter-functions string) | 1666 | (run-hook-with-args 'comint-output-filter-functions string) |
| 1667 | |||
| 1664 | (goto-char (process-mark process)) ; in case a filter moved it | 1668 | (goto-char (process-mark process)) ; in case a filter moved it |
| 1665 | 1669 | ||
| 1666 | (unless comint-use-prompt-regexp-instead-of-fields | 1670 | (unless comint-use-prompt-regexp-instead-of-fields |