unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* repeat the last single shell command
@ 2013-07-18  9:00 Luca Ferrari
       [not found] ` <CAKcmqqyD8e2bX99NHMKG0h+fdF=U66mBsJ-W=4ygtmvJgNGaGA@mail.gmail.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Luca Ferrari @ 2013-07-18  9:00 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,
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.

Thanks,
Luca



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
       [not found] ` <CAKcmqqyD8e2bX99NHMKG0h+fdF=U66mBsJ-W=4ygtmvJgNGaGA@mail.gmail.com>
@ 2013-07-18  9:55   ` Luca Ferrari
  2013-07-18 11:35     ` Suvayu Ali
  2013-07-18 12:42     ` Nicolas Richard
  0 siblings, 2 replies; 16+ messages in thread
From: Luca Ferrari @ 2013-07-18  9:55 UTC (permalink / raw)
  To: yi lu; +Cc: help-gnu-emacs

On Thu, Jul 18, 2013 at 11:31 AM, yi lu <zhiwudazhanjiangshi@gmail.com> wrote:
> Will "Up" arrow instead of "M-p" work?
>

Yes, it works, but that's pretty much the same of M-p. I'd like to
know if there's some shortcut, let's say like M-!!, to immediatly
repeat the last command. Otherwise I have to define a function.

Thanks,
Luca



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18  9:00 repeat the last single shell command Luca Ferrari
       [not found] ` <CAKcmqqyD8e2bX99NHMKG0h+fdF=U66mBsJ-W=4ygtmvJgNGaGA@mail.gmail.com>
@ 2013-07-18 10:33 ` Peter Dyballa
  2013-07-18 13:11 ` Tassilo Horn
  2 siblings, 0 replies; 16+ messages in thread
From: Peter Dyballa @ 2013-07-18 10:33 UTC (permalink / raw)
  To: Luca Ferrari; +Cc: help-gnu-emacs


Am 18.07.2013 um 11:00 schrieb Luca Ferrari:

> M-! M-p RET
> 
> but I guess there is a smarter way.

M-r ? On the prompt's line.

--
Mit friedvollen Grüßen

  Pete

Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we.
				– Georges W. Bush




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18  9:55   ` Luca Ferrari
@ 2013-07-18 11:35     ` Suvayu Ali
  2013-07-18 12:34       ` Luca Ferrari
  2013-07-18 12:42     ` Nicolas Richard
  1 sibling, 1 reply; 16+ messages in thread
From: Suvayu Ali @ 2013-07-18 11:35 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Jul 18, 2013 at 11:55:40AM +0200, Luca Ferrari wrote:
> On Thu, Jul 18, 2013 at 11:31 AM, yi lu <zhiwudazhanjiangshi@gmail.com> wrote:
> > Will "Up" arrow instead of "M-p" work?
> >
> 
> Yes, it works, but that's pretty much the same of M-p. I'd like to
> know if there's some shortcut, let's say like M-!!, to immediatly
> repeat the last command. Otherwise I have to define a function.

Maybe you are looking for repeat-complex-command, C-x ESC ESC?

-- 
Suvayu

Open source is the future. It sets us free.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18 11:35     ` Suvayu Ali
@ 2013-07-18 12:34       ` Luca Ferrari
  0 siblings, 0 replies; 16+ messages in thread
From: Luca Ferrari @ 2013-07-18 12:34 UTC (permalink / raw)
  To: Suvayu Ali; +Cc: help-gnu-emacs

On Thu, Jul 18, 2013 at 1:35 PM, Suvayu Ali <fatkasuvayu+linux@gmail.com> wrote:

> Maybe you are looking for repeat-complex-command, C-x ESC ESC?
>


Not the right one, since it will repeat the very last command, while I
want to repeat the last command within a shell (i.e., it would repeat
a kill buffer for instance, while I want to repeat only the last
single command).

But thanks for the idea.

Luca



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18  9:55   ` Luca Ferrari
  2013-07-18 11:35     ` Suvayu Ali
