Emacs eshell. How to read the contents of the command line when pressing RET

I intend to use bm.el Visible Bookmarks for each prompt when I press RET. I managed to some extent. Please comment on my code below if there is no important problem: for example. I have no idea if I need to process the arguments, except that they pass them to the function by default.

When I press RET on an empty command line, I do not want to add this line. How to intercept command line contents before passing contol on to the default function eshell-send-input?

(defun eshell-send-input-zAp (&optional use-region queue-p no-newline)
  "eshell-send-input, customized to add bm-bookmark to prompt line"
 (interactive)
  (bm-bookmark-add)
  (eshell-send-input use-region queue-p no-newline))

(add-hook 'eshell-mode-hook
          #'(lambda ()
              (define-key eshell-mode-map
                [return]
                'eshell-send-input-zAp)))
+5
source share
3 answers

. eshell-send-input, , .

interactive . "P" eshell-send-input.

(defun eshell-send-input-zAp (&optional use-region queue-p no-newline)
  "eshell-send-input, customized to add bm-bookmark to prompt line"
  (interactive "*P")
  (unless (string-equal (eshell-get-old-input use-region) "")
    (bm-bookmark-add))
  (eshell-send-input use-region queue-p no-newline))
+4

esh-mode eshell-last-output-end, , . , , ​​ , - (buffer-substring eshell-last-output-end (point-max)), .

EDIT: eshel-send-input:

" , Eshell . eshell-last-output-end, .. `eshell-get-old-input ' , .

USE-REGION , ( ) .

QUEUE-P , , . , .

NO-NEWLINE , ".

. eshel-send-input, , .

event_jr, , ... , .

+1

(Answering my own question) ... I realized that eshellat the core is just an emacs buffer. So, keeping that in mind, I came up with this method that works, but maybe do better. Perhaps there is something about this that I still do not suspect, so I am still open to suggestions.

(defun eshell-send-input-zAp (&optional use-region queue-p no-newline)
  "A customized `eshell-send-input`, to add bm-bookmark to prompt line" 
  (interactive)
  (let ((line (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
    (if (string-match eshell-prompt-regexp line)
        (if (> (length (substring line (match-end 0))) 0)
            (bm-bookmark-add))))
  (eshell-send-input use-region queue-p no-newline))
0
source

All Articles