From a79ba99751c87caac5f5ea39691b955428b45a0b Mon Sep 17 00:00:00 2001 From: Yiming Chen Date: Mon, 25 May 2026 16:53:40 -0700 Subject: [PATCH] fix(ghostel): support ghostel >= 0.22.0 which replaced ghostel--copy-mode-active with ghostel--input-mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ghostel commit bdd2b85 ("Add eat-style input modes") removed `ghostel--copy-mode-active` and replaced it with `ghostel--input-mode`. The three ghostel backend methods that referenced the old variable caused a `void-variable` error when called against new ghostel. This error was silently swallowed by Emacs's C-level window resize callback, causing `claude-code--adjust-window-size-advice` to return nil and suppress SIGWINCH. As a result, Claude Code's PTY was never notified of the correct terminal width and stayed at the 80-column fallback set at spawn time (the buffer is not yet displayed in any window when `ghostel-exec` is called, so it falls back to 80×24). Fix: extract `claude-code--ghostel-in-copy-mode-p` helper that checks for `ghostel--input-mode` first (>= 0.22.0: `(memq ghostel--input-mode '(copy emacs))`) and falls back to `(bound-and-true-p ghostel--copy-mode-active)` for older ghostel. Also handle `ghostel-copy-mode-exit` → `ghostel-readonly-exit` rename with an `fboundp` guard so both old and new ghostel work. Co-Authored-By: Claude Sonnet 4.6 --- claude-code.el | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/claude-code.el b/claude-code.el index 7f5918e..8bd3005 100644 --- a/claude-code.el +++ b/claude-code.el @@ -969,14 +969,16 @@ _BACKEND is the terminal backend type (should be \\='vterm)." ;; Declare external variables and functions from ghostel package (defvar ghostel--process) -(defvar ghostel--copy-mode-active) +(defvar ghostel--copy-mode-active) ; removed in ghostel >= 0.22.0, kept for compat +(defvar ghostel--input-mode) ; added in ghostel >= 0.22.0 (defvar ghostel-kill-buffer-on-exit) (defvar ghostel-set-title-function) (declare-function ghostel-exec "ghostel") (declare-function ghostel-send-string "ghostel") (declare-function ghostel-send-key "ghostel") (declare-function ghostel-copy-mode "ghostel") -(declare-function ghostel-copy-mode-exit "ghostel") +(declare-function ghostel-copy-mode-exit "ghostel") ; removed in ghostel >= 0.22.0 +(declare-function ghostel-readonly-exit "ghostel") ; added in ghostel >= 0.22.0 (declare-function ghostel--window-adjust-process-window-size "ghostel") ;; Helper to ensure ghostel is loaded @@ -1016,12 +1018,20 @@ BUFFER is the terminal buffer containing the process to kill." (kill-process ghostel--process))) (kill-buffer buffer))) +(defun claude-code--ghostel-in-copy-mode-p () + "Return non-nil if ghostel terminal is in copy/read-only mode. +Supports both ghostel >= 0.22.0 (ghostel--input-mode) and older versions +(ghostel--copy-mode-active)." + (if (boundp 'ghostel--input-mode) + (memq ghostel--input-mode '(copy emacs)) + (bound-and-true-p ghostel--copy-mode-active))) + (cl-defmethod claude-code--term-read-only-mode ((_backend (eql ghostel))) "Switch ghostel terminal to read-only mode. _BACKEND is the terminal backend type (should be \\='ghostel)." (claude-code--ensure-ghostel) - (unless ghostel--copy-mode-active + (unless (claude-code--ghostel-in-copy-mode-p) (ghostel-copy-mode))) (cl-defmethod claude-code--term-interactive-mode ((_backend (eql ghostel))) @@ -1029,16 +1039,18 @@ _BACKEND is the terminal backend type (should be \\='ghostel)." _BACKEND is the terminal backend type (should be \\='ghostel)." (claude-code--ensure-ghostel) - (when ghostel--copy-mode-active - (ghostel-copy-mode-exit) - ;; Re-setup keymap since ghostel-copy-mode-exit restores the saved keymap + (when (claude-code--ghostel-in-copy-mode-p) + (if (fboundp 'ghostel-readonly-exit) + (ghostel-readonly-exit) ; ghostel >= 0.22.0 + (ghostel-copy-mode-exit)) ; ghostel < 0.22.0 + ;; Re-setup keymap since exit restores the saved keymap (claude-code--term-setup-keymap 'ghostel))) (cl-defmethod claude-code--term-in-read-only-p ((_backend (eql ghostel))) "Check if ghostel terminal is in read-only mode. _BACKEND is the terminal backend type (should be \\='ghostel)." - ghostel--copy-mode-active) + (claude-code--ghostel-in-copy-mode-p)) (defun claude-code--ghostel-bell-handler () "Handle bell from ghostel terminal by triggering Claude notification."