Skip to content

Commit 156a714

Browse files
committed
Remove dead scroll commands and add C-c C-l to copy mode
Since scrollback is materialized directly into the Emacs buffer, the Zig viewport-scroll functions ghostel--scroll and ghostel--scroll-top are never called. Remove them along with the redundant ghostel-copy-mode-scroll-up/down wrappers (M-v/C-v inherit scroll-down/up-command from the global keymap). Keep ghostel--scroll-bottom for scroll-on-input — it's a cheap no-op when the viewport is already at the bottom. Also bind C-c C-l in copy mode to exit and clear scrollback, matching the terminal-mode binding.
1 parent 2d3bda7 commit 156a714

3 files changed

Lines changed: 22 additions & 68 deletions

File tree

ghostel.el

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,7 @@ Bump this only when the Elisp code requires a newer native module
397397
(declare-function ghostel--mouse-event "ghostel-module")
398398
(declare-function ghostel--new "ghostel-module")
399399
(declare-function ghostel--redraw "ghostel-module" (term &optional full))
400-
(declare-function ghostel--scroll "ghostel-module")
401400
(declare-function ghostel--scroll-bottom "ghostel-module")
402-
(declare-function ghostel--scroll-top "ghostel-module")
403401
(declare-function ghostel--set-default-colors "ghostel-module")
404402
(declare-function ghostel--set-palette "ghostel-module")
405403
(declare-function ghostel--set-size "ghostel-module")
@@ -1129,15 +1127,6 @@ scroll event to the running application instead."
11291127
(unless (ghostel--forward-scroll-event event 5) ; button 5 = scroll down
11301128
(scroll-up 3)))
11311129

1132-
(defun ghostel-copy-mode-scroll-up ()
1133-
"Scroll the Emacs window up by a page in copy mode."
1134-
(interactive)
1135-
(scroll-down-command))
1136-
1137-
(defun ghostel-copy-mode-scroll-down ()
1138-
"Scroll the Emacs window down by a page in copy mode."
1139-
(interactive)
1140-
(scroll-up-command))
11411130

