all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* `other-window-prefix' command, running anything in the other window
@ 2024-01-22  8:09 Psionic K
  2024-01-22  8:29 ` Emanuel Berg
  2024-01-22 21:06 ` Dmitry Gutov
  0 siblings, 2 replies; 6+ messages in thread
From: Psionic K @ 2024-01-22  8:09 UTC (permalink / raw)
  To: help-gnu-emacs

One of my TODO's is to compress all of the `*-other-window` commands
into a prefix command that will make `find-file` do what
`find-file-other-window` does for example.

I think I have an implementation that makes sense.  I'm not sure if it
makes the most sense.

The solution in my head is to create an `other-window-prefix` command.
The command needs to set a prefix state.  During the
`pre-command-hook`, a hook function would check if the prefix was set
and then:
1. If the command has "other-window" in the name, `user-error' because
the user's workflow is crap and they need to unbind that command and
never use it again
2. If the command has an "other-window" version, run that since it
might be smarter
3. Store the selected window (itself an impressive feat due to
minibuffers and dynamic `selected-window` results), create a window,
run the command, restore the selected window

1 & 2 are optional, but could mitigate silliness.

My biggest source of loathing before hacking this out is understanding
C-u, the command loop with minibuffer, and repeat maps, basically the
edge cases.  I think I can read my way through this, but insights
appreciated.  Commands that break when called in another window are
probably just bugs?

Repeat behavior should, like C-u, preserve the `other-window-prefix'
state.  I don't think `other-window-prefix` + `command` can or should
be repeated.  The user intended to stay where they are, and if they
did not, I'm pretty sure no key sequences can be saved.

Btw, pretty please `user-selected-window` and a hook?  Lisp programs
that need to know what the user is doing, not what an enclosing lisp
program is doing, need to know.  Modeline functions are an example.

Curious for better approaches to my `other-window-prefix'.  I may have
just completed copyright assignment and I think this belongs in Emacs.

IMO we should eliminate all instances of suffixed commands that would
be better prefixed by a modifying command, especially when the key
sequences for the longer version are equal to being invoked with a
prefix and the prefix is more versatile for commands that don't have
multiple versions.  Suffixed commands just clog up completions.

Thnkx <3



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

* Re: `other-window-prefix' command, running anything in the other window
  2024-01-22  8:09 `other-window-prefix' command, running anything in the other window Psionic K
@ 2024-01-22  8:29 ` Emanuel Berg
  2024-01-22 21:06 ` Dmitry Gutov
  1 sibling, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2024-01-22  8:29 UTC (permalink / raw)
  To: help-gnu-emacs

Psionic K wrote:

> One of my TODO's is to compress all of the `*-other-window`
> commands into a prefix command that will make `find-file` do
> what `find-file-other-window` does for example.

One of my favorite commands look like this, I have it bound to
M-o globally.

(defun other-window-or-split ()
  (interactive)
  (when (one-window-p)
    (split-window-below) )
  (other-window 1) )

Maybe it will be spared from your compression since it is in
fact a `other-window-*' command, not a `*-other-window' one?

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

Some more fun code:

(defmacro with-other-window (&rest body)
  `(with-selected-window (next-window)
     ,@body))

(defun apply-in-other-window (fn &rest args)
  (with-other-window
    (apply fn args) ))

https://dataswamp.org/~incal/emacs-init/window-other.el

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




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

* Re: `other-window-prefix' command, running anything in the other window
  2024-01-22  8:09 `other-window-prefix' command, running anything in the other window Psionic K
  2024-01-22  8:29 ` Emanuel Berg
@ 2024-01-22 21:06 ` Dmitry Gutov
  2024-01-22 21:50   ` Psionic K
  1 sibling, 1 reply; 6+ messages in thread
From: Dmitry Gutov @ 2024-01-22 21:06 UTC (permalink / raw)
  To: Psionic K, help-gnu-emacs

On 22/01/2024 10:09, Psionic K wrote:
> The solution in my head is to create an `other-window-prefix` command.

other-window-prefix is in Emacs since 28.1.



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

* Re: `other-window-prefix' command, running anything in the other window
  2024-01-22 21:06 ` Dmitry Gutov
@ 2024-01-22 21:50   ` Psionic K
  2024-01-22 22:21     ` Psionic K
  0 siblings, 1 reply; 6+ messages in thread
From: Psionic K @ 2024-01-22 21:50 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Psionic K, help-gnu-emacs

That's just hilarious.  I didn't pick that name until halfway through my
email.


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

* Re: `other-window-prefix' command, running anything in the other window
  2024-01-22 21:50   ` Psionic K
@ 2024-01-22 22:21     ` Psionic K
  2024-01-22 23:39       ` Dmitry Gutov
  0 siblings, 1 reply; 6+ messages in thread
From: Psionic K @ 2024-01-22 22:21 UTC (permalink / raw)
  To: Psionic K; +Cc: Dmitry Gutov, help-gnu-emacs

Oh yikes.  The `other-window-prefix' we have already is pretty limited.  No
go.  The behavior I want to achieve is: `other-window-prefix' +
`scroll-window' -> `scroll-other-window'

Second draft:

1. Switch window if there is another window.  If there is no other window,
run other-window-prefix to be sure we get a new one.
2. In post command hook, switch back to the previous window

I think it should work this way anyway, although not using a hook if
written  for Emacs.


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

* Re: `other-window-prefix' command, running anything in the other window
  2024-01-22 22:21     ` Psionic K
@ 2024-01-22 23:39       ` Dmitry Gutov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Gutov @ 2024-01-22 23:39 UTC (permalink / raw)
  To: Psionic K; +Cc: help-gnu-emacs

On 23/01/2024 00:21, Psionic K wrote:
> Oh yikes.  The `other-window-prefix' we have already is pretty limited.  
> No go.  The behavior I want to achieve is: `other-window-prefix' + 
> `scroll-window' -> `scroll-other-window'
> 
> Second draft:
> 
> 1. Switch window if there is another window.  If there is no other 
> window, run other-window-prefix to be sure we get a new one.
> 2. In post command hook, switch back to the previous window
> 
> I think it should work this way anyway, although not using a hook if 
> written  for Emacs.

You can make your version based on this one.

E.g. implement it on top of the existing function, or just look at the 
implementation and tweak as necessary.



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

end of thread, other threads:[~2024-01-22 23:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-22  8:09 `other-window-prefix' command, running anything in the other window Psionic K
2024-01-22  8:29 ` Emanuel Berg
2024-01-22 21:06 ` Dmitry Gutov
2024-01-22 21:50   ` Psionic K
2024-01-22 22:21     ` Psionic K
2024-01-22 23:39       ` Dmitry Gutov

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.