[ I'm using the latest emacs, and always emacsclient with the -nw option in a terminal ]

I have this workflow I want to "automate" with an emacs hotkey. I find myself doing this over a hundred times a day:

C-z # or M-x suspend-frame to minimize/bg emacs)
# now I'm at bash prompt
$ /usr/local/bin/t   # this runs some bash tests I wrote
$ sleep 5 # I stare at the test results for about 5 seconds
$ fg   # I resume my work in emacs
  • 2
    Why don't you use M-x shell or M-x eshell? – theldoria Jun 10 '17 at 13:55
  • 3
    And your command could also be run via M-x shell-command in the background, showing the result at end either in minibuffer or a new buffer, depending on output size. – theldoria Jun 10 '17 at 13:56
  • 1
    (suspend-emacs "/usr/local/bin/t && sleep 5 && fg")? – xuchunyang Jun 10 '17 at 15:54

As xuchunyang nearly pointed out, you can write those lines in your ~/emacs.d/init.el

(defun suspend-and-run ()
    (suspend-emacs "/usr/local/bin/t && sleep 5 && fg"))

(global-set-key (kbd "<f5>") 'suspend-and-run)

then when pressing F5 your stuff will be executed.

If you replace sleep 5 with read then you can look at the output until you press return.

This all works only with terminal-emacs, X11-emacs will refuse to do this.

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.