Skip to content

Commit bb213bb

Browse files
FrostyXjixiuf
authored andcommitted
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)))))
1 parent 3e5a9b7 commit bb213bb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

vterm.el

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,19 +1679,25 @@ in README."
16791679
(when pt (goto-char (1- pt))))))
16801680
(term-previous-prompt n)))
16811681

1682-
(defun vterm--get-beginning-of-line ()
1683-
"Find the start of the line, bypassing line wraps."
1682+
(defun vterm--get-beginning-of-line (&optional pt)
1683+
"Find the start of the line, bypassing line wraps.
1684+
If PT is specified, find it's beginning of the line instead of the beginning
1685+
of the line at cursor."
16841686
(save-excursion
1687+
(when pt (goto-char pt))
16851688
(beginning-of-line)
16861689
(while (and (not (bobp))
16871690
(get-text-property (1- (point)) 'vterm-line-wrap))
16881691
(forward-char -1)
16891692
(beginning-of-line))
16901693
(point)))
16911694

1692-
(defun vterm--get-end-of-line ()
1693-
"Find the start of the line, bypassing line wraps."
1695+
(defun vterm--get-end-of-line (&optional pt)
1696+
"Find the start of the line, bypassing line wraps.
1697+
If PT is specified, find it's end of the line instead of the end
1698+
of the line at cursor."
16941699
(save-excursion
1700+
(when pt (goto-char pt))
16951701
(end-of-line)
16961702
(while (get-text-property (point) 'vterm-line-wrap)
16971703
(forward-char)

0 commit comments

Comments
 (0)