Skip to content

Stop evil-ghostel insert entry at the input start - #789

Merged
dakra merged 2 commits into
mainfrom
fix/evil-insert-prompt-clamp
Nov 5, 2026
Merged

dakra merged 2 commits into
mainfrom
fix/evil-insert-prompt-clamp

Conversation

@dakra

@dakra dakra commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Summary

With evil-ghostel-mode in semi-char mode, i or a pressed with point inside the prompt on the cursor's row left the caret in the prompt until the next keystroke. Closes #788.

evil-ghostel-goto-input-position clamped a same-row target on the right only:

 evil-ghostel-goto-input-position (pos)
   if pos is on the cursor's row
     if pos is right of the cursor
       pos = min(pos, input end)          # never walk into an autosuggestion
+    else if a prompt is detected on the row, ending at or before the cursor
+      pos = max(pos, input start)        # the shell cannot move into the prompt
   send arrow keys for the distance, then move point to pos

One place covers i, a, the insert-state entry hook and paste. The ignored left arrows are no longer sent, so bash stops ringing the bell.

The clamp exposed a weakness in the prompt regexp fallback, fixed in the second commit:

 ghostel--regex-prompt-end (pos)
+  if the row begins after a soft-wrap newline
+    return nil                           # a wrapped row never starts with a prompt
   match ghostel-prompt-regexp at the row start

Rows after a hard newline still use the regexp, which is what detects continuation prompts such as > . This also corrects C-a in copy and Emacs mode and evil-ghostel's ^, I and operators on wrapped rows.

Evidence

  • Before: live zsh, bash and fish, 0 then i at the prompt: point stays inside the prompt, still there after one idle second. One i at an empty prompt sends 46 left arrows in bash and rings 46 bells.
    After: point lands on the input start and no arrow is sent.
  • Before: live zsh, command wrapped onto a second row reading aaa… $HOME bar, 0 i on that row with the clamp alone: column 19, after the $.
    After: column 0, and the typed character lands there.
  • ERT: five new tests. Each fails without its fix and passes with it.
    evil-ghostel-test-insert-in-prompt-lands-at-input-start
    evil-ghostel-test-goto-input-position-stops-at-input-start
    evil-ghostel-test-goto-input-position-stops-at-osc133-prompt
    evil-ghostel-test-goto-input-position-unclamped-without-prompt
    ghostel-test-regex-prompt-end-skips-soft-wrapped-row
    
  • elate matrix: new groups 0 i, 0 a, 0 i wrap in shells.json (bash, zsh, fish, nu), 0 i in python3.json, wrap-C-a in readonly-ghostel.json. The two wrap groups fail with the old helper swapped in. All 17 matrix runs exit 0 with only the documented expected failures.
  • Gate: make -j8 all exits 0, 1516 tests, 0 unexpected.

Merge Danger

Door: two-way

Two small elisp changes, no data or protocol change; reverting the commits restores the old behaviour.

Blast Radius: cursor placement

  • Leftward cursor moves in evil-ghostel now stop at a detected prompt. A row where the regexp fallback matches ordinary text as a prompt clamps there too. That is limited to hard-newline continuation rows whose own prompt has no $, #, % or > while the typed text does; operators, I and ^ already behaved that way on those rows.
  • ghostel--regex-prompt-end is shared by ghostel-input-start-point, ghostel-beginning-of-input-or-line and consult-ghostel; it now returns nil on wrapped rows for all of them.

dakra added 2 commits November 5, 2026 15:08
evil-ghostel-goto-input-position clamped a same-row target at the input
end only.  With point inside the prompt on the cursor's row, e.g. after
0, i and a sent left arrows the shell ignores at its start of line and
then moved point to the target, so the caret stayed inside the prompt
until the next keystroke redrew it.  The arrows went out twice, from the
command and from the insert-state entry hook, and bash rang the bell for
each one.

Clamp a leftward same-row target to the input start after a detected
prompt.  A regexp-fallback match that ends past the cursor is ignored,
so a prompt-less row keeps its unclamped moves.

The elate shell matrix gains 0 i and 0 a groups, and the python3 one
0 i for the regexp-detected prompt.

Closes #788.
ghostel--regex-prompt-end matched ghostel-prompt-regexp on any row
without ghostel-prompt text, including the rows a long input line
soft-wraps onto.  Text up to a $, #, % or > on such a row was taken for
a prompt, so C-a in copy and Emacs mode and evil-ghostel's ^, I and
operators stopped after it.  With the leftward clamp in
evil-ghostel-goto-input-position, i, a and paste stopped there too.

Return nil when the row begins after a ghostel-wrap newline: a wrapped
row never starts with a prompt.  Rows after a hard newline still use the
regexp, which is what detects continuation prompts.

The elate matrices gain a wrapped-row group each: 0 i wrap in the shell
matrix and wrap-C-a in the plain read-only suite.
@dakra
dakra merged commit 7bf0ad4 into main Nov 5, 2026
33 checks passed
@dakra
dakra deleted the fix/evil-insert-prompt-clamp branch November 5, 2026 15:14

This branch was previously deployed

1 inactive deployment
github-pages — 7bf0ad4c Deployed Nov 5, 2026 by dakra via deploy #249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

evil-ghostel: i on the current prompt row can enter insert before the input boundary

1 participant