4

My Emacs version is 24.5.1.

Comint-mode protects the prompt by somehow defining the beginning of line to start directly after the prompt regex. This works for normal motion commands like move-beginning-of-line and even evil-mode motions. For example I can kill the current input by calling evil-change-whole-line and leave the prompt on the same line intact.

Eshell-mode isn't derived from comint mode, and the C-a shortcut is overriden to eshell-bol, which takes the prompt into consideration. So by using normal Emacs shortcuts most things work, but trying to use the standard commands for movement like move-beginning-of-line yields unexpected results. So by using evil-change-whole-line I kill the whole line, when I only wanted to kill the input.

How does comint-mode protect the prompt and is it possible to implement the same behavior in eshell-mode?

Things I have tried but didn't bear fruit:

  1. comint-line-beginning-position and comint-bolare defined in comint.el, but they aren't called when calling evil-change-whole-line or move-beginning-of-line.
  2. I noticed some references to the inhibit-field-text-motion variable in comint.el. But it is nil in at least shell-mode, which is comint-derived.
1

1 Answer 1

4

Dan's comment helped me on the way. Comint achieves the prompt protecting functionality with text-properties. I can add the needed properties in eshell by evaluating.

(add-text-properties (point-at-bol)
                     (point)
                     '(inhibit-line-move-field-capture t
                       rear-nonsticky t
                       field output
                       front-sticky (field inhibit-line-move-field-capture)))

I'm still unsure how this specific combination of properties result in the functionality. But I was satisfied and added these properties to my custom prompt with propertize

2
  • 1
    "how [these] ... specific properties result in the functionality" - field and the "sticky" properties are explained in the linked manual page. inhibit-line-move-field-capture is not documented, but appears to be checked by line-move-1 and line-move-finish in simple.el.
    – npostavs
    Commented Jul 1, 2015 at 20:53
  • Thanks @npostavs for pointing me to simple.el! At least line-move-1 is called for most of the evil-mode movement commands. It's a shame the inhibit-line-move-field-capture property isn't documented thoroughly, because those functions are quite complex. I hope I have the time to study this further so I can propose a patch for eshell. Commented Jul 2, 2015 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.