@ 2013-07-18 12:42     ` Nicolas Richard
  2013-07-18 13:24       ` Tassilo Horn
       [not found]       ` <mailman.1333.1374153910.12400.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 16+ messages in thread
From: Nicolas Richard @ 2013-07-18 12:42 UTC (permalink / raw)
  To: Luca Ferrari; +Cc: yi lu, help-gnu-emacs

Luca Ferrari <fluca1978@infinito.it> writes:

> On Thu, Jul 18, 2013 at 11:31 AM, yi lu <zhiwudazhanjiangshi@gmail.com> wrote:
>> Will "Up" arrow instead of "M-p" work?
>>
>
> Yes, it works, but that's pretty much the same of M-p. I'd like to
> know if there's some shortcut, let's say like M-!!, to immediatly
> repeat the last command. Otherwise I have to define a function.

I think M-! M-p RET is simple enough, but you can do this:

(defun yf/last-history-element-and-exit ()
  "Select the last history element."
  (interactive)
  (goto-history-element 1)
  (exit-minibuffer))
(define-key minibuffer-local-shell-command-map (kbd "!") 'yf/last-history-element-and-exit)

then M-! ! does what M-! M-p RET would do.

-- 
Nico.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18  9:00 repeat the last single shell command Luca Ferrari
       [not found] ` <CAKcmqqyD8e2bX99NHMKG0h+fdF=U66mBsJ-W=4ygtmvJgNGaGA@mail.gmail.com>
  2013-07-18 10:33 ` Peter Dyballa
@ 2013-07-18 13:11 ` Tassilo Horn
  2013-07-18 14:01   ` Luca Ferrari
  2013-07-18 14:12   ` Nicolas Richard
  2 siblings, 2 replies; 16+ messages in thread
From: Tassilo Horn @ 2013-07-18 13:11 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18 12:42     ` Nicolas Richard
@ 2013-07-18 13:24       ` Tassilo Horn
  2013-07-18 13:52         ` Nicolas Richard
       [not found]       ` <mailman.1333.1374153910.12400.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 16+ messages in thread
From: Tassilo Horn @ 2013-07-18 13:24 UTC (permalink / raw)
  To: help-gnu-emacs

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

