[Top][All Lists]

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

Re: Share Your 'other-window' Commands

From: Eduardo Ochs
Subject: Re: Share Your 'other-window' Commands
Date: Tue, 6 Sep 2022 23:07:48 -0300

Hi list, and maybe hi arthurno1,

I wrote the message below as a long answer to a discussion on Reddit.
The first link below points to the original question (by arthurno1).
The second link points my first answer, that was little more than a
link to this:

Then arthurno1 sent a big answer - the third link:

and I wrote the answer below, that I think that wasn't accepted by
Reddit... and I've heard so many things about Reddit becoming more and
more unreliable recently that I thought that it would be better to
post my answer here and post a link to this post there. So here's my


Hi Arthurno1!

Sorry if my comment was too brief - I thought something like "I will
expand it if someone finds it interesting". So let me expand it

Let me start with the multiwindow functions. I will try to answer your
"execute command in 'other-buffer'" after that.

The functions in
<> are my
favorite basic building blocks for writing multiwindow functions. They
work well for me because I have very quick ways to generate elisp
hyperlinks to files and other kinds of buffers... for example, this
the function that I use to create a 3-window layout with a directory
of directory of photos of whiteboards ("quadros") at the left, a
makefile at the top right, and another makefile at the bottom right:

  (defun q2 () (interactive)
    (find-3a '(find-fline "~/2022.2-quadros/")
             '(find-fline "~/2022.2-C2/Makefile")
             '(find-fline "~/2022.2-C3/Makefile")))

I was able to write it very quickly because I used my functions to
create "hyperlinks to here" to generate the three "find-fline" sexps.
So: I visited the directory "~/2022.2-quadros/" and generated an elisp
hyperlink to that, then visited the first makefile and generated
another elisp hyperlink to that, then did the same for the second
makefile - and I copied those three hyperlinks to my notes.

If I precede a sexp hyperlink - obs: this only works well for
one-liners - by a function name, like this,

  q0 (find-fline "~/2022.2-quadros/")

and I type M-J then that line is converted to this:

  (defun q0 () (interactive) (find-fline "~/2022.2-quadros/"))

so defining a function with a very short name that opens a file or a
directory in the current window is something that takes only a few
keystrokes to me (but WARNING! Some people have told me that they find
the mechanism for generating "hyperlinks to here" quite clumsy to
use... I've worked a lot to make it easier to use, but I'm only
halfway there at best =(... I'll try to watch some videos on
ace-window after finishing this answer to see if it has ideas that I
borrow/steal. Any recommendations?)

Anyway, let me go back. So: producing the (defun q0 ...) above is
"trivial" in terms of number of keystrokes and things to remember, at
least if the person doing that is me... producing the (defun q2 ...)
further above - the one that is four lines long - not so much, I had
to write most of the stuff around the find-flines by hand. That
function q2 is not as fragile as it seems - this tutorial here

start by explaining that

  (find-3a '(find-fline "~/2022.2-quadros/")
           '(find-fline "~/2022.2-C2/Makefile")
           '(find-fline "~/2022.2-C3/Makefile"))

is equivalent to

  (find-wset "13_o2_o_o"
             '(find-fline "~/2022.2-quadros/")
             '(find-fline "~/2022.2-C2/Makefile")
             '(find-fline "~/2022.2-C3/Makefile"))

and that that is sort of equivalent to this,

  (progn (eek "C-x 1 C-x 3")
         (find-fline "~/2022.2-quadros/")
         (eek "C-x o C-x 2")
         (find-fline "~/2022.2-C2/Makefile")
         (eek "C-x o")
         (find-fline "~/2022.2-C3/Makefile")
         (eek "C-x o"))

but actually the find-wset above is equivalent to this:

  (progn (find-wset-1)
         (find-fline "~/2022.2-quadros/")
         (find-fline "~/2022.2-C2/Makefile")
         (find-fline "~/2022.2-C3/Makefile")

where find-wset-1, ..., find-wset-o are defined as:

  (defun find-wset-1 () (delete-other-windows))
  (defun find-wset-2 () (split-window-vertically))
  (defun find-wset-3 () (split-window-horizontally))
  (defun find-wset-o () (other-window 1))

Now let me try to answer your "execute command in 'other-buffer'". I
am not sure if I understood it correctly, so I'll answer the first
interpretation of your question that came to my mind...

I have always found very annoying that many functions in Emacs opened
a second window, or even a second frame, following defaults and
heuristics that were scattered through many variables, and that I was
never able to understand very well... so one thing that I did - ages
ago! - was to create variants of those functions that would always
show their buffers in the current window. For example,

  (man "1 cat")

is badly behaved - it uses a second window or a new frame - but

  (find-man "1 cat")

uses the current window, and is "refinable", in the sense that I can
add extra arguments meaning "search for this string"... for example:

  (find-man "1 cat" "-s, --squeeze-blank")

I usually follow elisp hyperlinks like the one above with just M-e,
that shows the target buffer in the current window, but if I follow it
with M-2 M-e then this will work as:

  (find-2a nil '(find-man "1 cat" "-s, --squeeze-blank"))

that splits the frame in two windows, opens the manpage in the window
at the right, and stays at the window at the left, and if I follow it
with M-3 M-e this will work as:

  (find-2b nil '(find-man "1 cat" "-s, --squeeze-blank"))

that does the same, but goes to the window at the right...

So: I interpreted your "other buffer" as "other window", and I
explained how I execute commands both "in the same window" and "at the
window at the right"... btw, most of my functions that make
badly-behaved functions use "the same window" use this wrapper

Anyway, I am watching this video now,

  Switching Emacs windows with hydra and ace-window

by abo-abo himself, and it looks AMAZING!!! I will try to learn how to
use it - and I think that for most people ace-window is more
convenient, and makes more sense, than my tricks for creating
functions with very short names that open certain files...

Anyway 2: hey, I am just a weirdo who finds one-liners in elisp much
more fun to play with than keybindings, and who got addicted to a
certain way of building new one-liners from old ones, and who hangs
out on IRC a lot!... If there are any parts of eev that look
interesting to you but that you don't know how to use conveniently -
i.e.: their workflows are a mystery - please get in touch, let's see
if we can solve that by chatting on #emacs! And until that happens
I'll try to see if I can learn ace-window...

Btw, the four defuns in your original question look very good to me! I
thought a bit on how I would write them using find-wset, and I think
that the "right way" to do that in (my) eev style would be by defining
a function find-wset-A... like this:

  (defun find-wset-A () (if (one-window-p) (split-window-horizontally)))
  (defun find-2A (b) (find-wset "Ao_O" b))
  ;; Test: (find-2A '(eek "<down>"))

Would you like me to try to translate your four defuns into that

  Best =),
    Eduardo Ochs

reply via email to

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