emacs-devel
[Top][All Lists]
Advanced

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

Re: Use of where-is-internal


From: Adam Porter
Subject: Re: Use of where-is-internal
Date: Sat, 01 Feb 2020 07:01:38 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Paul W. Rankin <address@hidden> writes:

> I'm considering of using where-is-internal in a program outside of the
> help library. I've used the following in my init for a while to cycle
> windows and so far the world has persisted unscathed:
>
>    (defun other-window-and-beyond (count &optional all-frames)
>      "Select another window in cyclic ordering of windows.
>    Successive pressing `o' calls `other-window'."
>      (interactive "p")
>      (let ((key-vector (where-is-internal this-command
>                                           overriding-local-map t)))
>        (set-transient-map
>         (let ((map (make-sparse-keymap)))
>           (define-key map (vector (aref key-vector (1- (length key-vector))))
>             'other-window)
>           map)
>         t)
>        (other-window count all-frames)))
>
> This function allows me to type C-x o o o o to cycle through all windows
> with the idea being to allow the command to work with any key binding
> rather than hardcoding anything.
>
> I maintain a minor mode called olivetti that also uses a transient key
> map to allow changing a buffer-local variable with C-c { { { ... The key
> binding is currently hardcoded within the transient key map but I'd like
> to allow user customisation.
>
> So, should I throw caution to the wind and reimplement the transient key
> map in olivetti using where-is-internal despite it being clearly marked
> as internal, or is there a better way?

This isn't what you asked, but here's a simple way to define commands
that repeat in the way you described:

https://github.com/alphapapa/defrepeater.el

In fact, other-window is what's used in the readme's example:

    (global-set-key (kbd "C-x o") (defrepeater #'other-window))

It's also useful with winner-undo.




reply via email to

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