unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Arthur Miller <arthur.miller@live.com>
To: Juri Linkov <juri@linkov.net>
Cc: Eli Zaretskii <eliz@gnu.org>, manuel@ledu-giraud.fr, emacs-devel@gnu.org
Subject: Re: Control help- and Info-mode buffers from other buffers
Date: Sun, 04 Jun 2023 16:04:39 +0200	[thread overview]
Message-ID: <AM9PR09MB4977DA910A88E71B60BCA176964CA@AM9PR09MB4977.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <86a5xfzllr.fsf@mail.linkov.net> (Juri Linkov's message of "Sun,  04 Jun 2023 10:52:40 +0300")

Juri Linkov <juri@linkov.net> writes:

>> The interactive form has to be the very first form in a function body, which
>> makes it impossible to just wrap the entire function  into
>> with-selected-window. In this case I save selected-window in global var
>> (Info-jump) and select that window back at the very end of the function. It is
>> the same effect as if being wrapped into with-selected-window, but unfortunately
>> it uses a global variable. I don't know how to do it otherwise, if there is a
>> better way, pleae let me know, I would like to learn how to do it in a better
>> way if there is one.
>
> Another way is to add a new argument WINDOW to all commands.
> Then the interactive form could send the window value to the body.

Sorry I wasn't answered to your last few mails; I am just busy and would to get
this done and over. Yeah I would myself pretty much like to have that pedal to
modify all commands like a piano player; but I am really bad with it, I forgett the
pedal all the time when I play. But I would gladly start a business and sell
Emacs pedals if you are interested!

If you think of the bit of code I sent in as test-command; I would like to get
that *effect*, not necessary to really paste in all that code in each and every
command. Could it be possibly to create a function, that is called by each
commands and that arranges to execute the command in correct context
(other-window or user selected window)? I mean like you suggested, some sort of
parameter, keyword etc? If you think of your idea, which seemed more flexible to
me, but to achieve that effect, and if that would in some easy to user macro a
lá define-minor-mode or use-package style.

> But when an interactive selection of a window by the user is not involved,
> then you can just call the same function like 'other-window-for-scrolling'
> twice: in the interactive form and in the body it should return the same.
>
>> I have both in my WM and in Emacs that focus should follow mouse. Now what
>> happens is that, despite the function jumpiing to correct Emacs window on
>> another frame, due to cursor being in old frame, all input goes to the old
>> frame, so at least this particular function does not work with multiple
>> frames. According to the docs for select-window, both frame to which the window
>> belongs, and the buffer displaying are made selected/current, so it is probably
>> my WM spooking. I will try to test with some other WM and to boot into Windows
>> and test there, but on systems where focus follows the mouse, I guess there is
>> nothing to do? I suppose the same issue will happen with few other functions
>> that prompt user for the input via minibuffer. It works well when Info window is
>> on the same frame of course.
>
> 'other-frame' explicitly calls 'select-frame-set-input-focus' at the end.
I have just found a solution that will display menu in users selected frame, so
all good :-).

#+begin_src emacs-lisp
(interactive
   (let (;; If point is within a menu item, use that item as the default
         (default nil)
         (p (point))
         beg
         (case-fold-search t)
         (mouse-autoselect-window nil)
         (info-window (get-buffer-window "*info*" t)))
     (unless (window-live-p info-window)
       (user-error "There is no visible Info buffer."))
     (with-current-buffer (window-buffer info-window)
       (save-excursion
         (goto-char (point-min))
         (if (not (search-forward "\n* menu:" nil t))
             (user-error "No menu in this node"))
         (setq beg (point))
         (and (< (point) p)
              (save-excursion
                (goto-char p)
                (end-of-line)
                (if (re-search-backward (concat "\n\\* +\\("
                                                Info-menu-entry-name-re
                                                "\\):")
                                        beg t)
                    (setq default (match-string-no-properties 1))))))
       (let ((item nil))
         (while (null item)
           (setq item (let ((completion-ignore-case t)
                            (Info-complete-menu-buffer (current-buffer)))
                        (completing-read (format-prompt "Menu item" default)
                                         #'Info-complete-menu-item nil t nil nil
                                         default))))
         (list item current-prefix-arg))))
   Info-mode)
#+end_src

As I got the idea yesterday while writing about it; It is possible to just work
in info-buffer, there is no need to also switch to window. The above interacitve
form is from Info-menu; and now I get the prompt displayed in the selected frame
not one with the *info* buffer and I can remove the ugly global var I used for
"the communication" too :).

