comparison lisp/comint.el @ 30731:4ce2b3d23348

(comint-highlight-prompt, comint-highlight-prompt-face) (comint-last-prompt-overlay): New variables. (comint-output-filter): Implement prompt highlighting. (comint-snapshot-last-prompt): New function. (comint-send-input): Snapshot the last prompt. Use comint-highlight-input-face. (comint-highlight-input-face): Renamed from `comint-highlight-face'. Use defface instead of defcustom. (send-invisible, comint-send-eof): Snapshot the last prompt. (comint-delchar-or-maybe-eof): Use comint-send-eof. (comint-mode): Make `comint-last-prompt-overlay' buffer-local.
author Miles Bader <miles@gnu.org>
date Thu, 10 Aug 2000 10:34:14 +0000
parents 766ccccf5c4f
children 7960e7b84348
comparison
equal deleted inserted replaced
30730:460a4e222f17 30731:4ce2b3d23348
209 "*If non-nil, highlight input; also allow choosing previous input with a mouse. 209 "*If non-nil, highlight input; also allow choosing previous input with a mouse.
210 See also `comint-highlight-face'." 210 See also `comint-highlight-face'."
211 :type 'boolean 211 :type 'boolean
212 :group 'comint) 212 :group 'comint)
213 213
214 (defcustom comint-highlight-face 'bold 214 (defface comint-highlight-input-face '((t (:bold t)))
215 "*Face to use to highlight input when `comint-highlight-input' is non-nil." 215 "Face to use to highlight input when `comint-highlight-input' is non-nil."
216 :type 'face 216 :group 'comint)
217
218 (defcustom comint-highlight-prompt t
219 "*If non-nil, highlight program prompts.
220 See also `comint-highlight-face'."
221 :type 'boolean
222 :group 'comint)
223
224 (defface comint-highlight-prompt-face
225 '((((background dark)) (:foreground "cyan"))
226 (t (:foreground "dark blue")))
227 "Face to use to highlight prompt when `comint-highlight-prompt' is non-nil."
217 :group 'comint) 228 :group 'comint)
218 229
219 (defcustom comint-input-ignoredups nil 230 (defcustom comint-input-ignoredups nil
220 "*If non-nil, don't add input matching the last on the input ring. 231 "*If non-nil, don't add input matching the last on the input ring.
221 This mirrors the optional behavior of bash. 232 This mirrors the optional behavior of bash.
478 (setq comint-last-input-end (make-marker)) 489 (setq comint-last-input-end (make-marker))
479 (set-marker comint-last-input-end (point-min)) 490 (set-marker comint-last-input-end (point-min))
480 (make-local-variable 'comint-last-output-start) 491 (make-local-variable 'comint-last-output-start)
481 (setq comint-last-output-start (make-marker)) 492 (setq comint-last-output-start (make-marker))
482 (make-local-variable 'comint-last-output-overlay) 493 (make-local-variable 'comint-last-output-overlay)
494 (make-local-variable 'comint-last-prompt-overlay)
483 (make-local-variable 'comint-prompt-regexp) ; Don't set; default 495 (make-local-variable 'comint-prompt-regexp) ; Don't set; default
484 (make-local-variable 'comint-input-ring-size) ; ...to global val. 496 (make-local-variable 'comint-input-ring-size) ; ...to global val.
485 (make-local-variable 'comint-input-ring) 497 (make-local-variable 'comint-input-ring)
486 (make-local-variable 'comint-input-ring-file-name) 498 (make-local-variable 'comint-input-ring-file-name)
487 (or (and (boundp 'comint-input-ring) comint-input-ring) 499 (or (and (boundp 'comint-input-ring) comint-input-ring)
1409 ;; `boundary' field to make cursor movement between input 1421 ;; `boundary' field to make cursor movement between input
1410 ;; and output fields smoother. 1422 ;; and output fields smoother.
1411 (overlay-put over 'field 'input) 1423 (overlay-put over 'field 'input)
1412 (overlay-put over 'front-sticky t)) 1424 (overlay-put over 'front-sticky t))
1413 (when comint-highlight-input 1425 (when comint-highlight-input
1414 (overlay-put over 'face comint-highlight-face) 1426 (overlay-put over 'face 'comint-highlight-input-face)
1415 (overlay-put over 'mouse-face 'highlight) 1427 (overlay-put over 'mouse-face 'highlight)
1416 (overlay-put over 'evaporate t)))) 1428 (overlay-put over 'evaporate t))))
1417 (unless comint-use-prompt-regexp-instead-of-fields 1429 (unless comint-use-prompt-regexp-instead-of-fields
1418 ;; Make an overlay for the terminating newline 1430 ;; Make an overlay for the terminating newline
1419 (let ((over (make-overlay end (1+ end)))) 1431 (let ((over (make-overlay end (1+ end))))
1420 (overlay-put over 'field 'boundary) 1432 (overlay-put over 'field 'boundary)
1421 (overlay-put over 'evaporate t)))) 1433 (overlay-put over 'evaporate t))))
1434
1435 (comint-snapshot-last-prompt)
1422 1436
1423 (setq comint-save-input-ring-index comint-input-ring-index) 1437 (setq comint-save-input-ring-index comint-input-ring-index)
1424 (setq comint-input-ring-index nil) 1438 (setq comint-input-ring-index nil)
1425 ;; Update the markers before we send the input 1439 ;; Update the markers before we send the input
1426 ;; in case we get output amidst sending the input. 1440 ;; in case we get output amidst sending the input.
1450 1464
1451 ;; When non-nil, this is the last overlay used for output. 1465 ;; 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 1466 ;; It is kept around so that we can extend it instead of creating
1453 ;; multiple contiguous overlays for multiple contiguous output chunks. 1467 ;; multiple contiguous overlays for multiple contiguous output chunks.
1454 (defvar comint-last-output-overlay nil) 1468 (defvar comint-last-output-overlay nil)
1469
1470 ;; When non-nil, this is an overlay over the last recognized prompt in
1471 ;; the buffer; it is used when highlighting the prompt.
1472 (defvar comint-last-prompt-overlay nil)
1473
1474 ;; `snapshot' any current comint-last-prompt-overlay, freezing it in place.
1475 ;; Any further output will then create a new comint-last-prompt-overlay.
1476 (defun comint-snapshot-last-prompt ()
1477 (when comint-last-prompt-overlay
1478 (overlay-put comint-last-prompt-overlay 'evaporate t)
1479 (setq comint-last-prompt-overlay nil)))
1455 1480
1456 ;; The purpose of using this filter for comint processes 1481 ;; The purpose of using this filter for comint processes
1457 ;; is to keep comint-last-input-end from moving forward 1482 ;; is to keep comint-last-input-end from moving forward
1458 ;; when output is inserted. 1483 ;; when output is inserted.
1459 (defun comint-output-filter (process string) 1484 (defun comint-output-filter (process string)
1497 (overlay-put over 'field 'output) 1522 (overlay-put over 'field 'output)
1498 (overlay-put over 'rear-nonsticky t) 1523 (overlay-put over 'rear-nonsticky t)
1499 (overlay-put over 'inhibit-line-move-field-capture t) 1524 (overlay-put over 'inhibit-line-move-field-capture t)
1500 (overlay-put over 'evaporate t) 1525 (overlay-put over 'evaporate t)
1501 (setq comint-last-output-overlay over)))) 1526 (setq comint-last-output-overlay over))))
1527
1528 (when comint-highlight-prompt
1529 ;; Highlight the prompt, where we define `prompt' to mean
1530 ;; the most recent output that doesn't end with a newline.
1531 (unless (and (bolp) (null comint-last-prompt-overlay))
1532 ;; Need to create or move the prompt overlay (in the
1533 ;; case where's no prompt ((bolp) == t), we still do
1534 ;; this if there's already an existing overlay.
1535 (let ((prompt-start (save-excursion (forward-line 0) (point))))
1536 (if comint-last-prompt-overlay
1537 ;; Just move an existing overlay
1538 (move-overlay comint-last-prompt-overlay
1539 prompt-start (point))
1540 ;; Need to create the overlay
1541 (setq comint-last-prompt-overlay
1542 (make-overlay prompt-start (point)))
1543 (overlay-put comint-last-prompt-overlay
1544 'rear-nonsticky t)
1545 (overlay-put comint-last-prompt-overlay
1546 'face 'comint-highlight-prompt-face)))))
1502 1547
1503 ;; Don't insert initial prompt outside the top of the window. 1548 ;; Don't insert initial prompt outside the top of the window.
1504 (if (= (window-start (selected-window)) (point)) 1549 (if (= (window-start (selected-window)) (point))
1505 (set-window-start (selected-window) (- (point) (length string)))) 1550 (set-window-start (selected-window) (- (point) (length string))))
1506 (if (and comint-last-input-end 1551 (if (and comint-last-input-end
1761 (interactive "P") ; Defeat snooping via C-x ESC ESC 1806 (interactive "P") ; Defeat snooping via C-x ESC ESC
1762 (let ((proc (get-buffer-process (current-buffer)))) 1807 (let ((proc (get-buffer-process (current-buffer))))
1763 (cond ((not proc) 1808 (cond ((not proc)
1764 (error "Current buffer has no process")) 1809 (error "Current buffer has no process"))
1765 ((stringp str) 1810 ((stringp str)
1811 (comint-snapshot-last-prompt)
1766 (funcall comint-input-sender proc str)) 1812 (funcall comint-input-sender proc str))
1767 (t 1813 (t
1768 (let ((str (comint-read-noecho "Non-echoed text: " t))) 1814 (let ((str (comint-read-noecho "Non-echoed text: " t)))
1769 (if (stringp str) 1815 (if (stringp str)
1770 (send-invisible str) 1816 (send-invisible str)
1875 "Delete ARG characters forward or send an EOF to subprocess. 1921 "Delete ARG characters forward or send an EOF to subprocess.
1876 Sends an EOF only if point is at the end of the buffer and there is no input." 1922 Sends an EOF only if point is at the end of the buffer and there is no input."
1877 (interactive "p") 1923 (interactive "p")
1878 (let ((proc (get-buffer-process (current-buffer)))) 1924 (let ((proc (get-buffer-process (current-buffer))))
1879 (if (and (eobp) proc (= (point) (marker-position (process-mark proc)))) 1925 (if (and (eobp) proc (= (point) (marker-position (process-mark proc))))
1880 (process-send-eof) 1926 (comint-send-eof)
1881 (delete-char arg)))) 1927 (delete-char arg))))
1882 1928
1883 (defun comint-send-eof () 1929 (defun comint-send-eof ()
1884 "Send an EOF to the current buffer's process." 1930 "Send an EOF to the current buffer's process."
1885 (interactive) 1931 (interactive)
1932 (comint-snapshot-last-prompt)
1886 (process-send-eof)) 1933 (process-send-eof))
1887 1934
1888 1935
1889 (defun comint-backward-matching-input (regexp arg) 1936 (defun comint-backward-matching-input (regexp arg)
1890 "Search backward through buffer for input fields that match REGEXP. 1937 "Search backward through buffer for input fields that match REGEXP.