Skip to content

Commit ea4353f

Browse files
committed
Add M-< / M-> to jump to top/bottom of scrollback in copy mode
New native functions ghostel--scroll-top and ghostel--scroll-bottom use ghostty's SCROLL_TOP/SCROLL_BOTTOM viewport tags for instant navigation to the edges of the scrollback buffer.
1 parent 83b7f44 commit ea4353f

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

ghostel.el

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,24 @@ pasted using bracketed paste."
733733
(move-to-column col)))
734734
(forward-line 1)))
735735

736+
(defun ghostel-copy-mode-beginning-of-buffer ()
737+
"Scroll to the top of scrollback in copy mode."
738+
(interactive)
739+
(when ghostel--term
740+
(ghostel--scroll-top ghostel--term)
741+
(let ((inhibit-read-only t))
742+
(ghostel--redraw ghostel--term))
743+
(goto-char (point-min))))
744+
745+
(defun ghostel-copy-mode-end-of-buffer ()
746+
"Scroll to the bottom of scrollback in copy mode."
747+
(interactive)
748+
(when ghostel--term
749+
(ghostel--scroll-bottom ghostel--term)
750+
(let ((inhibit-read-only t))
751+
(ghostel--redraw ghostel--term))
752+
(goto-char (point-max))))
753+
736754
;;; Mouse input
737755

738756
(defun ghostel--mouse-button-number (event)
@@ -814,6 +832,8 @@ pasted using bracketed paste."
814832
(define-key map (kbd "C-v") #'ghostel-copy-mode-scroll-down)
815833
(define-key map (kbd "C-n") #'ghostel-copy-mode-next-line)
816834
(define-key map (kbd "C-p") #'ghostel-copy-mode-previous-line)
835+
(define-key map (kbd "M-<") #'ghostel-copy-mode-beginning-of-buffer)
836+
(define-key map (kbd "M->") #'ghostel-copy-mode-end-of-buffer)
817837
map)
818838
"Keymap for `ghostel-copy-mode'.
819839
Standard Emacs navigation works.

src/module.zig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export fn emacs_module_init(runtime: *c.struct_emacs_runtime) callconv(.c) c_int
3333
env.bindFunction("ghostel--get-pwd", 1, 1, &fnGetPwd, "Get the terminal's working directory from OSC 7.\n\n(ghostel--get-pwd TERM)");
3434
env.bindFunction("ghostel--redraw", 1, 1, &fnRedraw, "Redraw dirty regions of the terminal into the current buffer.\n\n(ghostel--redraw TERM)");
3535
env.bindFunction("ghostel--scroll", 2, 2, &fnScroll, "Scroll the terminal viewport by DELTA lines.\n\n(ghostel--scroll TERM DELTA)");
36+
env.bindFunction("ghostel--scroll-top", 1, 1, &fnScrollTop, "Scroll the terminal viewport to the top of scrollback.\n\n(ghostel--scroll-top TERM)");
37+
env.bindFunction("ghostel--scroll-bottom", 1, 1, &fnScrollBottom, "Scroll the terminal viewport to the bottom.\n\n(ghostel--scroll-bottom TERM)");
3638
env.bindFunction("ghostel--encode-key", 3, 4, &fnEncodeKey, "Encode a key event using the terminal's key encoder.\n\n(ghostel--encode-key TERM KEY MODS &optional UTF8)");
3739
env.bindFunction("ghostel--mouse-event", 6, 6, &fnMouseEvent, "Send a mouse event to the terminal.\n\n(ghostel--mouse-event TERM ACTION BUTTON ROW COL MODS)");
3840
env.bindFunction("ghostel--focus-event", 2, 2, &fnFocusEvent, "Send a focus event to the terminal.\n\n(ghostel--focus-event TERM GAINED)");
@@ -343,6 +345,22 @@ fn fnScroll(raw_env: ?*c.emacs_env, _: isize, args: [*c]c.emacs_value, _: ?*anyo
343345
return env.nil();
344346
}
345347

348+
/// (ghostel--scroll-top TERM)
349+
fn fnScrollTop(raw_env: ?*c.emacs_env, _: isize, args: [*c]c.emacs_value, _: ?*anyopaque) callconv(.c) c.emacs_value {
350+
const env = emacs.Env.init(raw_env.?);
351+
const term = env.getUserPtr(Terminal, args[0]) orelse return env.nil();
352+
term.scrollViewport(gt.SCROLL_TOP, 0);
353+
return env.nil();
354+
}
355+
356+
/// (ghostel--scroll-bottom TERM)
357+
fn fnScrollBottom(raw_env: ?*c.emacs_env, _: isize, args: [*c]c.emacs_value, _: ?*anyopaque) callconv(.c) c.emacs_value {
358+
const env = emacs.Env.init(raw_env.?);
359+
const term = env.getUserPtr(Terminal, args[0]) orelse return env.nil();
360+
term.scrollViewport(gt.SCROLL_BOTTOM, 0);
361+
return env.nil();
362+
}
363+
346364
/// (ghostel--encode-key TERM KEY MODS &optional UTF8)
347365
/// Encode a key event and send it to the PTY.
348366
/// KEY is a key name string (e.g. "a", "return", "up", "f1").

0 commit comments

Comments
 (0)