xuchunyang/eshell-git-prompt

Make Prompt Text Read Only

Closed this issue · 4 comments

gopar commented

As someone who presses the backspace as if my life depends on it, I usually find myself deleting the prompt.

It would be nice if out of the box the prompts were read only.

It's read-only here, the same as the default prompt, and I don't believe I did anything to make it happen.

gopar commented

Interesting, have no idea why mine is editeable then.

I found the issue via Google, as I don't (yet?) use this prompt, but I found the reason and would like to document it.
eshell-highlight-prompt has a default value of t and the description of "If non-nil, Eshell should highlight the prompt." It seems that this means it would be better to set nil here, if the prompt has custom highlighting, however, what the variable does in addition, is to add a read-only text property, that makes sure the prompt cannot be edited. The relevant code in Emacs v. 28.1 is

(defun eshell-emit-prompt ()
  "Emit a prompt if eshell is being used interactively."
  (when (boundp 'ansi-color-context-region)
    (setq ansi-color-context-region nil))
  (run-hooks 'eshell-before-prompt-hook)
  (if (not eshell-prompt-function)
      (set-marker eshell-last-output-end (point))
    (let ((prompt (funcall eshell-prompt-function)))
      (and eshell-highlight-prompt
	   (add-text-properties 0 (length prompt)
				'(read-only t
				  font-lock-face eshell-prompt
				  front-sticky (font-lock-face read-only)
				  rear-nonsticky (font-lock-face read-only))
				prompt))
      (eshell-interactive-print prompt)))
  (run-hooks 'eshell-after-prompt-hook))

@xuchunyang Perhaps you would like to add the read-only property to your prompt to prevent any future confusion

@xuchunyang Perhaps you would like to add the read-only property to your prompt to prevent any future confusion

Done. Thanks for your input.