Mercurial > emacs
comparison lisp/comint.el @ 46941:1241ed1e9eee
[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'.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 19 Aug 2002 05:03:21 +0000 |
parents | 2c383709a149 |
children | 714225426f8e |
comparison
equal
deleted
inserted
replaced
46940:545e543e82d5 | 46941:1241ed1e9eee |
---|---|
1523 redirection buffer. | 1523 redirection buffer. |
1524 | 1524 |
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) |
1531 | 1535 |
1532 ;; `snapshot' any current comint-last-prompt-overlay, freezing its | 1536 ;; `snapshot' any current comint-last-prompt-overlay, freezing its |
1537 (let ((inhibit-read-only t)) | 1541 (let ((inhibit-read-only t)) |
1538 (add-text-properties (overlay-start comint-last-prompt-overlay) | 1542 (add-text-properties (overlay-start comint-last-prompt-overlay) |
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 |
1582 ;; when output is inserted. | 1581 ;; when output is inserted. |
1583 (defun comint-output-filter (process string) | 1582 (defun comint-output-filter (process string) |
1658 old-point)))) | 1657 old-point)))) |
1659 | 1658 |
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 |
1667 (let ((inhibit-read-only t)) | 1671 (let ((inhibit-read-only t)) |
1668 (add-text-properties comint-last-output-start (point) | 1672 (add-text-properties comint-last-output-start (point) |