Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs eshell. How to read content of command-line on pressing RET

My intention is to use bm.el Visible Bookmarks for each prompt as I press RET. I have managed to achieve this to a some degree.. Please comment on my code, below, if it is missing some important issue: eg. I have no idea if I need to handle the args beyond just passing them on to the default function.

When I press RET on an empty command line, I do not want to bookmark that line. How can I intercept the command line content 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)))
like image 752
Peter.O Avatar asked Aug 14 '12 05:08

Peter.O


1 Answers

Your code looks decent. If you read the code of eshell-send-input, you'll see how to get the current input.

Also read up on interactive arguments. "P" is required to pass the user-region on to 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))
like image 117
event_jr Avatar answered Sep 29 '22 07:09

event_jr