>> Yes, it works, but that's pretty much the same of M-p. I'd like to
>> know if there's some shortcut, let's say like M-!!, to immediatly
>> repeat the last command. Otherwise I have to define a function.
>
> I think M-! M-p RET is simple enough, but you can do this:
>
> (defun yf/last-history-element-and-exit ()
>   "Select the last history element."
>   (interactive)
>   (goto-history-element 1)
>   (exit-minibuffer))
> (define-key minibuffer-local-shell-command-map (kbd "!") 'yf/last-history-element-and-exit)

Nice idea, but then you can't enter ! anymore in a shell command.

Here's an improved version that does handle ! (or whatever char you've
bound `yf/last-history-element-and-exit' to) only special if it's the
first char entered at the prompt.

--8<---------------cut here---------------start------------->8---
(defun yf/last-history-element-and-exit ()
  "Select the last history element."
  (interactive)
  (if (not (= (1+ (minibuffer-prompt-width)) (point)))
      (self-insert-command 1)
    (goto-history-element 1)
    (exit-minibuffer)))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18 13:24       ` Tassilo Horn
@ 2013-07-18 13:52         ` Nicolas Richard
  2013-07-18 14:18           ` Tassilo Horn
  0 siblings, 1 reply; 16+ messages in thread
From: Nicolas Richard @ 2013-07-18 13:52 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

Tassilo Horn <tsdh@gnu.org> writes:
> Here's an improved version that does handle ! (or whatever char you've
> bound `yf/last-history-element-and-exit' to) only special if it's the
> first char entered at the prompt.

Agreed. Perhaps one of (eq last-command 'shell-command) or (equal ""
(minibuffer-contents-no-properties)) might be used as a more specific
test too, e.g. :

--8<---------------cut here---------------start------------->8---
(defun yf/last-history-element-and-exit ()
  "Select the last history element."
  (interactive)
  (if (not (eq last-command 'shell-command))
      (self-insert-command 1)
    (goto-history-element 1)
    (exit-minibuffer)))
--8<---------------cut here---------------end--------------->8---

-- 
Nico.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18 13:11 ` Tassilo Horn
@ 2013-07-18 14:01   ` Luca Ferrari
  2013-07-18 14:12   ` Nicolas Richard
  1 sibling, 0 replies; 16+ messages in thread
From: Luca Ferrari @ 2013-07-18 14:01 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, Jul 18, 2013 at 3:11 PM, Tassilo Horn <tsdh@gnu.org> wrote:

> --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---
>


Thank you Tassilo and Nicolas, it is clear I have to customize myself
the behavior and you both provided me good advices.

Luca



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18 13:11 ` Tassilo Horn
  2013-07-18 14:01   ` Luca Ferrari
@ 2013-07-18 14:12   ` Nicolas Richard
  2013-07-18 14:22     ` Tassilo Horn
  1 sibling, 1 reply; 16+ messages in thread
From: Nicolas Richard @ 2013-07-18 14:12 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

Tassilo Horn <tsdh@gnu.org> writes:
> You can capture the last shell command using an advice, and have a
> command for repeating it, though.

Since a history is maintained accross invocations, there must be a
variable holding that, already. Its name is shell-command-history ; its
(car) holds the last command.

-- 
Nico.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18 13:52         ` Nicolas Richard
@ 2013-07-18 14:18           ` Tassilo Horn
  2013-07-18 16:08             ` Yuri Khan
       [not found]             ` <mailman.1343.1374163702.12400.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 16+ messages in thread
From: Tassilo Horn @ 2013-07-18 14:18 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: help-gnu-emacs

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

>> Here's an improved version that does handle ! (or whatever char
>> you've bound `yf/last-history-element-and-exit' to) only special if
>> it's the first char entered at the prompt.
>
> Agreed. Perhaps one of (eq last-command 'shell-command) or (equal ""
> (minibuffer-contents-no-properties)) might be used as a more specific
> test too, e.g. :

That ties it to `shell-command'.  You could bind the other version also
in `minibuffer-local-map', and then `M-: !' would reevaluate the last
lisp expression, `M-! !' would reexecute the last shell command, `M-x !'
would execute the last complex command, `C-x C-f !'  would find the last
found file, `C-x b !' would switch to the last switched to buffer, etc.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18 14:12   ` Nicolas Richard
@ 2013-07-18 14:22     ` Tassilo Horn
  0 siblings, 0 replies; 16+ messages in thread
From: Tassilo Horn @ 2013-07-18 14:22 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: help-gnu-emacs

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

> Tassilo Horn <tsdh@gnu.org> writes:
>> You can capture the last shell command using an advice, and have a
>> command for repeating it, though.
>
> Since a history is maintained accross invocations, there must be a
> variable holding that, already. Its name is shell-command-history ;
> its (car) holds the last command.

Indeed, so

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

is enough.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
       [not found]       ` <mailman.1333.1374153910.12400.help-gnu-emacs@gnu.org>
@ 2013-07-18 14:45         ` Barry Margolin
  0 siblings, 0 replies; 16+ messages in thread
From: Barry Margolin @ 2013-07-18 14:45 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.1333.1374153910.12400.help-gnu-emacs@gnu.org>,
 Tassilo Horn <tsdh@gnu.org> wrote:

> Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:
> 
> >> Yes, it works, but that's pretty much the same of M-p. I'd like to
> >> know if there's some shortcut, let's say like M-!!, to immediatly
> >> repeat the last command. Otherwise I have to define a function.
> >
> > I think M-! M-p RET is simple enough, but you can do this:
> >
> > (defun yf/last-history-element-and-exit ()
> >   "Select the last history element."
> >   (interactive)
> >   (goto-history-element 1)
> >   (exit-minibuffer))
> > (define-key minibuffer-local-shell-command-map (kbd "!") 
> > 'yf/last-history-element-and-exit)
> 
> Nice idea, but then you can't enter ! anymore in a shell command.

It's not too often that one needs that character in shell one-liners. 
But if you do, you can always type it with C-q !.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
  2013-07-18 14:18           ` Tassilo Horn
