From 81886aeaffe76fd95e299403ef493a76bf606825 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Miha=20Rihtar=C5=A1i=C4=8D?= Date: Sun, 23 Jan 2022 21:13:24 +0100 Subject: [PATCH] Implement alternative sub-buffer support in term.el * etc/e/eterm-color.ti: Added termcaps for entering and leaving an alternative sub-buffer. * lisp/term.el (term-reset-size): Resize correctly in an alternative sub-buffer is in use. (term-clear-full-screen-programs): New user option. (term-handle-ansi-escape): (term-termcap-format): Handle termcaps for entering and leaving an alternative sub-buffer. (term-switch-to-alternate-sub-buffer): New (used to be commented out) function to enter or leave an alternative sub-buffer. bug#53485 --- etc/e/eterm-color | Bin 1296 -> 1318 bytes etc/e/eterm-color.ti | 5 ++- etc/e/eterm-direct | Bin 1375 -> 1397 bytes lisp/term.el | 92 +++++++++++++++++++++++++++---------------- 4 files changed, 60 insertions(+), 37 deletions(-) diff --git a/etc/e/eterm-color b/etc/e/eterm-color index bf44fa0f36de0f6681fa3172db13a83c414aa42a..fadac25ffcb55b3b3f6812e9c80f848e94f3dcc3 100644 GIT binary patch delta 283 zcmbQhwTz2fiqV}xl7XKglkwCn)5<@zW&S5BIC4glF4H;!5mNKjYa@GU!W`-RMd!Y&rGEAPxsAO}L z;T*$th6g~wmkgg6egkP1MwodJnit9!0Mf#YVvG_{zBJ?Hi;PxGvLNc@WC2EYCM8Co zk$PO}j7DH3=8Qn=rNkVd>XA)#1!?kP_Gavw9LOBSY+{}@QmR-kp2Nx0yCMB5yD~t((H^}j66_2KjY+wj8;s7AnGvCEM6ut#>opA^|+)N r)xb)$87Dh3N{N|3)x*pK(Uu@hUd;B4b(5o+qbBcWR^I%C*@+PVcS)1K diff --git a/etc/e/eterm-color.ti b/etc/e/eterm-color.ti index eeb9b0b6e6a..84b27aef5d9 100644 --- a/etc/e/eterm-color.ti +++ b/etc/e/eterm-color.ti @@ -16,6 +16,7 @@ eterm-color|Emacs term.el terminal emulator term-protocol-version 0.96, am, mir, msgr, + nrrmc, xenl, bel=^G, blink=\E[5m, @@ -77,8 +78,8 @@ eterm-color|Emacs term.el terminal emulator term-protocol-version 0.96, smso=\E[7m, u6=\E[%i%d;%dR, u7=\E[6n, -# smcup=\E[?47h, -# rmcup=\E[?47l, + smcup=\E[47h, + rmcup=\E[47l, # rs2 may need to be added eterm-direct|Emacs term.el with direct-color indexing term-protocol-version 0.96, diff --git a/etc/e/eterm-direct b/etc/e/eterm-direct index c113c3713693b948ae9d52e75df5d89957fd0c77..f4c16621eb185d7d0de14b56fb2e2b73a57adab8 100644 GIT binary patch delta 259 zcmcc5^_7cTjwz5ql7XKglkww3?nF)o7?_w{>JrZI|9>n)5<@zW&S5BIC4gjv8)YPxGOPl!*8}lph8+xhq4EbACLd%}vOdai zj^R4P1EAnbhEEK?fiw#v%s2?m3*`#{X<gMrG@r42Kv_Gh6`*-DP;j z@E%D2fJ(zmWMqV}Sb#J;BNrnNl+Qm|ky&{11x5`I)2BRfZu?4d| term-home-marker home-marker) + (let ((inhibit-read-only t)) + (delete-region home-marker term-home-marker))))))) ;; Recursive routine used to check if any string in term-kill-echo-list ;; matches part of the buffer before point. @@ -1611,6 +1631,7 @@ Using \"emacs\" loses, because bash disables editing if $TERM == emacs.") "%s%s:li#%d:co#%d:cl=\\E[H\\E[J:cd=\\E[J:bs:am:xn:cm=\\E[%%i%%d;%%dH\ :nd=\\E[C:up=\\E[A:ce=\\E[K:ho=\\E[H:pt\ :al=\\E[L:dl=\\E[M:DL=\\E[%%dM:AL=\\E[%%dL:cs=\\E[%%i%%d;%%dr:sf=^J\ +:NR:te=\\E[47l:ti=\\E[47h\ :dc=\\E[P:DC=\\E[%%dP:IC=\\E[%%d@:im=\\E[4h:ei=\\E[4l:mi:\ :mb=\\E[5m:mh=\\E[2m:ZR=\\E[23m:ZH=\\E[3m\ :so=\\E[7m:se=\\E[m:us=\\E[4m:ue=\\E[m:md=\\E[1m:mr=\\E[7m:me=\\E[m\ @@ -3539,16 +3560,14 @@ otherwise use the current foreground color." ((eq char ?h) (cond ((eq (car params) 4) ;; (terminfo: smir) (setq term-insert-mode t)) - ;; ((eq (car params) 47) ;; (terminfo: smcup) - ;; (term-switch-to-alternate-sub-buffer t)) - )) + ((eq (car params) 47) ;; (terminfo: smcup) + (term-switch-to-alternate-sub-buffer t)))) ;; \E[?l - DEC Private Mode Reset ((eq char ?l) (cond ((eq (car params) 4) ;; (terminfo: rmir) (setq term-insert-mode nil)) - ;; ((eq (car params) 47) ;; (terminfo: rmcup) - ;; (term-switch-to-alternate-sub-buffer nil)) - )) + ((eq (car params) 47) ;; (terminfo: rmcup) + (term-switch-to-alternate-sub-buffer nil)))) ;; Modified to allow ansi coloring -mm ;; \E[m - Set/reset modes, set bg/fg @@ -3595,32 +3614,35 @@ The top-most line is line 0." (term-move-columns (- (term-current-column))) (term-goto 0 0)) -;; (defun term-switch-to-alternate-sub-buffer (set) -;; ;; If asked to switch to (from) the alternate sub-buffer, and already (not) -;; ;; using it, do nothing. This test is needed for some programs (including -;; ;; Emacs) that emit the ti termcap string twice, for unknown reason. -;; (term-handle-deferred-scroll) -;; (if (eq set (not (term-using-alternate-sub-buffer))) -;; (let ((row (term-current-row)) -;; (col (term-horizontal-column))) -;; (cond (set -;; (goto-char (point-max)) -;; (if (not (eq (preceding-char) ?\n)) -;; (term-insert-char ?\n 1)) -;; (setq term-scroll-with-delete t) -;; (setq term-saved-home-marker (copy-marker term-home-marker)) -;; (set-marker term-home-marker (point))) -;; (t -;; (setq term-scroll-with-delete -;; (not (and (= term-scroll-start 0) -;; (= term-scroll-end term-height)))) -;; (set-marker term-home-marker term-saved-home-marker) -;; (set-marker term-saved-home-marker nil) -;; (setq term-saved-home-marker nil) -;; (goto-char term-home-marker))) -;; (setq term-current-column nil) -;; (setq term-current-row 0) -;; (term-goto row col)))) +(defun term-switch-to-alternate-sub-buffer (set) + ;; If asked to switch to (from) the alternate sub-buffer, and already (not) + ;; using it, do nothing. This test is needed for some programs (including + ;; Emacs) that emit the ti termcap string twice, for unknown reason. + (term-handle-deferred-scroll) + (when (eq set (not (term-using-alternate-sub-buffer))) + (cond + (set + (goto-char (point-max)) + (if (not (eq (preceding-char) ?\n)) + (term-insert-char ?\n 1)) + (setq term-scroll-with-delete t) + (setq term-saved-home-marker (copy-marker term-home-marker)) + (set-marker term-home-marker (point))) + (t + (setq term-scroll-with-delete + (not (and (= term-scroll-start 0) + (= term-scroll-end (term--last-line))))) + (goto-char (point-max)) + (when term-clear-full-screen-programs + (delete-region term-home-marker (point)) + (set-marker term-home-marker term-saved-home-marker)) + (set-marker term-saved-home-marker nil) + (setq term-saved-home-marker nil))) + + (setq term-start-line-column nil) + (setq term-current-column nil) + (setq term-current-row nil) + (term-handle-deferred-scroll))) ;; Default value for the symbol term-command-function. -- 2.39.2