How can I tell emacs to run my own script (which can be elisp too or something in Perl, BASH or whatever), and use the next word after the mouse cursor as argument, or maybe using a group of marked words? The output would be in another buffer.

  • "use next word" how - as the STDIN? as the command line argument? while Perl and bash are similar enough, elisp is far to different, you probably want to clearly specify one or the other, or maybe just re-phrase the question as, e.g., "how do pass the current word or selection to an elisp function". – sds Mar 11 '14 at 20:58

Here's something that takes the current region and displays it in a new buffer with a timestamp:

(defun date-stamp ()
(format-time-string " [%a %b %e %H:%M:%S %Z %Y]"))

(defun extract-region (start end)
  (interactive "r")
  (setq sel (buffer-substring start end))
  (switch-to-buffer-other-window (generate-new-buffer "*Command Output*"))
  (insert (concat (date-stamp) "\n" sel "\n")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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