[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [External] : Prefix for command to save it as a Lisp expression
From: |
Drew Adams |
Subject: |
RE: [External] : Prefix for command to save it as a Lisp expression |
Date: |
Sun, 20 Feb 2022 03:18:47 +0000 |
> Is there any prefix I can type before entering a command which will add
> that command as a Lisp expression to my kill ring?
>
> For example, [prefix] C-n would add "(next-line)" to my kill-ring.
>
> The specific use case I have in mind is [prefix] M-x global-set-key,
> where after I finish running the global-set-key I'd have a Lisp
> expression I can put into my init.el.
>
> Currently, I can do this after the fact by looking at
> list-command-history and kill things out of that. But it would be cool
> if I could type some prefix and just automatically have the command be
> added to my kill ring.
>
> Alternatively, maybe there's a way to yank things directly from
> command-history? Then I could just do that after the fact, rather than
> using a prefix ahead of time, which might be even nicer.
This doesn't answer your question directly.
Hopefully someone else will.
___
FWIW, I use `C-x ESC ESC' (aka `C-x M-ESC'),
which is bound to command `repeat-command'.
That doesn't save the Lisp for the `M-x'
command you _will_ enter. It shows you the
Lisp for the command that you last entered.
It shows you, in the minibuffer - to edit
and optionally enter, the Lisp sexp of the
last command invoked with `M-x'.
M-x global-set-key RET
^L ; I hit `C-l'
forward-sexp RET ; I enter forward-sexp
C-x ESC ESC
;; I'm prompted in the minibuffer:
Redo: (global-set-key "^L" 'forward-sexp)
You can grab that text and do anything you
want with it (`M-w' puts it in the kill-ring).
___
(I've written "^L" here (3 chars), but in
reality it's a string with a single char,
Control-L.)