GNU bug report logs - #6000
describe-text-sexp does not know window-width

Previous Next

Package: emacs;

Reported by: Lennart Borgman <lennart.borgman <at> gmail.com>

Date: Thu, 22 Apr 2010 12:16:01 UTC

Severity: minor

To reply to this bug, email your comments to 6000 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6000; Package emacs. (Thu, 22 Apr 2010 12:16:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Lennart Borgman <lennart.borgman <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 22 Apr 2010 12:16:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lennart Borgman <lennart.borgman <at> gmail.com>
To: Emacs Bugs <bug-gnu-emacs <at> gnu.org>
Subject: describe-text-sexp does not know window-width
Date: Thu, 22 Apr 2010 14:15:26 +0200
In describe-text-sexp there is a call to window-width. I believe this
gives unreliable results because the help-window might not be select
at that point always.

This shows up in the display of (what-cursor-position t) where the
sexp are sometimes unnecessary hidden behind "[Show]".

A possible good enough cure is to surround the call to window-width
with something like this

   (with-selected-window (or (get-buffer-window "*Help*") (selected-window))
     (window-width))





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6000; Package emacs. (Wed, 02 Jul 2014 00:19:02 GMT) Full text and rfc822 format available.

Message #8 received at 6000 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Lennart Borgman <lennart.borgman <at> gmail.com>
Cc: martin rudalics <rudalics <at> gmx.at>, 6000 <at> debbugs.gnu.org
Subject: Re: bug#6000: describe-text-sexp does not know window-width
Date: Wed, 02 Jul 2014 02:37:10 +0300
> In describe-text-sexp there is a call to window-width. I believe this
> gives unreliable results because the help-window might not be select
> at that point always.
>
> This shows up in the display of (what-cursor-position t) where the
> sexp are sometimes unnecessary hidden behind "[Show]".
>
> A possible good enough cure is to surround the call to window-width
> with something like this
>
>    (with-selected-window (or (get-buffer-window "*Help*") (selected-window))
>      (window-width))

Martin referred to this bug report from bug#17831, and I noticed
that instead of hard-coding the "*Help*" buffer name, better would be
to use (current-buffer) because the formatted buffer is current:

  (- (if (window-live-p (get-buffer-window (current-buffer) t))
         (with-selected-window (get-buffer-window (current-buffer) t)
           (window-width))
       (window-width))
     (current-column))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6000; Package emacs. (Thu, 03 Jun 2021 09:08:02 GMT) Full text and rfc822 format available.

Message #11 received at 6000 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Juri Linkov <juri <at> jurta.org>
Cc: martin rudalics <rudalics <at> gmx.at>, 6000 <at> debbugs.gnu.org,
 Lennart Borgman <lennart.borgman <at> gmail.com>
Subject: Re: bug#6000: describe-text-sexp does not know window-width
Date: Thu, 03 Jun 2021 11:07:39 +0200
Juri Linkov <juri <at> jurta.org> writes:

>>    (with-selected-window (or (get-buffer-window "*Help*") (selected-window))
>>      (window-width))
>
> Martin referred to this bug report from bug#17831, and I noticed
> that instead of hard-coding the "*Help*" buffer name, better would be
> to use (current-buffer) because the formatted buffer is current:
>
>   (- (if (window-live-p (get-buffer-window (current-buffer) t))
>          (with-selected-window (get-buffer-window (current-buffer) t)
>            (window-width))
>        (window-width))
>      (current-column))

This sounds like a good idea to me, but there wasn't a recipe to
reproduce whatever error this bug report was talking about, so I can't
test.

Does anybody have a test case that displays the problem (in case it's
still in place after all these years)?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 03 Jun 2021 09:08:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6000; Package emacs. (Thu, 03 Jun 2021 20:34:02 GMT) Full text and rfc822 format available.

Message #16 received at 6000 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: martin rudalics <rudalics <at> gmx.at>, 6000 <at> debbugs.gnu.org,
 Lennart Borgman <lennart.borgman <at> gmail.com>
Subject: Re: bug#6000: describe-text-sexp does not know window-width
Date: Thu, 03 Jun 2021 23:25:20 +0300
> This sounds like a good idea to me, but there wasn't a recipe to
> reproduce whatever error this bug report was talking about, so I can't
> test.
>
> Does anybody have a test case that displays the problem (in case it's
> still in place after all these years)?

Indeed a test case would be needed, but I have none.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6000; Package emacs. (Fri, 04 Jun 2021 09:19:02 GMT) Full text and rfc822 format available.

Message #19 received at 6000 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> jurta.org>, Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 6000 <at> debbugs.gnu.org, Lennart Borgman <lennart.borgman <at> gmail.com>
Subject: Re: bug#6000: describe-text-sexp does not know window-width
Date: Fri, 4 Jun 2021 11:18:35 +0200
>> This sounds like a good idea to me, but there wasn't a recipe to
>> reproduce whatever error this bug report was talking about, so I can't
>> test.
>>
>> Does anybody have a test case that displays the problem (in case it's
>> still in place after all these years)?
>
> Indeed a test case would be needed, but I have none.

There's no realistic test case for this.  You can do

(defun foo ()
  (interactive)
  (with-current-buffer (get-buffer-create "*foo*")
    (describe-text-sexp 'foooooooooooooooooooooooooooooooooo)))

and M-x foo in some window.  Dependent on the width of that window,
`describe-text-sexp' will decide whether to insert the expression in
*foo* or display a "Show" button instead.  When you eventually display
*foo* you will see the result.  I think a simple check like

    (if (and (not (string-match-p "\n" pp))
             (eq (window-buffer) (current-buffer))
             (<= (length pp) (- (window-width) (current-column))))
	(insert pp)

should work.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6000; Package emacs. (Fri, 04 Jun 2021 09:50:02 GMT) Full text and rfc822 format available.

Message #22 received at 6000 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Juri Linkov <juri <at> jurta.org>, Lennart Borgman <lennart.borgman <at> gmail.com>,
 6000 <at> debbugs.gnu.org
Subject: Re: bug#6000: describe-text-sexp does not know window-width
Date: Fri, 04 Jun 2021 11:49:20 +0200
martin rudalics <rudalics <at> gmx.at> writes:

> and M-x foo in some window.  Dependent on the width of that window,
> `describe-text-sexp' will decide whether to insert the expression in
> *foo* or display a "Show" button instead.  When you eventually display
> *foo* you will see the result.  I think a simple check like
>
>     (if (and (not (string-match-p "\n" pp))
>              (eq (window-buffer) (current-buffer))
>              (<= (length pp) (- (window-width) (current-column))))
> 	(insert pp)
>
> should work.

Hm...  this will always insert the [Show] button if the *foo* buffer
isn't the current buffer?  Is that what we want here?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6000; Package emacs. (Fri, 04 Jun 2021 12:45:01 GMT) Full text and rfc822 format available.

Message #25 received at 6000 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Juri Linkov <juri <at> jurta.org>, Lennart Borgman <lennart.borgman <at> gmail.com>,
 6000 <at> debbugs.gnu.org
Subject: Re: bug#6000: describe-text-sexp does not know window-width
Date: Fri, 4 Jun 2021 14:44:38 +0200
>> and M-x foo in some window.  Dependent on the width of that window,
>> `describe-text-sexp' will decide whether to insert the expression in
>> *foo* or display a "Show" button instead.  When you eventually display
>> *foo* you will see the result.  I think a simple check like
>>
>>      (if (and (not (string-match-p "\n" pp))
>>               (eq (window-buffer) (current-buffer))
>>               (<= (length pp) (- (window-width) (current-column))))
>> 	(insert pp)
>>
>> should work.
>
> Hm...  this will always insert the [Show] button if the *foo* buffer
> isn't the current buffer?  Is that what we want here?

`describe-text-sexp' always works on the current buffer

(defun describe-text-sexp (sexp)
  "Insert a short description of SEXP in the current buffer."

so the added line will avoid the [Show] button iff the selected window
doesn't show the current buffer which should be rare enough.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6000; Package emacs. (Sun, 06 Jun 2021 07:43:01 GMT) Full text and rfc822 format available.

Message #28 received at 6000 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> jurta.org>, Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 6000 <at> debbugs.gnu.org, Lennart Borgman <lennart.borgman <at> gmail.com>
Subject: Re: bug#6000: describe-text-sexp does not know window-width
Date: Sun, 6 Jun 2021 09:42:22 +0200
>> Does anybody have a test case that displays the problem (in case it's
>> still in place after all these years)?
>
> Indeed a test case would be needed, but I have none.

With emacs -Q evaluate

(progn
  (split-window nil -20 t)
  (put-text-property 1 2 'foo "This is a very long text property")
  (describe-char 1))

or

(progn
  (setq split-height-threshold nil)
  (setq split-width-threshold 20)
  (put-text-property 1 2 'foo "This is a very long text property")
  (describe-char 1))

Here these show a *Help* window on the right where not the entire text
property string is visible.  Depending on your settings it won't matter
much because the rest of that buffer is only partially visible too.

To show the inverse effect, again with emacs -Q, evaluate

(progn
  (split-window nil 20 t)
  (put-text-property 1 2 'foo t)
  (describe-char 1))

Here this shows *Help* in the window on the right with a line

  foo                  [Show]

where clicking on [Show] will show "t" in the window on the left.
This is embarrassingly silly.

Obviously, there are many more scenarios but most of them require to
customize `display-buffer-alist'.  Presumably, most people don't notice
the behavior - they just got used to it.

We could

- Do nothing: If, in the earlier scenarios, we'd insert a "Show" button
  instead of the text, clicking that button might again pop up a too
  narrow *Pp Eval Output* window and nothing has been gained.  As for
  the last scenario, we could tell users that they are on their own when
  they invoke `describe-char' in a too narrow window.

- Skip the `window-width' check in `describe-text-sexp' and maybe
  recommend using `temp-buffer-resize-mode' with a few tweaks like

(progn
  (temp-buffer-resize-mode)
  (setq temp-buffer-max-width 100)
  (setq fit-window-to-buffer-horizontally t)
  (setq split-height-threshold nil)
  (setq split-width-threshold 20)
  (put-text-property 1 2 'foo "This is a very long text property")
  (describe-char 1))

  But some people don't like `temp-buffer-resize-mode'.

- Calculate the maximum width of text in the buffer preceding the line
  where to insert the property with a function like

(defun max-column-in-frame ()
  "Return maximum column of current buffer in selected frame.
The return value is the longest column from the beginning of the
buffer to the line specified by the selected frame's height."
  (save-excursion
    (goto-char (point-min))
    (let ((width (frame-width))
	  (height (frame-height))
	  (line 0)
	  (max-column 0)
	  column)
      (while (and (< line height) (< (point) (point-max)))
	(setq column (move-to-column width))
	(when (> column max-column)
	  (setq max-column column))
	(forward-line 1)
	(setq line (1+ line)))
      max-column)))

and use that instead of `window-width' in `describe-text-sexp' as

    	     (<= (length pp) (- (max-column-in-frame) (current-column))))

This will delegate the problem to those who inserted text earlier into
that buffer.  If they were right, `describe-text-sexp' won't do anything
wrong.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6000; Package emacs. (Sun, 06 Jun 2021 09:05:01 GMT) Full text and rfc822 format available.

Message #31 received at 6000 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Juri Linkov <juri <at> jurta.org>, Lennart Borgman <lennart.borgman <at> gmail.com>,
 6000 <at> debbugs.gnu.org
Subject: Re: bug#6000: describe-text-sexp does not know window-width
Date: Sun, 06 Jun 2021 11:03:47 +0200
martin rudalics <rudalics <at> gmx.at> writes:

> `describe-text-sexp' always works on the current buffer
>
> (defun describe-text-sexp (sexp)
>   "Insert a short description of SEXP in the current buffer."
>
> so the added line will avoid the [Show] button iff the selected window
> doesn't show the current buffer which should be rare enough.

That's what I thought should happen, but your proposed change is the
patch below, which seems to do the opposite?  I.e., it'll always do the
[Show] button if the selected window doesn't show the current buffer...

diff --git a/lisp/descr-text.el b/lisp/descr-text.el
index 85017de5d5..f92f37d53d 100644
--- a/lisp/descr-text.el
+++ b/lisp/descr-text.el
@@ -51,7 +51,8 @@ describe-text-sexp
       (setq pp (substring pp 0 (1- (length pp)))))
 
     (if (and (not (string-match-p "\n" pp))
-    	     (<= (length pp) (- (window-width) (current-column))))
+             (eq (window-buffer) (current-buffer))
+             (<= (length pp) (- (window-width) (current-column))))
 	(insert pp)
       (insert-text-button
        "[Show]"


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Removed tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 04 Jul 2021 14:52:01 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 344 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.