all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Prefix for command to save it as a Lisp expression
@ 2022-02-19 23:45 Spencer Baugh
  2022-02-20  2:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Spencer Baugh @ 2022-02-19 23:45 UTC (permalink / raw)
  To: help-gnu-emacs


Hi,

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.

Thanks!



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

* Re: Prefix for command to save it as a Lisp expression
  2022-02-19 23:45 Prefix for command to save it as a Lisp expression Spencer Baugh
@ 2022-02-20  2:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2022-02-20  3:18 ` [External] : " Drew Adams
  2022-02-20  4:00 ` Eduardo Ochs
  2 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2022-02-20  2:56 UTC (permalink / raw)
  To: help-gnu-emacs

Spencer Baugh wrote:

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

I do something similar in:

  https://dataswamp.org/~incal/emacs-init/wrap-search.el

-- 
underground experts united
https://dataswamp.org/~incal




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

* RE: [External] : Prefix for command to save it as a Lisp expression
  2022-02-19 23:45 Prefix for command to save it as a Lisp expression Spencer Baugh
  2022-02-20  2:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2022-02-20  3:18 ` Drew Adams
  2022-02-20  4:00 ` Eduardo Ochs
  2 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2022-02-20  3:18 UTC (permalink / raw)
  To: Spencer Baugh, help-gnu-emacs@gnu.org

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



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

* Re: Prefix for command to save it as a Lisp expression
  2022-02-19 23:45 Prefix for command to save it as a Lisp expression Spencer Baugh
  2022-02-20  2:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2022-02-20  3:18 ` [External] : " Drew Adams
@ 2022-02-20  4:00 ` Eduardo Ochs
  2 siblings, 0 replies; 4+ messages in thread
From: Eduardo Ochs @ 2022-02-20  4:00 UTC (permalink / raw)
  To: Spencer Baugh; +Cc: help-gnu-emacs

On Sat, 19 Feb 2022 at 23:15, Spencer Baugh <sbaugh@catern.com> wrote:
> Hi,
>
> 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.
>
> Thanks!


Hi Spencer,

I tried to implement your idea but it seems to be a bit tricky...
there are lots of occurrences of `command-history' and `add-to-history'
in the Emacs sources. But if you are interested in something that will
be ready in 5 minutes and that does a part of what you want you can
try this:

  1) install eev with M-x list-packages,

  2) run these two sexps:

       (require 'eev-load)
       (defun ch () (interactive) (find-eppp command-history))

The first sexp loads all modules of eev without turning eev-mode on,
and the second one defines `M-x ch' to be a function that
pretty-prints the value of the variable `command-history' and displays
that in an _editable_ temporary buffer. I played a bit with both `M-x
command-history' and `M-x ch' here and I found `M-x ch' much more
convenient, because I can edit some individual lines, kill other ones,
and run `M-x reverse-region' in a range of lines...

For more info on what eev-mode does, see:

  http://angg.twu.net/eev-intros/find-eev-quick-intro.html#1

For more info on `find-eppp', see:

  http://angg.twu.net/eev-current/eev-blinks.el.html#find-epp

Cheers,
  Eduardo Ochs
  http://angg.twu.net/#eev



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

end of thread, other threads:[~2022-02-20  4:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-19 23:45 Prefix for command to save it as a Lisp expression Spencer Baugh
2022-02-20  2:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-02-20  3:18 ` [External] : " Drew Adams
2022-02-20  4:00 ` Eduardo Ochs

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.