comparison lisp/term.el @ 57163:22cfa0559b07

(term-emulate-terminal): Turn off undo for output. Use with-current-buffer and save-selected-window.
author Richard M. Stallman <rms@gnu.org>
date Mon, 20 Sep 2004 15:59:31 +0000
parents 338c77460ae7
children d838e748405a 0796fc36c2bd
comparison
equal deleted inserted replaced
57162:a9bbdf07a7d6 57163:22cfa0559b07
2633 ;;; Terminal emulation 2633 ;;; Terminal emulation
2634 ;;; This is the standard process filter for term buffers. 2634 ;;; This is the standard process filter for term buffers.
2635 ;;; It emulates (most of the features of) a VT100/ANSI-style terminal. 2635 ;;; It emulates (most of the features of) a VT100/ANSI-style terminal.
2636 2636
2637 (defun term-emulate-terminal (proc str) 2637 (defun term-emulate-terminal (proc str)
2638 (let* ((previous-buffer (current-buffer)) 2638 (with-current-buffer (process-buffer proc)
2639 (i 0) char funny count save-point save-marker old-point temp win 2639 (let* ((i 0) char funny count save-point save-marker old-point temp win
2640 (selected (selected-window)) 2640 (buffer-undo-list t)
2641 last-win 2641 (selected (selected-window))
2642 (str-length (length str))) 2642 last-win
2643 (unwind-protect 2643 (str-length (length str)))
2644 (progn 2644 (save-selected-window
2645 (set-buffer (process-buffer proc)) 2645
2646 2646 ;; Let's handle the messages. -mm
2647 ;;; Let's handle the messages. -mm 2647
2648 2648 (setq str (term-handle-ansi-terminal-messages str))
2649 (setq str (term-handle-ansi-terminal-messages str)) 2649 (setq str-length (length str))
2650 (setq str-length (length str)) 2650
2651 2651 (if (marker-buffer term-pending-delete-marker)
2652 (if (marker-buffer term-pending-delete-marker) 2652 (progn
2653 (progn 2653 ;; Delete text following term-pending-delete-marker.
2654 ;; Delete text following term-pending-delete-marker. 2654 (delete-region term-pending-delete-marker (process-mark proc))
2655 (delete-region term-pending-delete-marker (process-mark proc)) 2655 (set-marker term-pending-delete-marker nil)))
2656 (set-marker term-pending-delete-marker nil))) 2656
2657 2657 (if (eq (window-buffer) (current-buffer))
2658 (if (eq (window-buffer) (current-buffer)) 2658 (progn
2659 (progn 2659 (setq term-vertical-motion (symbol-function 'vertical-motion))
2660 (setq term-vertical-motion (symbol-function 'vertical-motion)) 2660 (term-check-size proc))
2661 (term-check-size proc)) 2661 (setq term-vertical-motion
2662 (setq term-vertical-motion 2662 (symbol-function 'buffer-vertical-motion)))
2663 (symbol-function 'buffer-vertical-motion))) 2663
2664 2664 (setq save-marker (copy-marker (process-mark proc)))
2665 (setq save-marker (copy-marker (process-mark proc))) 2665
2666 2666 (if (/= (point) (process-mark proc))
2667 (if (/= (point) (process-mark proc)) 2667 (progn (setq save-point (point-marker))
2668 (progn (setq save-point (point-marker)) 2668 (goto-char (process-mark proc))))
2669 (goto-char (process-mark proc)))) 2669
2670 2670 (save-restriction
2671 (save-restriction 2671 ;; If the buffer is in line mode, and there is a partial
2672 ;; If the buffer is in line mode, and there is a partial 2672 ;; input line, save the line (by narrowing to leave it
2673 ;; input line, save the line (by narrowing to leave it 2673 ;; outside the restriction ) until we're done with output.
2674 ;; outside the restriction ) until we're done with output. 2674 (if (and (> (point-max) (process-mark proc))
2675 (if (and (> (point-max) (process-mark proc)) 2675 (term-in-line-mode))
2676 (term-in-line-mode)) 2676 (narrow-to-region (point-min) (process-mark proc)))
2677 (narrow-to-region (point-min) (process-mark proc))) 2677
2678 2678 (if term-log-buffer
2679 (if term-log-buffer 2679 (princ str term-log-buffer))
2680 (princ str term-log-buffer)) 2680 (cond ((eq term-terminal-state 4) ;; Have saved pending output.
2681 (cond ((eq term-terminal-state 4) ;; Have saved pending output. 2681 (setq str (concat term-terminal-parameter str))
2682 (setq str (concat term-terminal-parameter str)) 2682 (setq term-terminal-parameter nil)
2683 (setq term-terminal-parameter nil) 2683 (setq str-length (length str))
2684 (setq str-length (length str)) 2684 (setq term-terminal-state 0)))
2685 (setq term-terminal-state 0))) 2685
2686 2686 (while (< i str-length)
2687 (while (< i str-length) 2687 (setq char (aref str i))
2688 (setq char (aref str i)) 2688 (cond ((< term-terminal-state 2)
2689 (cond ((< term-terminal-state 2) 2689 ;; Look for prefix of regular chars
2690 ;; Look for prefix of regular chars 2690 (setq funny
2691 (setq funny 2691 (string-match "[\r\n\000\007\033\t\b\032\016\017]"
2692 (string-match "[\r\n\000\007\033\t\b\032\016\017]" 2692 str i))
2693 str i)) 2693 (if (not funny) (setq funny str-length))
2694 (if (not funny) (setq funny str-length)) 2694 (cond ((> funny i)
2695 (cond ((> funny i) 2695 (cond ((eq term-terminal-state 1)
2696 (cond ((eq term-terminal-state 1) 2696 (term-move-columns 1)
2697 (term-move-columns 1) 2697 (setq term-terminal-state 0)))
2698 (setq term-terminal-state 0))) 2698 (setq count (- funny i))
2699 (setq count (- funny i)) 2699 (setq temp (- (+ (term-horizontal-column) count)
2700 (setq temp (- (+ (term-horizontal-column) count) 2700 term-width))
2701 term-width)) 2701 (cond ((<= temp 0)) ;; All count chars fit in line.
2702 (cond ((<= temp 0)) ;; All count chars fit in line. 2702 ((> count temp) ;; Some chars fit.
2703 ((> count temp) ;; Some chars fit. 2703 ;; This iteration, handle only what fits.
2704 ;; This iteration, handle only what fits. 2704 (setq count (- count temp))
2705 (setq count (- count temp)) 2705 (setq funny (+ count i)))
2706 (setq funny (+ count i))) 2706 ((or (not (or term-pager-count
2707 ((or (not (or term-pager-count 2707 term-scroll-with-delete))
2708 term-scroll-with-delete)) 2708 (> (term-handle-scroll 1) 0))
2709 (> (term-handle-scroll 1) 0)) 2709 (term-adjust-current-row-cache 1)
2710 (term-adjust-current-row-cache 1) 2710 (setq count (min count term-width))
2711 (setq count (min count term-width)) 2711 (setq funny (+ count i))
2712 (setq funny (+ count i)) 2712 (setq term-start-line-column
2713 (setq term-start-line-column 2713 term-current-column))
2714 term-current-column)) 2714 (t ;; Doing PAGER processing.
2715 (t ;; Doing PAGER processing. 2715 (setq count 0 funny i)
2716 (setq count 0 funny i) 2716 (setq term-current-column nil)
2717 (setq term-current-column nil) 2717 (setq term-start-line-column nil)))
2718 (setq term-start-line-column nil))) 2718 (setq old-point (point))
2719 (setq old-point (point)) 2719
2720 2720 ;; Insert a string, check how many columns
2721 ;; Insert a string, check how many columns 2721 ;; we moved, then delete that many columns
2722 ;; we moved, then delete that many columns 2722 ;; following point if not eob nor insert-mode.
2723 ;; following point if not eob nor insert-mode. 2723 (let ((old-column (current-column))
2724 (let ((old-column (current-column)) 2724 columns pos)
2725 columns pos) 2725 (insert (substring str i funny))
2726 (insert (substring str i funny)) 2726 (setq term-current-column (current-column)
2727 (setq term-current-column (current-column) 2727 columns (- term-current-column old-column))
2728 columns (- term-current-column old-column)) 2728 (when (not (or (eobp) term-insert-mode))
2729 (when (not (or (eobp) term-insert-mode)) 2729 (setq pos (point))
2730 (setq pos (point)) 2730 (term-move-columns columns)
2731 (term-move-columns columns) 2731 (delete-region pos (point))))
2732 (delete-region pos (point)))) 2732 (setq term-current-column nil)
2733 (setq term-current-column nil) 2733
2734 2734 (put-text-property old-point (point)
2735 (put-text-property old-point (point) 2735 'face term-current-face)
2736 'face term-current-face) 2736 ;; If the last char was written in last column,
2737 ;; If the last char was written in last column, 2737 ;; back up one column, but remember we did so.
2738 ;; back up one column, but remember we did so. 2738 ;; Thus we emulate xterm/vt100-style line-wrapping.
2739 ;; Thus we emulate xterm/vt100-style line-wrapping. 2739 (cond ((eq temp 0)
2740 (cond ((eq temp 0) 2740 (term-move-columns -1)
2741 (term-move-columns -1) 2741 (setq term-terminal-state 1)))
2742 (setq term-terminal-state 1))) 2742 (setq i (1- funny)))
2743 (setq i (1- funny))) 2743 ((and (setq term-terminal-state 0)
2744 ((and (setq term-terminal-state 0) 2744 (eq char ?\^I)) ; TAB
2745 (eq char ?\^I)) ; TAB 2745 ;; FIXME: Does not handle line wrap!
2746 ;; FIXME: Does not handle line wrap! 2746 (setq count (term-current-column))
2747 (setq count (term-current-column)) 2747 (setq count (+ count 8 (- (mod count 8))))
2748 (setq count (+ count 8 (- (mod count 8)))) 2748 (if (< (move-to-column count nil) count)
2749 (if (< (move-to-column count nil) count) 2749 (term-insert-char char 1))
2750 (term-insert-char char 1)) 2750 (setq term-current-column count))
2751 (setq term-current-column count)) 2751 ((eq char ?\r)
2752 ((eq char ?\r) 2752 ;; Optimize CRLF at end of buffer:
2753 ;; Optimize CRLF at end of buffer: 2753 (cond ((and (< (setq temp (1+ i)) str-length)
2754 (cond ((and (< (setq temp (1+ i)) str-length) 2754 (eq (aref str temp) ?\n)
2755 (eq (aref str temp) ?\n) 2755 (= (point) (point-max))
2756 (= (point) (point-max)) 2756 (not (or term-pager-count
2757 (not (or term-pager-count 2757 term-kill-echo-list
2758 term-kill-echo-list 2758 term-scroll-with-delete)))
2759 term-scroll-with-delete))) 2759 (insert ?\n)
2760 (insert ?\n) 2760 (term-adjust-current-row-cache 1)
2761 (term-adjust-current-row-cache 1) 2761 (setq term-start-line-column 0)
2762 (setq term-start-line-column 0) 2762 (setq term-current-column 0)
2763 (setq term-current-column 0) 2763 (setq i temp))
2764 (setq i temp)) 2764 (t ;; Not followed by LF or can't optimize:
2765 (t ;; Not followed by LF or can't optimize: 2765 (term-vertical-motion 0)
2766 (term-vertical-motion 0) 2766 (setq term-current-column term-start-line-column))))
2767 (setq term-current-column term-start-line-column)))) 2767 ((eq char ?\n)
2768 ((eq char ?\n) 2768 (if (not (and term-kill-echo-list
2769 (if (not (and term-kill-echo-list 2769 (term-check-kill-echo-list)))
2770 (term-check-kill-echo-list))) 2770 (term-down 1 t)))
2771 (term-down 1 t))) 2771 ((eq char ?\b)
2772 ((eq char ?\b) 2772 (term-move-columns -1))
2773 (term-move-columns -1)) 2773 ((eq char ?\033) ; Escape
2774 ((eq char ?\033) ; Escape 2774 (setq term-terminal-state 2))
2775 (setq term-terminal-state 2)) 2775 ((eq char 0)) ; NUL: Do nothing
2776 ((eq char 0)) ; NUL: Do nothing 2776 ((eq char ?\016)) ; Shift Out - ignored
2777 ((eq char ?\016)) ; Shift Out - ignored 2777 ((eq char ?\017)) ; Shift In - ignored
2778 ((eq char ?\017)) ; Shift In - ignored 2778 ((eq char ?\^G)
2779 ((eq char ?\^G) 2779 (beep t)) ; Bell
2780 (beep t)) ; Bell 2780 ((eq char ?\032)
2781 ((eq char ?\032) 2781 (let ((end (string-match "\r?$" str i)))
2782 (let ((end (string-match "\r?$" str i))) 2782 (if end
2783 (if end 2783 (funcall term-command-hook
2784 (funcall term-command-hook 2784 (prog1 (substring str (1+ i) end)
2785 (prog1 (substring str (1+ i) end) 2785 (setq i (match-end 0))))
2786 (setq i (match-end 0)))) 2786 (setq term-terminal-parameter
2787 (setq term-terminal-parameter 2787 (substring str i))
2788 (substring str i)) 2788 (setq term-terminal-state 4)
2789 (setq term-terminal-state 4) 2789 (setq i str-length))))
2790 (setq i str-length)))) 2790 (t ; insert char FIXME: Should never happen
2791 (t ; insert char FIXME: Should never happen 2791 (term-move-columns 1)
2792 (term-move-columns 1) 2792 (backward-delete-char 1)
2793 (backward-delete-char 1) 2793 (insert char))))
2794 (insert char)))) 2794 ((eq term-terminal-state 2) ; Seen Esc
2795 ((eq term-terminal-state 2) ; Seen Esc 2795 (cond ((eq char ?\133) ;; ?\133 = ?[
2796 (cond ((eq char ?\133) ;; ?\133 = ?[
2797 2796
2798 ;;; Some modifications to cope with multiple settings like ^[[01;32;43m -mm 2797 ;;; Some modifications to cope with multiple settings like ^[[01;32;43m -mm
2799 ;;; Note that now the init value of term-terminal-previous-parameter has 2798 ;;; Note that now the init value of term-terminal-previous-parameter has
2800 ;;; been changed to -1 2799 ;;; been changed to -1
2801 2800
2802 (make-local-variable 'term-terminal-parameter) 2801 (make-local-variable 'term-terminal-parameter)
2803 (make-local-variable 'term-terminal-previous-parameter) 2802 (make-local-variable 'term-terminal-previous-parameter)
2804 (make-local-variable 'term-terminal-previous-parameter-2) 2803 (make-local-variable 'term-terminal-previous-parameter-2)
2805 (make-local-variable 'term-terminal-previous-parameter-3) 2804 (make-local-variable 'term-terminal-previous-parameter-3)
2806 (make-local-variable 'term-terminal-previous-parameter-4) 2805 (make-local-variable 'term-terminal-previous-parameter-4)
2807 (make-local-variable 'term-terminal-more-parameters) 2806 (make-local-variable 'term-terminal-more-parameters)
2808 (setq term-terminal-parameter 0) 2807 (setq term-terminal-parameter 0)
2809 (setq term-terminal-previous-parameter -1) 2808 (setq term-terminal-previous-parameter -1)
2810 (setq term-terminal-previous-parameter-2 -1) 2809 (setq term-terminal-previous-parameter-2 -1)
2811 (setq term-terminal-previous-parameter-3 -1) 2810 (setq term-terminal-previous-parameter-3 -1)
2812 (setq term-terminal-previous-parameter-4 -1) 2811 (setq term-terminal-previous-parameter-4 -1)
2813 (setq term-terminal-more-parameters 0) 2812 (setq term-terminal-more-parameters 0)
2814 (setq term-terminal-state 3)) 2813 (setq term-terminal-state 3))
2815 ((eq char ?D) ;; scroll forward 2814 ((eq char ?D) ;; scroll forward
2816 (term-handle-deferred-scroll) 2815 (term-handle-deferred-scroll)
2817 (term-down 1 t) 2816 (term-down 1 t)
2818 (setq term-terminal-state 0)) 2817 (setq term-terminal-state 0))
2819 ((eq char ?M) ;; scroll reversed 2818 ((eq char ?M) ;; scroll reversed
2820 (term-insert-lines 1) 2819 (term-insert-lines 1)
2821 (setq term-terminal-state 0)) 2820 (setq term-terminal-state 0))
2822 ((eq char ?7) ;; Save cursor 2821 ((eq char ?7) ;; Save cursor
2823 (term-handle-deferred-scroll) 2822 (term-handle-deferred-scroll)
2824 (setq term-saved-cursor 2823 (setq term-saved-cursor
2825 (cons (term-current-row) 2824 (cons (term-current-row)
2826 (term-horizontal-column))) 2825 (term-horizontal-column)))
2827 (setq term-terminal-state 0)) 2826 (setq term-terminal-state 0))
2828 ((eq char ?8) ;; Restore cursor 2827 ((eq char ?8) ;; Restore cursor
2829 (if term-saved-cursor 2828 (if term-saved-cursor
2830 (term-goto (car term-saved-cursor) 2829 (term-goto (car term-saved-cursor)
2831 (cdr term-saved-cursor))) 2830 (cdr term-saved-cursor)))
2832 (setq term-terminal-state 0)) 2831 (setq term-terminal-state 0))
2833 ((setq term-terminal-state 0)))) 2832 ((setq term-terminal-state 0))))
2834 ((eq term-terminal-state 3) ; Seen Esc [ 2833 ((eq term-terminal-state 3) ; Seen Esc [
2835 (cond ((and (>= char ?0) (<= char ?9)) 2834 (cond ((and (>= char ?0) (<= char ?9))
2836 (setq term-terminal-parameter 2835 (setq term-terminal-parameter
2837 (+ (* 10 term-terminal-parameter) (- char ?0)))) 2836 (+ (* 10 term-terminal-parameter) (- char ?0))))
2838 ((eq char ?\;) 2837 ((eq char ?\;)
2839 ;;; Some modifications to cope with multiple settings like ^[[01;32;43m -mm 2838 ;;; Some modifications to cope with multiple settings like ^[[01;32;43m -mm
2840 (setq term-terminal-more-parameters 1) 2839 (setq term-terminal-more-parameters 1)
2841 (setq term-terminal-previous-parameter-4 2840 (setq term-terminal-previous-parameter-4
2842 term-terminal-previous-parameter-3) 2841 term-terminal-previous-parameter-3)
2843 (setq term-terminal-previous-parameter-3 2842 (setq term-terminal-previous-parameter-3
2844 term-terminal-previous-parameter-2) 2843 term-terminal-previous-parameter-2)
2845 (setq term-terminal-previous-parameter-2 2844 (setq term-terminal-previous-parameter-2
2846 term-terminal-previous-parameter) 2845 term-terminal-previous-parameter)
2847 (setq term-terminal-previous-parameter 2846 (setq term-terminal-previous-parameter
2848 term-terminal-parameter) 2847 term-terminal-parameter)
2849 (setq term-terminal-parameter 0)) 2848 (setq term-terminal-parameter 0))
2850 ((eq char ??)) ; Ignore ? 2849 ((eq char ??)) ; Ignore ?
2851 (t 2850 (t
2852 (term-handle-ansi-escape proc char) 2851 (term-handle-ansi-escape proc char)
2853 (setq term-terminal-more-parameters 0) 2852 (setq term-terminal-more-parameters 0)
2854 (setq term-terminal-previous-parameter-4 -1) 2853 (setq term-terminal-previous-parameter-4 -1)
2855 (setq term-terminal-previous-parameter-3 -1) 2854 (setq term-terminal-previous-parameter-3 -1)
2856 (setq term-terminal-previous-parameter-2 -1) 2855 (setq term-terminal-previous-parameter-2 -1)
2857 (setq term-terminal-previous-parameter -1) 2856 (setq term-terminal-previous-parameter -1)
2858 (setq term-terminal-state 0))))) 2857 (setq term-terminal-state 0)))))
2859 (if (term-handling-pager) 2858 (if (term-handling-pager)
2860 ;; Finish stuff to get ready to handle PAGER. 2859 ;; Finish stuff to get ready to handle PAGER.
2861 (progn 2860 (progn
2862 (if (> (% (current-column) term-width) 0) 2861 (if (> (% (current-column) term-width) 0)
2862 (setq term-terminal-parameter
2863 (substring str i))
2864 ;; We're at column 0. Goto end of buffer; to compensate,
2865 ;; prepend a ?\r for later. This looks more consistent.
2866 (if (zerop i)
2863 (setq term-terminal-parameter 2867 (setq term-terminal-parameter
2864 (substring str i)) 2868 (concat "\r" (substring str i)))
2865 ;; We're at column 0. Goto end of buffer; to compensate, 2869 (setq term-terminal-parameter (substring str (1- i)))
2866 ;; prepend a ?\r for later. This looks more consistent. 2870 (aset term-terminal-parameter 0 ?\r))
2867 (if (zerop i) 2871 (goto-char (point-max)))
2868 (setq term-terminal-parameter 2872 (setq term-terminal-state 4)
2869 (concat "\r" (substring str i))) 2873 (make-local-variable 'term-pager-old-filter)
2870 (setq term-terminal-parameter (substring str (1- i))) 2874 (setq term-pager-old-filter (process-filter proc))
2871 (aset term-terminal-parameter 0 ?\r)) 2875 (set-process-filter proc term-pager-filter)
2872 (goto-char (point-max))) 2876 (setq i str-length)))
2873 (setq term-terminal-state 4) 2877 (setq i (1+ i))))
2874 (make-local-variable 'term-pager-old-filter) 2878
2875 (setq term-pager-old-filter (process-filter proc)) 2879 (if (>= (term-current-row) term-height)
2876 (set-process-filter proc term-pager-filter) 2880 (term-handle-deferred-scroll))
2877 (setq i str-length))) 2881
2878 (setq i (1+ i)))) 2882 (set-marker (process-mark proc) (point))
2879 2883 (if save-point
2880 (if (>= (term-current-row) term-height) 2884 (progn (goto-char save-point)
2881 (term-handle-deferred-scroll)) 2885 (set-marker save-point nil)))
2882 2886
2883 (set-marker (process-mark proc) (point)) 2887 ;; Check for a pending filename-and-line number to display.
2884 (if save-point 2888 ;; We do this before scrolling, because we might create a new window.
2885 (progn (goto-char save-point) 2889 (if (and term-pending-frame
2886 (set-marker save-point nil))) 2890 (eq (window-buffer selected) (current-buffer)))
2887 2891 (progn (term-display-line (car term-pending-frame)
2888 ;; Check for a pending filename-and-line number to display. 2892 (cdr term-pending-frame))
2889 ;; We do this before scrolling, because we might create a new window. 2893 (setq term-pending-frame nil)
2890 (if (and term-pending-frame 2894 ;; We have created a new window, so check the window size.
2891 (eq (window-buffer selected) (current-buffer))) 2895 (term-check-size proc)))
2892 (progn (term-display-line (car term-pending-frame) 2896
2893 (cdr term-pending-frame)) 2897 ;; Scroll each window displaying the buffer but (by default)
2894 (setq term-pending-frame nil) 2898 ;; only if the point matches the process-mark we started with.
2895 ;; We have created a new window, so check the window size. 2899 (setq win selected)
2896 (term-check-size proc))) 2900 ;; Avoid infinite loop in strange case where minibuffer window
2897 2901 ;; is selected but not active.
2898 ;; Scroll each window displaying the buffer but (by default) 2902 (while (window-minibuffer-p win)
2899 ;; only if the point matches the process-mark we started with. 2903 (setq win (next-window win nil t)))
2900 (setq win selected) 2904 (setq last-win win)
2901 ;; Avoid infinite loop in strange case where minibuffer window 2905 (while (progn
2902 ;; is selected but not active. 2906 (setq win (next-window win nil t))
2903 (while (window-minibuffer-p win) 2907 (if (eq (window-buffer win) (process-buffer proc))
2904 (setq win (next-window win nil t))) 2908 (let ((scroll term-scroll-to-bottom-on-output))
2905 (setq last-win win) 2909 (select-window win)
2906 (while (progn 2910 (if (or (= (point) save-marker)
2907 (setq win (next-window win nil t)) 2911 (eq scroll t) (eq scroll 'all)
2908 (if (eq (window-buffer win) (process-buffer proc)) 2912 ;; Maybe user wants point to jump to the end.
2909 (let ((scroll term-scroll-to-bottom-on-output)) 2913 (and (eq selected win)
2910 (select-window win) 2914 (or (eq scroll 'this) (not save-point)))
2911 (if (or (= (point) save-marker) 2915 (and (eq scroll 'others)
2912 (eq scroll t) (eq scroll 'all) 2916 (not (eq selected win))))
2913 ;; Maybe user wants point to jump to the end. 2917 (progn
2914 (and (eq selected win) 2918 (goto-char term-home-marker)
2915 (or (eq scroll 'this) (not save-point))) 2919 (recenter 0)
2916 (and (eq scroll 'others) 2920 (goto-char (process-mark proc))
2917 (not (eq selected win)))) 2921 (if (not (pos-visible-in-window-p (point) win))
2918 (progn 2922 (recenter -1))))
2919 (goto-char term-home-marker) 2923 ;; Optionally scroll so that the text
2920 (recenter 0) 2924 ;; ends at the bottom of the window.
2921 (goto-char (process-mark proc)) 2925 (if (and term-scroll-show-maximum-output
2922 (if (not (pos-visible-in-window-p (point) win)) 2926 (>= (point) (process-mark proc)))
2923 (recenter -1)))) 2927 (save-excursion
2924 ;; Optionally scroll so that the text 2928 (goto-char (point-max))
2925 ;; ends at the bottom of the window. 2929 (recenter -1)))))
2926 (if (and term-scroll-show-maximum-output 2930 (not (eq win last-win))))
2927 (>= (point) (process-mark proc)))
2928 (save-excursion
2929 (goto-char (point-max))
2930 (recenter -1)))))
2931 (not (eq win last-win))))
2932 2931
2933 ;;; Stolen from comint.el and adapted -mm 2932 ;;; Stolen from comint.el and adapted -mm
2934 (if (> term-buffer-maximum-size 0) 2933 (if (> term-buffer-maximum-size 0)
2935 (save-excursion 2934 (save-excursion
2936 (goto-char (process-mark (get-buffer-process (current-buffer)))) 2935 (goto-char (process-mark (get-buffer-process (current-buffer))))
2937 (forward-line (- term-buffer-maximum-size)) 2936 (forward-line (- term-buffer-maximum-size))
2938 (beginning-of-line) 2937 (beginning-of-line)
2939 (delete-region (point-min) (point)))) 2938 (delete-region (point-min) (point))))
2940 ;;; 2939 ;;;
2941 2940
2942 (set-marker save-marker nil)) 2941 (set-marker save-marker nil)))))
2943 ;; unwind-protect cleanup-forms follow:
2944 (set-buffer previous-buffer)
2945 (select-window selected))))
2946 2942
2947 (defun term-handle-deferred-scroll () 2943 (defun term-handle-deferred-scroll ()
2948 (let ((count (- (term-current-row) term-height))) 2944 (let ((count (- (term-current-row) term-height)))
2949 (if (>= count 0) 2945 (if (>= count 0)
2950 (save-excursion 2946 (save-excursion