Skip to content

Commit d4ac858

Browse files
committed
Fix C-t and other control keys not being sent to the terminal
Several control keys (C-b, C-f, C-j, C-o, C-q, C-s, C-t, C-v) were not bound in ghostel-mode-map, causing them to fall through to Emacs defaults (e.g. C-t triggered transpose-chars instead of sending ^T to the shell). Replace individual define-key calls with a loop that binds all C-a through C-z (minus ghostel-keymap-exceptions and TAB/RET/yank special cases). Also bind C-@ (NUL) for programs that use it.
1 parent 97e18e8 commit d4ac858

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

ghostel.el

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -620,21 +620,26 @@ Used for prompt navigation and optional re-application after full redraws.")
620620
(define-key map (kbd "DEL") #'ghostel--send-event)
621621
;; Emacs reports S-TAB as <backtab>
622622
(define-key map (kbd "<backtab>") #'ghostel--send-event)
623-
;; Control keys
624-
(define-key map (kbd "C-d") (lambda () (interactive) (ghostel--send-key "\x04")))
625-
(define-key map (kbd "C-a") (lambda () (interactive) (ghostel--send-key "\x01")))
626-
(define-key map (kbd "C-e") (lambda () (interactive) (ghostel--send-key "\x05")))
627-
(define-key map (kbd "C-k") (lambda () (interactive) (ghostel--send-key "\x0b")))
628-
(define-key map (kbd "C-l") (lambda () (interactive) (ghostel--send-key "\x0c")))
629-
(define-key map (kbd "C-n") (lambda () (interactive) (ghostel--send-key "\x0e")))
630-
(define-key map (kbd "C-p") (lambda () (interactive) (ghostel--send-key "\x10")))
631-
(define-key map (kbd "C-r") (lambda () (interactive) (ghostel--send-key "\x12")))
632-
(define-key map (kbd "C-w") (lambda () (interactive) (ghostel--send-key "\x17")))
623+
;; Control keys — bind all C-<letter> to send ASCII control codes,
624+
;; except keys in ghostel-keymap-exceptions and special cases.
625+
;; C-i = TAB and C-m = RET are equivalent to <tab>/<return> (bound above).
626+
(let ((skip '(?i ?m ?y))) ; i=TAB, m=RET already bound; y=ghostel-yank below
627+
(dolist (c (number-sequence ?a ?z))
628+
(let ((key-str (format "C-%c" c)))
629+
(unless (or (member key-str ghostel-keymap-exceptions)
630+
(memq c skip))
631+
(define-key map (kbd key-str)
632+
(let ((code (- c 96)))
633+
(lambda () (interactive)
634+
(ghostel--send-key (string code)))))))))
635+
;; C-@ (NUL, same as C-SPC) — used by programs like Emacs-in-terminal
636+
(define-key map (kbd "C-@")
637+
(lambda () (interactive) (ghostel--send-key "\x00")))
638+
;; C-y: yank from Emacs kill ring into the terminal
633639
(define-key map (kbd "C-y") #'ghostel-yank)
634640
(when (eq system-type 'darwin)
635641
(define-key map (kbd "s-v") #'ghostel-yank))
636642
(define-key map (kbd "M-y") #'ghostel-yank-pop)
637-
(define-key map (kbd "C-z") (lambda () (interactive) (ghostel--send-key "\x1a")))
638643
;; Terminal control via C-c prefix (pass through to Emacs, then handled here)
639644
(define-key map (kbd "C-c C-c") #'ghostel-send-C-c)
640645
(define-key map (kbd "C-c C-z") #'ghostel-send-C-z)

test/ghostel-test.el

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,18 @@ cell, so the visual line width must equal the terminal column count."
13941394
;; send-key sets last-send-time via the fallback path
13951395
(should ghostel--last-send-time)))))
13961396

1397+
(ert-deftest ghostel-test-control-key-bindings ()
1398+
"All non-exception C-<letter> keys should be bound in ghostel-mode-map."
1399+
(dolist (c (number-sequence ?a ?z))
1400+
(let* ((key-str (format "C-%c" c))
1401+
(key-vec (kbd key-str))
1402+
(binding (lookup-key ghostel-mode-map key-vec)))
1403+
;; Skip exceptions (may have sub-keymaps like C-c C-c)
1404+
(unless (member key-str ghostel-keymap-exceptions)
1405+
(should binding))))
1406+
;; C-@ should also be bound (sends NUL)
1407+
(should (lookup-key ghostel-mode-map (kbd "C-@"))))
1408+
13971409
(defconst ghostel-test--elisp-tests
13981410
'(ghostel-test-raw-key-sequences
13991411
ghostel-test-modifier-number
@@ -1420,7 +1432,8 @@ cell, so the visual line width must equal the terminal column count."
14201432
ghostel-test-input-coalesce-disabled
14211433
ghostel-test-input-flush-sends-buffered
14221434
ghostel-test-send-encoded-sets-send-time
1423-
ghostel-test-send-encoded-no-send-time-on-fallback)
1435+
ghostel-test-send-encoded-no-send-time-on-fallback
1436+
ghostel-test-control-key-bindings)
14241437
"Tests that require only Elisp (no native module).")
14251438

14261439
(defun ghostel-test-run-elisp ()

0 commit comments

Comments
 (0)