Skip to content

Commit 14b4e85

Browse files
committed
Deactivate mark when C-g is sent to the terminal
`ghostel-mode' sets `inhibit-quit' so C-g routes through the keymap into `ghostel-send-C-g' instead of running `keyboard-quit'. That sent SIGINT to the PTY but skipped the side effect users expect from C-g — clearing the active region. Call `deactivate-mark' explicitly, mirroring what `ghostel-copy-mode-exit' already does. Fixes #200.
1 parent 0b19011 commit 14b4e85

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

lisp/ghostel.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,9 +1447,11 @@ paste rather than character-by-character typed keystrokes."
14471447
(defun ghostel-send-C-g ()
14481448
"Send \\`C-g' to the terminal.
14491449
Clears `quit-flag' which Emacs sets when \\`C-g' is pressed with
1450-
`inhibit-quit' non-nil."
1450+
`inhibit-quit' non-nil, and deactivates the mark so the region
1451+
overlay clears the way \\`keyboard-quit' would in other buffers."
14511452
(interactive)
14521453
(setq quit-flag nil)
1454+
(deactivate-mark)
14531455
(ghostel--send-string (string 7)))
14541456

14551457

test/ghostel-test.el

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6386,6 +6386,29 @@ rather than the selected window's buffer."
63866386
(should (local-variable-p 'inhibit-quit)))
63876387
(kill-buffer buf))))
63886388

6389+
(ert-deftest ghostel-test-c-g-deactivates-mark ()
6390+
"`ghostel-send-C-g' should clear an active region and `quit-flag'.
6391+
`keyboard-quit' is bypassed because `inhibit-quit' is set, so both
6392+
side effects have to happen explicitly inside the command."
6393+
(let ((buf (generate-new-buffer " *ghostel-test-c-g-mark*"))
6394+
(sent nil))
6395+
(unwind-protect
6396+
(with-current-buffer buf
6397+
(ghostel-mode)
6398+
(insert "hello world")
6399+
(goto-char (point-min))
6400+
(set-mark (point))
6401+
(goto-char (point-max))
6402+
(should (region-active-p))
6403+
(setq quit-flag t)
6404+
(cl-letf (((symbol-function 'ghostel--send-string)
6405+
(lambda (s) (push s sent))))
6406+
(ghostel-send-C-g))
6407+
(should-not (region-active-p))
6408+
(should-not quit-flag)
6409+
(should (equal sent (list (string 7)))))
6410+
(kill-buffer buf))))
6411+
63896412
(ert-deftest ghostel-test-meta-key-bindings ()
63906413
"All non-exception M-<letter> keys should be bound in ghostel-mode-map."
63916414
(dolist (c (number-sequence ?a ?z))

0 commit comments

Comments
 (0)