bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#53910: [External] : bug#53910: 29.0.50; context-menu-mode breaks hel


From: Juri Linkov
Subject: bug#53910: [External] : bug#53910: 29.0.50; context-menu-mode breaks help in read-only buffers
Date: Sat, 12 Feb 2022 19:05:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>> > But 'select-window' only does
>> >
>> >   In addition, make WINDOW’s buffer current and set its
>> >   buffer’s value of ‘point’ to the value of WINDOW’s ‘window-point’.
>> >
>> > as advertised.  Or do you mean something else?
>>
>> Yep, this is what I meant.  I expected it no-op
>> in this case, but the documented behavior is fine.
>
> Maybe it would help to draw some more attention
> to this in the doc somehow?
>
> I don't find this obvious at all, even if the doc
> does specify it.  The function names don't give
> the impression that the behavior you speak of is
> part of the what the functions do.

I don't know, maybe the docstring could warn about this case too.

What worries me more is that the following idiom is not always safe:

  (with-selected-window (or window (selected-window))
    body
    ...)

because it might switch the buffer of the already selected window.
This idiom is used to prevent duplicating body in e.g.:

  (if window
      (with-selected-window window
        body
        ...)
    ;; Else call `body' in the selected window:
    body
    ...)

To avoid this problem, maybe the macro `with-selected-window'
could select the window only if it is non-nil, like this:

diff --git a/lisp/subr.el b/lisp/subr.el
index a78af09c40..2e528f5c8c 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4224,7 +4224,8 @@ with-selected-window
           (internal--before-with-selected-window ,window)))
      (save-current-buffer
        (unwind-protect
-           (progn (select-window (car save-selected-window--state) 'norecord)
+           (progn (when (car save-selected-window--state)
+                    (select-window (car save-selected-window--state) 
'norecord))
                  ,@body)
          (internal--after-with-selected-window save-selected-window--state)))))

Then this could be used even when 'window' is nil:

  (with-selected-window window
    body
    ...)





reply via email to

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