aboutsummaryrefslogtreecommitdiff
path: root/vterm.el
diff options
context:
space:
mode:
authorJakub Kadlcik <frostyx@email.cz>2023-04-01 18:28:49 +0200
committerjixiuf <jixiuf@qq.com>2023-04-17 12:16:44 +0800
commitbb213bb97800d35a93d0fc1138d9e0ec2c0807a8 (patch)
treec62722de1dcfb748dbbddd63b0b59893a8b5bcb7 /vterm.el
parent3e5a9b754b8e61850bb7d1b63b090b9fbf6687f3 (diff)
Allow to find beginning and end of line from a specific point
I didn't find an easy way to determine whether the cursor is in the last prompt line or what the prompt line number even is. And one cannot assume the prompt line is the last line of the buffer beacuse vterm is basically a rectangle filling the whole buffer. As a consequence `(line-number-at-pos (point-max))` _doesn't work_ because `(point-max)` _doesn't work_. With this patch, it is possible to find the prompt line using: (line-number-at-pos (vterm--get-beginning-of-line (vterm--get-cursor-point))))) And in case the command in prompt is long and wraps into multiple lines, its end can be found using: (line-number-at-pos (vterm--get-end-of-line (vterm--get-cursor-point)))))
Diffstat (limited to 'vterm.el')
-rw-r--r--vterm.el14
1 files changed, 10 insertions, 4 deletions
diff --git a/vterm.el b/vterm.el
index 2f32319..4b44c6b 100644
--- a/vterm.el
+++ b/vterm.el
@@ -1679,9 +1679,12 @@ in README."
(when pt (goto-char (1- pt))))))
(term-previous-prompt n)))
-(defun vterm--get-beginning-of-line ()
- "Find the start of the line, bypassing line wraps."
+(defun vterm--get-beginning-of-line (&optional pt)
+ "Find the start of the line, bypassing line wraps.
+If PT is specified, find it's beginning of the line instead of the beginning
+of the line at cursor."
(save-excursion
+ (when pt (goto-char pt))
(beginning-of-line)
(while (and (not (bobp))
(get-text-property (1- (point)) 'vterm-line-wrap))
@@ -1689,9 +1692,12 @@ in README."
(beginning-of-line))
(point)))
-(defun vterm--get-end-of-line ()
- "Find the start of the line, bypassing line wraps."
+(defun vterm--get-end-of-line (&optional pt)
+ "Find the start of the line, bypassing line wraps.
+If PT is specified, find it's end of the line instead of the end
+of the line at cursor."
(save-excursion
+ (when pt (goto-char pt))
(end-of-line)
(while (get-text-property (point) 'vterm-line-wrap)
(forward-char)