help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: repeat the last single shell command


From: Tassilo Horn
Subject: Re: repeat the last single shell command
Date: Thu, 18 Jul 2013 15:11:30 +0200
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux)

Luca Ferrari <fluca1978@infinito.it> writes:

Hi Luca,

> this should be trivial, but I'm not able to find an easy and simple
> way of running again the last single shell command (M-!). I know I can
> use the shell ring to get back the last command, like M-P so that I
> have to:
>
> M-! M-p RET
>
> but I guess there is a smarter way. And I don't want to open a full
> shell, this is supposed to let me test quickly a shell script.

You can do `C-x M-:' which is:

,----[ C-h k C-x M-: ]
| C-x M-: runs the command repeat-complex-command, which is an interactive
| compiled Lisp function in `simple.el'.
| 
| It is bound to <again>, <redo>, C-x M-:, C-x M-ESC.
| 
| (repeat-complex-command ARG)
| 
| Edit and re-evaluate last complex command, or ARGth from last.
| A complex command is one which used the minibuffer.
| The command is placed in the minibuffer as a Lisp form for editing.
| The result is executed, repeating the command as changed.
| If the command has been changed or is not the most recent previous
| command it is added to the front of the command history.
| You can use the minibuffer history commands M-n and M-p
| to get different commands to edit and resubmit.
`----

Well, that's actually not really faster to type...

You can capture the last shell command using an advice, and have a
command for repeating it, though.

--8<---------------cut here---------------start------------->8---
(defvar th-last-shell-command)

(defadvice shell-command (before th-capture-shell-command
                                 (command &optional output-buffer error-buffer)
                                 activate)
  (setq th-last-shell-command (list command output-buffer error-buffer)))

(defun th-repeat-last-shell-command ()
  (interactive)
  (if th-last-shell-command
      (apply #'shell-command th-last-shell-command)
    (message "There's no last shell command!")))
--8<---------------cut here---------------end--------------->8---

Then you can bind `th-repeat-last-shell-command' to some key that's
convenient to you.

Bye,
Tassilo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]