>> I do have another question too: what is a good strategy if there are multiple info
>> windows open? Prompt user to select with a completing read, or just leave as-is,
>> i.e. return the first info window?
>
> I think a good default would be to use the most recently used window.

Isn't that what would Emacs does per automatic, I mean what get-buffer or
get-buffer-window chooses?



  reply	other threads:[~2023-06-04 14:04 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  5:38 Control help- and Info-mode buffers from other buffers Arthur Miller
2023-05-30 12:54 ` Manuel Giraud via Emacs development discussions.
2023-05-30 13:31   ` Arthur Miller
2023-05-30 15:22     ` Manuel Giraud via Emacs development discussions.
2023-05-30 17:29     ` Juri Linkov
2023-05-31  5:55       ` Arthur Miller
2023-05-31 17:13         ` Juri Linkov
2023-06-01  3:16           ` Arthur Miller
2023-06-01  6:35             ` Juri Linkov
2023-06-01  7:05               ` Eli Zaretskii
2023-06-01  7:20                 ` Juri Linkov
2023-06-01  9:03                   ` Arthur Miller
2023-06-01  9:55                     ` Eli Zaretskii
2023-06-01 14:01                       ` Arthur Miller
2023-06-01  9:16                   ` Arthur Miller
2023-06-01  9:58                     ` Eli Zaretskii
2023-06-01 13:45                       ` Arthur Miller
2023-06-01 16:19                         ` Eli Zaretskii
2023-06-02  1:26                           ` Arthur Miller
2023-06-02  6:34                             ` Juri Linkov
2023-06-02 15:11                               ` Arthur Miller
2023-06-02 15:29                               ` Yuri Khan
2023-06-02 16:32                                 ` Juri Linkov
2023-06-04 14:09                                   ` Arthur Miller
2023-06-02  7:11                             ` Eli Zaretskii
2023-06-02 15:09                               ` Arthur Miller
2023-06-02 15:16                                 ` Eli Zaretskii
2023-06-03 13:53                                   ` Arthur Miller
2023-06-03 14:04                                     ` Eli Zaretskii
2023-06-03 15:06                                       ` Arthur Miller
2023-06-03 15:15                                         ` Eli Zaretskii
2023-06-04 14:19                                           ` Arthur Miller
2023-06-04 14:33                                             ` Eli Zaretskii
2023-06-04  7:52                                     ` Juri Linkov
2023-06-04 14:04                                       ` Arthur Miller [this message]
2023-06-04 16:50                                         ` Juri Linkov
2023-06-02 16:13                                 ` Juri Linkov
2023-06-03 13:49                                   ` Manuel Giraud via Emacs development discussions.
2023-06-04  7:44                                     ` Juri Linkov
2023-06-04  8:50                                       ` Eli Zaretskii
2023-06-04 13:40                                         ` [External] : " Drew Adams
2023-06-04 13:53                                           ` Arthur Miller
2023-06-04 14:00                                             ` Drew Adams
2023-06-04 14:20                                           ` Eli Zaretskii
2023-06-04 13:38                                       ` Manuel Giraud via Emacs development discussions.
2023-06-04  7:48                                   ` Juri Linkov
2023-06-01  8:50               ` Arthur Miller
2023-06-01 10:04                 ` Eli Zaretskii
2023-06-01 11:33                   ` Arthur Miller
2023-06-01 16:39                 ` Juri Linkov
2023-06-01 19:15                   ` Eli Zaretskii
2023-06-02  1:10                   ` Arthur Miller
2023-06-02  6:32                     ` Juri Linkov
2023-06-04 14:41                       ` Arthur Miller
2023-06-04 16:54                         ` Juri Linkov
2023-06-01  6:31           ` Juri Linkov
2023-05-30 16:15 ` Eli Zaretskii
2023-05-31  6:38   ` Arthur Miller
2023-05-30 18:04 ` [External] : " Drew Adams
2023-05-31  6:06   ` Arthur Miller
2023-05-31 13:00     ` Drew Adams
2023-05-31 13:27       ` Arthur Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM9PR09MB4977DA910A88E71B60BCA176964CA@AM9PR09MB4977.eurprd09.prod.outlook.com \
    --to=arthur.miller@live.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    --cc=manuel@ledu-giraud.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).