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:24:39 +0200
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux)

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




reply via email to

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