Move to the input line automatically in line mode

* eat.el (eat-line-auto-move-to-input): New user option.
* eat.el (eat--line-move-to-input): New function.
* eat.el (eat--line-mode): Add/remove 'eat--line-move-to-input'
to 'pre-command-hook' locally.
* eat.texi (Line Mode): Document 'eat-line-auto-move-to-input'.
This commit is contained in:
Akib Azmain Turja 2023-09-23 12:36:54 +06:00
parent 44e9a6f5de
commit db6c64d029
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B
2 changed files with 54 additions and 30 deletions

77
eat.el
View file

@ -191,6 +191,40 @@ FUNCTION Call FUNCTION with the command and arguments (using
:group 'eat-ui
:group 'eat-eshell)
(defcustom eat-line-input-ring-size 1000
"Number of input history items to keep."
:type 'natnum
:group 'eat-ui)
(defcustom eat-line-auto-move-to-input t
"Non-nil means move to input line when inserting characters."
:type 'boolean
:group 'eat-ui)
(defcustom eat-line-move-point-for-matching-input 'after-input
"Controls where to place point after matching input.
\\<eat-line-mode-map>This influences the commands \
\\[eat-line-previous-matching-input-from-input] and \
\\[eat-line-next-matching-input-from-input].
If `after-input', point will be positioned after the input typed
by the user, but before the rest of the history entry that has
been inserted. If `end-of-line', point will be positioned at the
end of the current logical (not visual) line after insertion."
:type '(radio (const :tag "Stay after input" after-input)
(const :tag "Move to end of line" end-of-line))
:group 'eat-ui)
(defcustom eat-line-input-send-function #'eat-line-send-default
"Function to send the shell prompt input.
The function is called without any argument. The buffer is narrowed
to the input. The function may modify the input but mustn't modify
the buffer restrictions. It should call
`eat-line-send-default' to send the final output."
:type 'function
:group 'eat-ui)
(defcustom eat-semi-char-non-bound-keys
'([?\C-x] [?\C-\\] [?\C-q] [?\C-g] [?\C-h] [?\e ?\C-c] [?\C-u]
[?\e ?x] [?\e ?:] [?\e ?!] [?\e ?&]
@ -327,35 +361,6 @@ arguments, otherwise it's ignored."
:type 'boolean
:group 'eat-ui)
(defcustom eat-line-input-ring-size 1000
"Number of input history items to keep."
:type 'natnump
:group 'eat-ui)
(defcustom eat-line-move-point-for-matching-input 'after-input
"Controls where to place point after matching input.
\\<eat-line-mode-map>This influences the commands \
\\[eat-line-previous-matching-input-from-input] and \
\\[eat-line-next-matching-input-from-input].
If `after-input', point will be positioned after the input typed
by the user, but before the rest of the history entry that has
been inserted. If `end-of-line', point will be positioned at the
end of the current logical (not visual) line after insertion."
:type '(radio (const :tag "Stay after input" after-input)
(const :tag "Move to end of line" end-of-line))
:group 'eat-ui)
(defcustom eat-line-input-send-function #'eat-line-send-default
"Function to send the shell prompt input.
The function is called without any argument. The buffer is narrowed
to the input. The function may modify the input but mustn't modify
the buffer restrictions. It should call
`eat-line-send-default' to send the final output."
:type 'function
:group 'eat-ui)
(defcustom eat-enable-shell-prompt-annotation t
"Non-nil means annotate shell prompt with the status of command.
@ -5833,7 +5838,10 @@ MODE should one of:
(define-minor-mode eat--line-mode
"Minor mode for line mode."
:interactive nil
:keymap eat-line-mode-map)
:keymap eat-line-mode-map
(if eat--line-mode
(add-hook 'pre-command-hook #'eat--line-move-to-input nil t)
(remove-hook 'pre-command-hook #'eat--line-move-to-input t)))
(defun eat-line-mode ()
"Switch to line mode."
@ -5859,6 +5867,15 @@ MODE should one of:
(setq eat--inhibit-auto-line-mode t)
(setq eat--auto-line-mode-prev-mode nil)))
(defun eat--line-move-to-input ()
"Move point to the input line."
(when (and eat-line-auto-move-to-input
(< (point) (eat-term-end eat--terminal))
(eq #'self-insert-command this-command))
(deactivate-mark)
(push-mark)
(goto-char (point-max))))
(defun eat-line-send-default ()
"Send shell prompt input directly to the terminal."
(eat-term-send-string eat--terminal (buffer-string))

View file

@ -397,6 +397,13 @@ input a newline character without actually sending it, you can press
the terminal. @kbd{C-d} deletes the character after the point, or
sends EOF if the input is empty.
@vindex eat-line-auto-move-to-input
You can't modify the terminal in ``line mode'', you can write only in
the input line. Eat automatically moves the point to the input line
if you try to insert character in the terminal region. This behavior
can be disabled by customizing @code{eat-line-auto-move-to-input} to
@code{nil}.
@kindex C-c C-e @r{(``line mode'')}
@kindex C-c C-j @r{(``line mode'')}
@kindex C-c M-d @r{(``line mode'')}