Skip to content

Commit c901c02

Browse files
committed
Add ghostel-ignore-cursor-change defcustom
When non-nil, terminal requests to change cursor shape or visibility are ignored. Useful when editor-owned cursor behavior should take precedence. Copy mode always forces a visible cursor regardless. Inspired by kiennq/ghostel fork.
1 parent 057fb1f commit c901c02

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ individual faces with `M-x customize-face`.
393393
| `ghostel-enable-osc52` | `nil` | Allow apps to set clipboard via OSC 52 |
394394
| `ghostel-enable-url-detection` | `t` | Linkify plain-text URLs in terminal output |
395395
| `ghostel-enable-file-detection` | `t` | Linkify file:line references in terminal output |
396+
| `ghostel-ignore-cursor-change` | `nil` | Ignore terminal-driven cursor shape/visibility changes |
396397
| `ghostel-keymap-exceptions` | `("C-c" "C-x" ...)` | Keys passed through to Emacs |
397398
| `ghostel-exit-functions` | `nil` | Hook run when the shell process exits |
398399

ghostel.el

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ When nil, falls back to `tramp-default-method'."
266266
These keys pass through to Emacs instead."
267267
:type '(repeat string))
268268

269+
(defcustom ghostel-ignore-cursor-change nil
270+
"When non-nil, ignore terminal requests to change cursor shape or visibility.
271+
Useful when editor-owned cursor behavior should take precedence over
272+
terminal-driven cursor changes. Copy mode restores `cursor-type' to its
273+
default value."
274+
:type 'boolean)
275+
269276
(defcustom ghostel-scroll-on-input t
270277
"Automatically scroll to the bottom when typing in the terminal.
271278
When non-nil, any character typed while the viewport is scrolled
@@ -1707,8 +1714,10 @@ buffer has not been manually renamed by the user."
17071714
"Set the cursor style based on terminal state.
17081715
STYLE is one of: 0=bar, 1=block, 2=underline, 3=hollow-block.
17091716
VISIBLE is t or nil.
1710-
Skipped when copy mode is active because copy mode manages its own cursor."
1711-
(unless ghostel--copy-mode-active
1717+
Skipped when copy mode is active because copy mode manages its own
1718+
cursor, or when `ghostel-ignore-cursor-change' is non-nil."
1719+
(unless (or ghostel--copy-mode-active
1720+
ghostel-ignore-cursor-change)
17121721
(setq cursor-type
17131722
(if visible
17141723
(pcase style

test/ghostel-test.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,22 @@ buffer and hand nil to the native module."
18811881
(should (null cursor-type)))) ; cursor hidden again
18821882
(kill-buffer buf))))
18831883

1884+
(ert-deftest ghostel-test-ignore-cursor-change ()
1885+
"Test that `ghostel-ignore-cursor-change' suppresses cursor style updates."
1886+
(let ((buf (generate-new-buffer " *ghostel-test-ignore-cursor*")))
1887+
(unwind-protect
1888+
(with-current-buffer buf
1889+
(ghostel-mode)
1890+
;; Default: cursor changes are applied
1891+
(let ((ghostel-ignore-cursor-change nil))
1892+
(ghostel--set-cursor-style 2 t)
1893+
(should (equal cursor-type '(hbar . 2))))
1894+
;; With ignore: cursor changes are suppressed
1895+
(let ((ghostel-ignore-cursor-change t))
1896+
(ghostel--set-cursor-style 1 t)
1897+
(should (equal cursor-type '(hbar . 2))))) ; unchanged
1898+
(kill-buffer buf))))
1899+
18841900
;; -----------------------------------------------------------------------
18851901
;; Test: copy-mode hl-line-mode management
18861902
;; -----------------------------------------------------------------------
@@ -2998,6 +3014,7 @@ while :; do sleep 0.1; done'\n")
29983014
ghostel-test-osc51-eval-catches-errors
29993015
ghostel-test-flush-pending-output-preserves-buffer
30003016
ghostel-test-copy-mode-cursor
3017+
ghostel-test-ignore-cursor-change
30013018
ghostel-test-copy-mode-hl-line
30023019
ghostel-test-project-buffer-name
30033020
ghostel-test-project-universal-arg

0 commit comments

Comments
 (0)