[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/coterm 044b03e 06/80: Simplify
From: |
ELPA Syncer |
Subject: |
[elpa] externals/coterm 044b03e 06/80: Simplify |
Date: |
Wed, 13 Oct 2021 18:57:25 -0400 (EDT) |
branch: externals/coterm
commit 044b03efd3102c8abdd99e73981b8223b8050b6a
Author: m <>
Commit: m <>
Simplify
---
coterm.el | 111 ++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 61 insertions(+), 50 deletions(-)
diff --git a/coterm.el b/coterm.el
index 897e63e..d27d8f9 100644
--- a/coterm.el
+++ b/coterm.el
@@ -49,6 +49,48 @@ In sync with variables `coterm--t-home-marker',
(setq coterm-t-height height)
(setq coterm-t-width width))
+(defun coterm--t-point (row col)
+ "Return position that approximates ROW and COL."
+ (save-excursion
+ (goto-char coterm--t-home-marker)
+ (and
+ (zerop (forward-line
+ (+ coterm--t-home-offset row)))
+ (not (eobp))
+ (move-to-column col))
+ (point)))
+
+(defun coterm--t-delete-region (row1 col1 row2 col2)
+ (delete-region (coterm--t-point row1 col1)
+ (coterm--t-point row2 col2))
+ (setq coterm--t-pmark-in-sync nil))
+
+(defun coterm--t-clear-region (proc-filt process row1 col1 row2 col2)
+ (save-excursion
+ (let ((p1 (coterm--t-point row1 col1))
+ (p2 (coterm--t-point row2 col2))
+ row col h)
+ (if (> p2 p1)
+ (setq row row1 col col1
+ h (- row2 row1))
+ (setq row row2 col col2
+ h (- row1 row2)))
+ (delete-region p1 p2)
+ (coterm--t-open-space proc-filt process row col h (abs (- col2 col1)))
+ (setq coterm--t-pmark-in-sync nil))))
+
+(defun coterm--t-open-space (proc-filt process row col height width)
+ (save-excursion
+ (goto-char (coterm--t-point row col))
+ (unless (eobp)
+ (set-marker (process-mark process) (point))
+ (funcall
+ proc-filt process
+ (concat (make-string height ?\n)
+ (unless (eolp)
+ (make-string (+ width (if (= row 0) 0 col)) ?\s))))
+ (setq coterm--t-pmark-in-sync nil))))
+
(defun coterm--t-normalize-home-offset ()
(save-excursion
(goto-char coterm--t-home-marker)
@@ -268,9 +310,9 @@ initialize it sensibly."
(?8 (ins) ;; Restore cursor (terminfo: rc)
(when-let ((cursor coterm--t-saved-cursor))
(setq coterm--t-row (car cursor))
- (setq cursor (cdr (cursor)))
+ (setq cursor (cdr cursor))
(setq coterm--t-col (car cursor))
- (setq cursor (cdr (cursor)))
+ (setq cursor (cdr cursor))
(when (car cursor)
(setq coterm--t-row (caar cursor)))))
(?c (ins) ;; \Ec - Reset (terminfo: rs1)
@@ -313,64 +355,33 @@ initialize it sensibly."
;; \E[J - clear to end of screen (terminfo: ed, clear)
((and ?J (guard (eq 0 (car ctl-params))))
(ins)
- (coterm--t-approximate-pmark pmark)
- (delete-region pmark (point-max))
+ (delete-region (coterm--t-point coterm--t-row
coterm--t-col)
+ (point-max))
(dirty))
((and ?J (guard (eq 1 (car ctl-params))))
(ins)
- (coterm--t-approximate-pmark pmark)
- (coterm--t-normalize-home-offset)
- (delete-region coterm--t-home-marker pmark)
- (if (= pmark (point-max))
- (dirty)
- ;; Substitute deleted region with empty lines
- (funcall proc-filt process
- (concat (make-string coterm--t-row ?\n)
- (unless (eq (char-after pmark)
?\n)
- (make-string coterm--t-col
?\s))))))
+ (coterm--t-clear-region
+ proc-filt process 0 0 coterm--t-row coterm--t-col))
(?J
(ins)
- (coterm--t-normalize-home-offset)
- (delete-region coterm--t-home-marker (point-max))
+ (delete-region (coterm--t-point 0 0) (point-max))
(dirty))
(?K ;; \E[K - clear to end of line (terminfo: el, el1)
(ins)
- (coterm--t-approximate-pmark pmark)
- (save-excursion
- (goto-char pmark)
- (if (eq 1 (car ctl-params))
- ;; Clear left of pmark
- (forward-line 0)
- ;; Clear right of pmark
- (forward-line 1)
- (unless (eobp)
- (backward-char)))
- (delete-region (point) pmark)
- (if (eolp)
- (if (eq 1 (car ctl-params)) (dirty))
- (funcall proc-filt process
- (make-string coterm--t-col ?\s)))))
+ (coterm--t-clear-region
+ proc-filt process
+ coterm--t-row coterm--t-col
+ coterm--t-row (if (eq 1 (car ctl-params)) 0
+ coterm-t-width)))
(?L ;; \E[L - insert lines (terminfo: il, il1)
;; Remove from bottom
- (let ((coterm--t-col 0)
- end)
- (dirty)
- (let ((coterm--t-row coterm-t-height) )
- (coterm--t-approximate-pmark pmark)
- (setq end (marker-position pmark)))
- (let ((coterm--t-row
- (max (- coterm-t-height
- (car ctl-params))
- coterm--t-row)))
- (coterm--t-approximate-pmark pmark)
- (delete-region pmark end))
- (dirty)
- ;; Insert new lines
- (coterm--t-approximate-pmark pmark)
- (unless (= pmark (point-max))
- (funcall proc-filt process
- (make-string (car ctl-params) ?\n))))
- (dirty))))))))))
+ (coterm--t-delete-region
+ coterm-t-height 0
+ (- coterm-t-height (car ctl-params)))
+ ;; Insert at position
+ (coterm--t-open-space
+ proc-filt process coterm--t-row 0
+ (car ctl-params) 0))))))))))
(cond
((setq match (string-match coterm-t-control-seq-prefix-regexp
- [elpa] externals/coterm 29ef3ad 07/80: Fix scrolling, (continued)
- [elpa] externals/coterm 29ef3ad 07/80: Fix scrolling, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm ba74fb8 10/80: Simplify, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm f1cc63e 12/80: Support \e[6n for reporting cursor position, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm cfc9f03 13/80: Fix some escape params defaulting to 1, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm cf9217d 09/80: Support \e[P and \e[@, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm e22fe83 17/80: Adjust column after resizing window, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 586ce4e 20/80: Delete off-screen rows when scrolling up, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 7b1e001 01/80: Initial commit, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm a983b5e 02/80: New function for approximately moving pmark, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 0647615 04/80: Plug marker leak, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 044b03e 06/80: Simplify,
ELPA Syncer <=
- [elpa] externals/coterm c48515c 11/80: Support \e[4h and \e[4l for insert mode, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm ab1dcd4 14/80: Fix typo, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm ba651c6 15/80: Fix negative and too high column positions, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 2403460 16/80: Make all coterm-t-* variables private, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 753fba8 21/80: Refactor line deletion and insertion, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 9d532fb 22/80: Refactor some more, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm e21bb54 18/80: Major refactor and started scroll region, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 4a23ae2 23/80: Further refactor some more, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 08cf379 19/80: Minor fixes, ELPA Syncer, 2021/10/13
- [elpa] externals/coterm 9e7720b 37/80: Use save-excursion more sparingly, ELPA Syncer, 2021/10/13