unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: 64986@debbugs.gnu.org
Subject: bug#64986: 30.0.50; window-text-pixel-size sometimes returns 0 width when called from temporary buffer
Date: Tue, 01 Aug 2023 07:47:32 +0000	[thread overview]
Message-ID: <87o7jrgq5n.fsf@localhost> (raw)

Hi,

I stumbled upon apparently unexpected return value of
`window-text-pixel-size'. There is no easy reproducer involving emacs
-Q, but I can reliably reproduce it with certain variant of
`org-string-width' function. I am not 100% sure if it is a real Emacs
bug or if it is my misunderstanding of `window-text-pixel-size'.

Steps to reproduce:

1. git clone --depth 1 --branch bug/window-text-pixel-size https://git.sr.ht/~yantar92/org-mode
2. cd org-mode
3. make repro REPRO_ARGS="-l ./testing/org-test.el"
4. (setq org-confirm-babel-evaluate nil)
5. M-x debug-on-entry org-string-width
6. Insert and execute the following in *scratch*

  (org-test-with-temp-text-in-file "

#+NAME: example-list
- simple
  - not
  - nested
- list

<point>#+BEGIN_SRC emacs-lisp :var x=example-list
(print x)
#+END_SRC"

    (should (equal '("simple" "list") (org-babel-execute-src-block)))
    (forward-line 5)
    (should (string=
             "| simple | list |"
             (buffer-substring
	      (point-at-bol)
	      (point-at-eol)))))

7. If we "c" in the debugger, there is arith error originating from the
   second call to `window-text-pixel-size' returning (0 . X) in buffer
   containing text "a".

The code of `org-string-width' is:

(defun org-string-width (string &optional pixels)
  "Return width of STRING when displayed in the current buffer.
Return width in pixels when PIXELS is non-nil."
       ....
      (with-current-buffer (get-buffer-create " *Org string width*")
        (setq-local display-line-numbers nil
                    line-prefix nil
                    wrap-prefix nil)
        (setq-local buffer-invisibility-spec
                    (if (listp current-invisibility-spec)
                        (mapcar (lambda (el)
                                  ;; Consider ellipsis to have 0 width.
                                  ;; It is what Emacs 28+ does, but we have
                                  ;; to force it in earlier Emacs versions.
                                  (if (and (consp el) (cdr el))
                                      (list (car el))
                                    el))
                                current-invisibility-spec)
                      current-invisibility-spec))
        (setq-local char-property-alias-alist
                    current-char-property-alias-alist)
        (let (pixel-width symbol-width)
          (with-silent-modifications
            (erase-buffer)
            (insert string)
            (setq pixel-width
                  (car (window-text-pixel-size
                        nil (line-beginning-position) (point-max))))
            (unless pixels
              (erase-buffer)
              (insert "a")
              (setq symbol-width
                    (car (window-text-pixel-size ;; <---- unexpected return
                          nil (line-beginning-position) (point-max))))))
          (if pixels
              pixel-width
            (/ pixel-width symbol-width)))))))

In GNU Emacs 30.0.50 (build 5, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.17.8) of 2023-07-29 built on localhost
Repository revision: ce48073f1597ceecb82800e71c89b53badc9f9d0
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: Gentoo Linux

Configured using:
 'configure --with-native-compilation'


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>





             reply	other threads:[~2023-08-01  7:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01  7:47 Ihor Radchenko [this message]
2023-08-01 12:07 ` bug#64986: 30.0.50; window-text-pixel-size sometimes returns 0 width when called from temporary buffer Eli Zaretskii
2023-08-01 13:13   ` Ihor Radchenko
2023-08-03  8:55     ` Eli Zaretskii

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=87o7jrgq5n.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=64986@debbugs.gnu.org \
    /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).