all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Use of where-is-internal
@ 2020-01-25  6:18 Paul W. Rankin
  2020-01-25 16:02 ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Paul W. Rankin @ 2020-01-25  6:18 UTC (permalink / raw)
  To: help-gnu-emacs

Hello Emacs major modes,

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

As the docstring implies, this function allows me to type C-x o o o o to
keep on truckin through all frame windows (and only trips me up with I
want to then immediately type "o"), 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, or is there a better way?

Thanks,

--
Paul W. Rankin
https://www.paulwrankin.com



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

* Re: Use of where-is-internal
  2020-01-25  6:18 Use of where-is-internal Paul W. Rankin
@ 2020-01-25 16:02 ` Stefan Monnier
  2020-02-01 14:58   ` Paul W. Rankin
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2020-01-25 16:02 UTC (permalink / raw)
  To: help-gnu-emacs

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

I think you're looking for `this-single-command-keys`.
The difference is not just the avoidance of "-internal" but also the
behavior in case the command is bound to several keys, since you
probably want to support repeating the same last key that was used to
run the command rather than repeating "the last key of its first
keybinding".


        Stefan




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

* Use of where-is-internal
@ 2020-02-01  6:53 Paul W. Rankin
  2020-02-01 13:01 ` Adam Porter
  2020-02-01 14:24 ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: Paul W. Rankin @ 2020-02-01  6:53 UTC (permalink / raw)
  To: emacs-devel

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?

Thanks,

--
Paul W. Rankin
https://www.paulwrankin.com



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

* Re: Use of where-is-internal
  2020-02-01  6:53 Paul W. Rankin
@ 2020-02-01 13:01 ` Adam Porter
  2020-02-01 14:24 ` Stefan Monnier
  1 sibling, 0 replies; 7+ messages in thread
From: Adam Porter @ 2020-02-01 13:01 UTC (permalink / raw)
  To: emacs-devel

Paul W. Rankin <hello@paulwrankin.com> 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.




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

* Re: Use of where-is-internal
  2020-02-01  6:53 Paul W. Rankin
  2020-02-01 13:01 ` Adam Porter
@ 2020-02-01 14:24 ` Stefan Monnier
  2020-02-01 15:27   ` Noam Postavsky
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2020-02-01 14:24 UTC (permalink / raw)
  To: Paul W. Rankin; +Cc: emacs-devel

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

I have a feeling of "déjà vu"!

The answer involved `this-single-command-keys`.


        Stefan




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

* Re: Use of where-is-internal
  2020-01-25 16:02 ` Stefan Monnier
@ 2020-02-01 14:58   ` Paul W. Rankin
  0 siblings, 0 replies; 7+ messages in thread
From: Paul W. Rankin @ 2020-02-01 14:58 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs


> On 26 Jan 2020, at 2:02 am, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> 
>>    (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)))
> 
> I think you're looking for `this-single-command-keys`.
> The difference is not just the avoidance of "-internal" but also the
> behavior in case the command is bound to several keys, since you
> probably want to support repeating the same last key that was used to
> run the command rather than repeating "the last key of its first
> keybinding".

Thanks for both replies! I didn't receive this one as I'm not subscribed, but should have checked the archives first.


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

* Re: Use of where-is-internal
  2020-02-01 14:24 ` Stefan Monnier
@ 2020-02-01 15:27   ` Noam Postavsky
  0 siblings, 0 replies; 7+ messages in thread
From: Noam Postavsky @ 2020-02-01 15:27 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Paul W. Rankin, Emacs developers

On Sat, 1 Feb 2020 at 09:25, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
> > 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)))
>
> I have a feeling of "déjà vu"!

Yeah, https://lists.gnu.org/archive/html/help-gnu-emacs/2020-01/msg00176.html



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

end of thread, other threads:[~2020-02-01 15:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-25  6:18 Use of where-is-internal Paul W. Rankin
2020-01-25 16:02 ` Stefan Monnier
2020-02-01 14:58   ` Paul W. Rankin
  -- strict thread matches above, loose matches on Subject: below --
2020-02-01  6:53 Paul W. Rankin
2020-02-01 13:01 ` Adam Porter
2020-02-01 14:24 ` Stefan Monnier
2020-02-01 15:27   ` Noam Postavsky

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.