11421131
(defun ghostel-copy-mode-previous-line ()
11431132
"Move to the previous line in copy mode."
@@ -1256,14 +1245,13 @@ scroll event to the running application instead."
12561245
(define-key map (kbd "<mouse-5>") #'ghostel--scroll-down)
12571246
(define-key map (kbd "<wheel-up>") #'ghostel--scroll-up)
12581247
(define-key map (kbd "<wheel-down>") #'ghostel--scroll-down)
1259-
(define-key map (kbd "M-v") #'ghostel-copy-mode-scroll-up)
1260-
(define-key map (kbd "C-v") #'ghostel-copy-mode-scroll-down)
12611248
(define-key map (kbd "C-n") #'ghostel-copy-mode-next-line)
12621249
(define-key map (kbd "C-p") #'ghostel-copy-mode-previous-line)
12631250
(define-key map (kbd "M-<") #'ghostel-copy-mode-beginning-of-buffer)
12641251
(define-key map (kbd "M->") #'ghostel-copy-mode-end-of-buffer)
12651252
(define-key map (kbd "C-e") #'ghostel-copy-mode-end-of-line)
12661253
(define-key map (kbd "C-l") #'ghostel-copy-mode-recenter)
1254+
(define-key map (kbd "C-c C-l") #'ghostel-copy-mode-exit-and-clear)
12671255
map)
12681256
"Keymap for `ghostel-copy-mode'.
12691257
Standard Emacs navigation works.
@@ -1323,6 +1311,12 @@ in the buffer. Press \\`q' or \\[ghostel-copy-mode-exit] to exit."
13231311
(ghostel--invalidate)
13241312
(message "Copy mode exited")))
13251313

1314+
(defun ghostel-copy-mode-exit-and-clear ()
1315+
"Exit copy mode and clear the scrollback."
1316+
(interactive)
1317+
(ghostel-copy-mode-exit)
1318+
(ghostel-clear-scrollback))
1319+
13261320
(defun ghostel-copy-mode-exit-and-send ()
13271321
"Exit copy mode and send the key that triggered exit to the terminal."
13281322
(interactive)

src/module.zig

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ export fn emacs_module_init(runtime: *c.struct_emacs_runtime) callconv(.c) c_int
3535
env.bindFunction("ghostel--get-title", 1, 1, &fnGetTitle, "Get the terminal title.\n\n(ghostel--get-title TERM)");
3636
env.bindFunction("ghostel--get-pwd", 1, 1, &fnGetPwd, "Get the terminal's working directory from OSC 7.\n\n(ghostel--get-pwd TERM)");
3737
env.bindFunction("ghostel--redraw", 1, 2, &fnRedraw, "Redraw the terminal into the current buffer.\n\n(ghostel--redraw TERM &optional FULL)");
38-
env.bindFunction("ghostel--scroll", 2, 2, &fnScroll, "Scroll the terminal viewport by DELTA lines.\n\n(ghostel--scroll TERM DELTA)");
39-
env.bindFunction("ghostel--scroll-top", 1, 1, &fnScrollTop, "Scroll the terminal viewport to the top of scrollback.\n\n(ghostel--scroll-top TERM)");
4038
env.bindFunction("ghostel--scroll-bottom", 1, 1, &fnScrollBottom, "Scroll the terminal viewport to the bottom.\n\n(ghostel--scroll-bottom TERM)");
4139
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)");
4240
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)");
@@ -536,25 +534,6 @@ fn fnRedraw(raw_env: ?*c.emacs_env, nargs: isize, args: [*c]c.emacs_value, _: ?*
536534
return env.nil();
537535
}
538536

539-
/// (ghostel--scroll TERM DELTA)
540-
fn fnScroll(raw_env: ?*c.emacs_env, _: isize, args: [*c]c.emacs_value, _: ?*anyopaque) callconv(.c) c.emacs_value {
541-
const env = emacs.Env.init(raw_env.?);
542-
const term = env.getUserPtr(Terminal, args[0]) orelse return env.nil();
543-
544-
const delta = env.extractInteger(args[1]);
545-
term.scrollViewport(gt.SCROLL_DELTA, @intCast(delta));
546-
547-
return env.nil();
548-
}
549-
550-
/// (ghostel--scroll-top TERM)
551-
fn fnScrollTop(raw_env: ?*c.emacs_env, _: isize, args: [*c]c.emacs_value, _: ?*anyopaque) callconv(.c) c.emacs_value {
552-
const env = emacs.Env.init(raw_env.?);
553-
const term = env.getUserPtr(Terminal, args[0]) orelse return env.nil();
554-
term.scrollViewport(gt.SCROLL_TOP, 0);
555-
return env.nil();
556-
}
557-
558537
/// (ghostel--scroll-bottom TERM)
559538
fn fnScrollBottom(raw_env: ?*c.emacs_env, _: isize, args: [*c]c.emacs_value, _: ?*anyopaque) callconv(.c) c.emacs_value {
560539
const env = emacs.Env.init(raw_env.?);

test/ghostel-test.el

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,6 @@ succeeds."
175175
(let ((state (ghostel--debug-state term)))
176176
(should (string-match-p "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" state))))) ; 40 x's on row
177177

178-
;; -----------------------------------------------------------------------
179-
;; Test: scrollback
180-
;; -----------------------------------------------------------------------
181-
182-
(ert-deftest ghostel-test-scrollback ()
183-
"Test scrollback by overflowing visible rows."
184-
(let ((term (ghostel--new 5 80 100)))
185-
(dotimes (i 10)
186-
(ghostel--write-input term (format "line %d\r\n" i)))
187-
(let ((state (ghostel--debug-state term)))
188-
(should (string-match-p "line [6-9]" state))) ; recent lines visible
189-
(ghostel--scroll term -5)
190-
(let ((state (ghostel--debug-state term)))
191-
(should (string-match-p "line [0-4]" state))))) ; scrollback shows earlier lines
192-
193178
;; -----------------------------------------------------------------------
194179
;; Test: scrollback is materialized into the Emacs buffer (vterm parity)
195180
;; -----------------------------------------------------------------------
@@ -427,25 +412,21 @@ scrolling libghostty's viewport."
427412
(with-current-buffer buf
428413
(ghostel-mode)
429414
(setq ghostel--term (ghostel--new 5 80 100))
430-
;; Fill screen + scrollback with 10 lines
431-
(dotimes (i 10)
432-
(ghostel--write-input ghostel--term (format "line %d\r\n" i)))
433-
;; Verify content on screen and in scrollback
434-
(let ((state (ghostel--debug-state ghostel--term)))
435-
(should (string-match-p "line [6-9]" state))) ; recent lines on screen
436-
(ghostel--scroll ghostel--term -5)
437-
(let ((state (ghostel--debug-state ghostel--term)))
438-
(should (string-match-p "line [0-4]" state))) ; early lines in scrollback
439-
;; Return to bottom and call the actual function
440-
(ghostel--scroll-bottom ghostel--term)
441-
(ghostel-clear-scrollback)
442-
;; Screen should be empty
443-
(let ((state (ghostel--debug-state ghostel--term)))
444-
(should-not (string-match-p "line [6-9]" state))) ; screen cleared
445-
;; Scrollback should also be empty
446-
(ghostel--scroll ghostel--term -10)
447-
(let ((state (ghostel--debug-state ghostel--term)))
448-
(should-not (string-match-p "line [0-4]" state)))) ; scrollback cleared
415+
(let ((inhibit-read-only t))
416+
;; Fill screen + scrollback with 10 lines
417+
(dotimes (i 10)
418+
(ghostel--write-input ghostel--term (format "line %d\r\n" i)))
419+
(ghostel--redraw ghostel--term t)
420+
;; Verify lines materialized in the buffer
421+
(let ((content (buffer-substring-no-properties (point-min) (point-max))))
422+
(should (string-match-p "line 0" content))
423+
(should (string-match-p "line 9" content)))
424+
;; Clear scrollback (sends CSI 3J to libghostty)
425+
(ghostel-clear-scrollback)
426+
(ghostel--redraw ghostel--term t)
427+
;; Screen and scrollback should be empty
428+
(let ((content (buffer-substring-no-properties (point-min) (point-max))))
429+
(should-not (string-match-p "line [0-9]" content)))))
449430
(kill-buffer buf))))
450431

451432
;; -----------------------------------------------------------------------

0 commit comments

Comments
 (0)