@ 2013-07-18 16:08             ` Yuri Khan
       [not found]             ` <mailman.1343.1374163702.12400.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 16+ messages in thread
From: Yuri Khan @ 2013-07-18 16:08 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: Nicolas Richard, help-gnu-emacs

On Thu, Jul 18, 2013 at 9:18 PM, Tassilo Horn <tsdh@gnu.org> wrote:

> That ties it to `shell-command'.  You could bind the other version also
> in `minibuffer-local-map', and then `M-: !' would reevaluate the last
> lisp expression, `M-! !' would reexecute the last shell command, `M-x !'
> would execute the last complex command, `C-x C-f !'  would find the last
> found file, `C-x b !' would switch to the last switched to buffer, etc.

That kind of misses the point, which for M-! ! is the fact that it’s
easy to type — because of finger position caching. (I’d maybe even go
as far as making it M-! M-!.) After M-: or M-x, ! is not in the cache.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: repeat the last single shell command
       [not found]             ` <mailman.1343.1374163702.12400.help-gnu-emacs@gnu.org>
@ 2013-07-18 19:07               ` Barry Margolin
  0 siblings, 0 replies; 16+ messages in thread
From: Barry Margolin @ 2013-07-18 19:07 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1402 bytes --]

In article <mailman.1343.1374163702.12400.help-gnu-emacs@gnu.org>,
 Yuri Khan <yuri.v.khan@gmail.com> wrote:

> On Thu, Jul 18, 2013 at 9:18 PM, Tassilo Horn <tsdh@gnu.org> wrote:
> 
> > That ties it to `shell-command'.  You could bind the other version also
> > in `minibuffer-local-map', and then `M-: !' would reevaluate the last
> > lisp expression, `M-! !' would reexecute the last shell command, `M-x !'
> > would execute the last complex command, `C-x C-f !'  would find the last
> > found file, `C-x b !' would switch to the last switched to buffer, etc.
> 
> That kind of misses the point, which for M-! ! is the fact that it’s
> easy to type — because of finger position caching. (I’d maybe even go
> as far as making it M-! M-!.) After M-: or M-x, ! is not in the cache.

M-! M-! makes quite a bit of sense, and avoids the problem someone else 
mentioned about making it hard to use ! in a command. I could see 
generalizing this: M-x M-x should recall the last extended command, M-: 
M-: should recall the last eval-expression, etc.

This assumes you're typing the commands with a real Meta key, since it's 
easier to keep your finger on it while you repeat the character. If 
you're using an ESC prefix to emulate Meta, ESC ! ! would be more 
intuitive, I think.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2013-07-18 19:07 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-18  9:00 repeat the last single shell command Luca Ferrari
     [not found] ` <CAKcmqqyD8e2bX99NHMKG0h+fdF=U66mBsJ-W=4ygtmvJgNGaGA@mail.gmail.com>
2013-07-18  9:55   ` Luca Ferrari
2013-07-18 11:35     ` Suvayu Ali
2013-07-18 12:34       ` Luca Ferrari
2013-07-18 12:42     ` Nicolas Richard
2013-07-18 13:24       ` Tassilo Horn
2013-07-18 13:52         ` Nicolas Richard
2013-07-18 14:18           ` Tassilo Horn
2013-07-18 16:08             ` Yuri Khan
     [not found]             ` <mailman.1343.1374163702.12400.help-gnu-emacs@gnu.org>
2013-07-18 19:07               ` Barry Margolin
     [not found]       ` <mailman.1333.1374153910.12400.help-gnu-emacs@gnu.org>
2013-07-18 14:45         ` Barry Margolin
2013-07-18 10:33 ` Peter Dyballa
2013-07-18 13:11 ` Tassilo Horn
2013-07-18 14:01   ` Luca Ferrari
2013-07-18 14:12   ` Nicolas Richard
2013-07-18 14:22     ` Tassilo Horn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).