unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#64986: 30.0.50; window-text-pixel-size sometimes returns 0 width when called from temporary buffer
@ 2023-08-01  7:47 Ihor Radchenko
  2023-08-01 12:07 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2023-08-01  7:47 UTC (permalink / raw)
  To: 64986

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>





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-03  8:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-01  7:47 bug#64986: 30.0.50; window-text-pixel-size sometimes returns 0 width when called from temporary buffer Ihor Radchenko
2023-08-01 12:07 ` Eli Zaretskii
2023-08-01 13:13   ` Ihor Radchenko
2023-08-03  8:55     ` Eli Zaretskii

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).