diff options
| author | Miles Bader | 2002-06-10 08:14:59 +0000 |
|---|---|---|
| committer | Miles Bader | 2002-06-10 08:14:59 +0000 |
| commit | 3238a55c37a3ec4e73ffd4a3202d70fd231328ac (patch) | |
| tree | d7d6b8de68b26d2604df018363e8728b240a1067 | |
| parent | 85fd1cfa83bfff596fabab6d26fd6207c158d858 (diff) | |
| download | emacs-3238a55c37a3ec4e73ffd4a3202d70fd231328ac.tar.gz emacs-3238a55c37a3ec4e73ffd4a3202d70fd231328ac.zip | |
Make comint use text properties for highlighting instead of overlays:
(comint-last-output-overlay): Variable removed.
(comint-send-input, comint-output-filter): Use text properties instead
of overlays.
(comint-insert-clicked-input): Rewrite to work with text properties as
well as overlays.
(comint-snapshot-last-prompt): Snapshot using text properties.
(comint-get-old-input-default, comint-extract-string): Don't copy text
properties.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/comint.el | 121 |
2 files changed, 61 insertions, 70 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fcd53795c80..cd4ccd1e490 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,15 @@ | |||
| 1 | 2002-06-10 Miles Bader <miles@gnu.org> | 1 | 2002-06-10 Miles Bader <miles@gnu.org> |
| 2 | 2 | ||
| 3 | Make comint use text properties for highlighting instead of overlays: | ||
| 4 | * comint.el (comint-last-output-overlay): Variable removed. | ||
| 5 | (comint-send-input, comint-output-filter): Use text properties | ||
| 6 | instead of overlays. | ||
| 7 | (comint-insert-clicked-input): Rewrite to work with text | ||
| 8 | properties as well as overlays | ||
| 9 | (comint-snapshot-last-prompt): Snapshot using text properties. | ||
| 10 | (comint-get-old-input-default, comint-extract-string): Don't copy | ||
| 11 | text properties. | ||
| 12 | |||
| 3 | * simple.el (line-move-finish): Inhibit field motion when | 13 | * simple.el (line-move-finish): Inhibit field motion when |
| 4 | computing `line-end'. | 14 | computing `line-end'. |
| 5 | 15 | ||
diff --git a/lisp/comint.el b/lisp/comint.el index ca6f2e6f018..d6247dd14a6 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -140,7 +140,6 @@ | |||
| 140 | ;; comint-scroll-to-bottom-on-output symbol ... | 140 | ;; comint-scroll-to-bottom-on-output symbol ... |
| 141 | ;; comint-scroll-show-maximum-output boolean ... | 141 | ;; comint-scroll-show-maximum-output boolean ... |
| 142 | ;; comint-accum-marker maker For comint-accumulate | 142 | ;; comint-accum-marker maker For comint-accumulate |
| 143 | ;; comint-last-output-overlay overlay | ||
| 144 | ;; | 143 | ;; |
| 145 | ;; Comint mode non-buffer local variables: | 144 | ;; Comint mode non-buffer local variables: |
| 146 | ;; comint-completion-addsuffix boolean/cons For file name | 145 | ;; comint-completion-addsuffix boolean/cons For file name |
| @@ -477,7 +476,6 @@ Entry to this mode runs the hooks on `comint-mode-hook'." | |||
| 477 | (set (make-local-variable 'comint-last-input-start) (point-min-marker)) | 476 | (set (make-local-variable 'comint-last-input-start) (point-min-marker)) |
| 478 | (set (make-local-variable 'comint-last-input-end) (point-min-marker)) | 477 | (set (make-local-variable 'comint-last-input-end) (point-min-marker)) |
| 479 | (set (make-local-variable 'comint-last-output-start) (make-marker)) | 478 | (set (make-local-variable 'comint-last-output-start) (make-marker)) |
| 480 | (make-local-variable 'comint-last-output-overlay) | ||
| 481 | (make-local-variable 'comint-last-prompt-overlay) | 479 | (make-local-variable 'comint-last-prompt-overlay) |
| 482 | (make-local-variable 'comint-prompt-regexp) ; Don't set; default | 480 | (make-local-variable 'comint-prompt-regexp) ; Don't set; default |
| 483 | (make-local-variable 'comint-input-ring-size) ; ...to global val. | 481 | (make-local-variable 'comint-input-ring-size) ; ...to global val. |
| @@ -768,27 +766,26 @@ buffer. The hook `comint-exec-hook' is run after each exec." | |||
| 768 | (defun comint-insert-clicked-input (event) | 766 | (defun comint-insert-clicked-input (event) |
| 769 | "In a comint buffer, set the current input to the clicked-on previous input." | 767 | "In a comint buffer, set the current input to the clicked-on previous input." |
| 770 | (interactive "e") | 768 | (interactive "e") |
| 771 | (let ((over (catch 'found | 769 | (let ((pos (posn-point (event-end event)))) |
| 772 | ;; Ignore non-input overlays | 770 | (if (not (eq (get-char-property pos 'field) 'input)) |
| 773 | (dolist (ov (overlays-at (posn-point (event-end event)))) | 771 | ;; No input at POS, fall back to the global definition. |
| 774 | (when (eq (overlay-get ov 'field) 'input) | 772 | (let* ((keys (this-command-keys)) |
| 775 | (throw 'found ov)))))) | 773 | (last-key (and (vectorp keys) (aref keys (1- (length keys))))) |
| 776 | ;; Do we have input in this area? | 774 | (fun (and last-key (lookup-key global-map (vector last-key))))) |
| 777 | (if over | 775 | (and fun (call-interactively fun))) |
| 778 | (let ((input-str (buffer-substring (overlay-start over) | 776 | ;; There's previous input at POS, insert it at the end of the buffer. |
| 779 | (overlay-end over)))) | 777 | (goto-char (point-max)) |
| 780 | (goto-char (point-max)) | 778 | ;; First delete any old unsent input at the end |
| 781 | (delete-region | 779 | (delete-region |
| 782 | ;; Can't use kill-region as it sets this-command | 780 | (or (marker-position comint-accum-marker) |
| 783 | (or (marker-position comint-accum-marker) | 781 | (process-mark (get-buffer-process (current-buffer)))) |
| 784 | (process-mark (get-buffer-process (current-buffer)))) | 782 | (point)) |
| 785 | (point)) | 783 | ;; Insert the clicked-upon input |
| 786 | (insert input-str)) | 784 | (insert-buffer-substring |
| 787 | ;; Fall back to the global definition. | 785 | (current-buffer) |
| 788 | (let* ((keys (this-command-keys)) | 786 | (previous-single-char-property-change (1+ pos) 'field) |
| 789 | (last-key (and (vectorp keys) (aref keys (1- (length keys))))) | 787 | (next-single-char-property-change pos 'field))))) |
| 790 | (fun (and last-key (lookup-key global-map (vector last-key))))) | 788 | |
| 791 | (if fun (call-interactively fun)))))) | ||
| 792 | 789 | ||
| 793 | 790 | ||
| 794 | ;; Input history processing in a buffer | 791 | ;; Input history processing in a buffer |
| @@ -1450,27 +1447,26 @@ Similarly for Soar, Scheme, etc." | |||
| 1450 | (let ((beg (marker-position pmark)) | 1447 | (let ((beg (marker-position pmark)) |
| 1451 | (end (if no-newline (point) (1- (point))))) | 1448 | (end (if no-newline (point) (1- (point))))) |
| 1452 | (when (not (> beg end)) ; handle a special case | 1449 | (when (not (> beg end)) ; handle a special case |
| 1453 | ;; Make an overlay for the input field | 1450 | ;; Set text-properties for the input field |
| 1454 | (let ((over (make-overlay beg end nil nil t))) | 1451 | (add-text-properties |
| 1455 | (unless comint-use-prompt-regexp-instead-of-fields | 1452 | beg end |
| 1456 | ;; Give old user input a field property of `input', to | 1453 | '(front-sticky t |
| 1457 | ;; distinguish it from both process output and unsent | 1454 | font-lock-face comint-highlight-input |
| 1458 | ;; input. The terminating newline is put into a special | 1455 | mouse-face highlight |
| 1459 | ;; `boundary' field to make cursor movement between input | 1456 | help-echo "mouse-2: insert after prompt as new input")) |
| 1460 | ;; and output fields smoother. | 1457 | (unless comint-use-prompt-regexp-instead-of-fields |
| 1461 | (overlay-put over 'field 'input)) | 1458 | ;; Give old user input a field property of `input', to |
| 1462 | (overlay-put over 'font-lock-face 'comint-highlight-input) | 1459 | ;; distinguish it from both process output and unsent |
| 1463 | (overlay-put over 'mouse-face 'highlight) | 1460 | ;; input. The terminating newline is put into a special |
| 1464 | (overlay-put over | 1461 | ;; `boundary' field to make cursor movement between input |
| 1465 | 'help-echo | 1462 | ;; and output fields smoother. |
| 1466 | "mouse-2: insert after prompt as new input") | 1463 | (put-text-property beg end 'field 'input))) |
| 1467 | (overlay-put over 'evaporate t))) | ||
| 1468 | (unless comint-use-prompt-regexp-instead-of-fields | 1464 | (unless comint-use-prompt-regexp-instead-of-fields |
| 1469 | ;; Make an overlay for the terminating newline | 1465 | ;; Cover the terminating newline |
| 1470 | (let ((over (make-overlay end (1+ end) nil t nil))) | 1466 | (add-text-properties end (1+ end) |
| 1471 | (overlay-put over 'field 'boundary) | 1467 | '(rear-nonsticky t |
| 1472 | (overlay-put over 'inhibit-line-move-field-capture t) | 1468 | field boundary |
| 1473 | (overlay-put over 'evaporate t)))) | 1469 | inhibit-line-move-field-capture t)))) |
| 1474 | 1470 | ||
| 1475 | (comint-snapshot-last-prompt) | 1471 | (comint-snapshot-last-prompt) |
| 1476 | 1472 | ||
| @@ -1532,21 +1528,18 @@ redirection buffer. | |||
| 1532 | You can use `add-hook' to add functions to this list | 1528 | You can use `add-hook' to add functions to this list |
| 1533 | either globally or locally.") | 1529 | either globally or locally.") |
| 1534 | 1530 | ||
| 1535 | ;; When non-nil, this is the last overlay used for output. | ||
| 1536 | ;; It is kept around so that we can extend it instead of creating | ||
| 1537 | ;; multiple contiguous overlays for multiple contiguous output chunks. | ||
| 1538 | (defvar comint-last-output-overlay nil) | ||
| 1539 | |||
| 1540 | ;; When non-nil, this is an overlay over the last recognized prompt in | 1531 | ;; When non-nil, this is an overlay over the last recognized prompt in |
| 1541 | ;; the buffer; it is used when highlighting the prompt. | 1532 | ;; the buffer; it is used when highlighting the prompt. |
| 1542 | (defvar comint-last-prompt-overlay nil) | 1533 | (defvar comint-last-prompt-overlay nil) |
| 1543 | 1534 | ||
| 1544 | ;; `snapshot' any current comint-last-prompt-overlay, freezing it in place. | 1535 | ;; `snapshot' any current comint-last-prompt-overlay, freezing its |
| 1545 | ;; Any further output will then create a new comint-last-prompt-overlay. | 1536 | ;; attributes in place, even when more input comes a long and moves the |
| 1537 | ;; prompt overlay. | ||
| 1546 | (defun comint-snapshot-last-prompt () | 1538 | (defun comint-snapshot-last-prompt () |
| 1547 | (when comint-last-prompt-overlay | 1539 | (when comint-last-prompt-overlay |
| 1548 | (overlay-put comint-last-prompt-overlay 'evaporate t) | 1540 | (add-text-properties (overlay-start comint-last-prompt-overlay) |
| 1549 | (setq comint-last-prompt-overlay nil))) | 1541 | (overlay-end comint-last-prompt-overlay) |
| 1542 | (overlay-properties comint-last-prompt-overlay)))) | ||
| 1550 | 1543 | ||
| 1551 | (defun comint-carriage-motion (string) | 1544 | (defun comint-carriage-motion (string) |
| 1552 | "Handle carriage control characters in comint output. | 1545 | "Handle carriage control characters in comint output. |
| @@ -1670,22 +1663,10 @@ This function should be in the list `comint-output-filter-functions'." | |||
| 1670 | (set-marker (process-mark process) (point)) | 1663 | (set-marker (process-mark process) (point)) |
| 1671 | 1664 | ||
| 1672 | (unless comint-use-prompt-regexp-instead-of-fields | 1665 | (unless comint-use-prompt-regexp-instead-of-fields |
| 1673 | ;; We check to see if the last overlay used for output is | 1666 | (add-text-properties comint-last-output-start (point) |
| 1674 | ;; adjacent to the new input, and if so, just extend it. | 1667 | '(rear-nonsticky t |
| 1675 | (if (and comint-last-output-overlay | 1668 | field output |
| 1676 | (equal (overlay-end comint-last-output-overlay) | 1669 | inhibit-line-move-field-capture t))) |
| 1677 | (marker-position comint-last-output-start))) | ||
| 1678 | ;; Extend comint-last-output-overlay to include the | ||
| 1679 | ;; most recent output | ||
| 1680 | (move-overlay comint-last-output-overlay | ||
| 1681 | (overlay-start comint-last-output-overlay) | ||
| 1682 | (point)) | ||
| 1683 | ;; Create a new overlay | ||
| 1684 | (let ((over (make-overlay comint-last-output-start (point)))) | ||
| 1685 | (overlay-put over 'field 'output) | ||
| 1686 | (overlay-put over 'inhibit-line-move-field-capture t) | ||
| 1687 | (overlay-put over 'evaporate t) | ||
| 1688 | (setq comint-last-output-overlay over)))) | ||
| 1689 | 1670 | ||
| 1690 | ;; Highlight the prompt, where we define `prompt' to mean | 1671 | ;; Highlight the prompt, where we define `prompt' to mean |
| 1691 | ;; the most recent output that doesn't end with a newline. | 1672 | ;; the most recent output that doesn't end with a newline. |
| @@ -1816,7 +1797,7 @@ the current line with any initial string matching the regexp | |||
| 1816 | (if (eq (get-char-property bof 'field) 'input) | 1797 | (if (eq (get-char-property bof 'field) 'input) |
| 1817 | (field-string bof) | 1798 | (field-string bof) |
| 1818 | (comint-bol) | 1799 | (comint-bol) |
| 1819 | (buffer-substring (point) (line-end-position))))) | 1800 | (buffer-substring-no-properties (point) (line-end-position))))) |
| 1820 | 1801 | ||
| 1821 | (defun comint-copy-old-input () | 1802 | (defun comint-copy-old-input () |
| 1822 | "Insert after prompt old input at point as new input to be edited. | 1803 | "Insert after prompt old input at point as new input to be edited. |
| @@ -2404,7 +2385,7 @@ This command is like `M-.' in bash." | |||
| 2404 | (and (search-forward "\"" eol t) | 2385 | (and (search-forward "\"" eol t) |
| 2405 | (1- (point)))))) | 2386 | (1- (point)))))) |
| 2406 | (and start end | 2387 | (and start end |
| 2407 | (buffer-substring start end))))) | 2388 | (buffer-substring-no-properties start end))))) |
| 2408 | 2389 | ||
| 2409 | (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p) | 2390 | (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p) |
| 2410 | (let* ((def (comint-source-default prev-dir/file source-modes)) | 2391 | (let* ((def (comint-source-default prev-dir/file source-modes)) |