0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-08-25 13:02:51 +00:00

org-sting-width: Do no err in dedicated windows

* lisp/org-macs.el (org-string-width): Do not err when current window
is dedicated.  Force-remove dedicated status temporarily during the
call.  This should be safe as we only need to take over the window
temporarily to hook into Emacs display and calculate the string
width.

Reported-by: Bruno BARBIER <brubar.cs@gmail.com>
Link: https://orgmode.org/list/63662793.5d0a0220.62647.3003@mx.google.com
This commit is contained in:
Ihor Radchenko 2022-11-05 17:38:37 +08:00
parent 3e010d81dc
commit 946abeb49a
No known key found for this signature in database
GPG key ID: 6470762A7DA11D8B

View file

@ -1100,9 +1100,17 @@ Return width in pixels when PIXELS is non-nil."
(if (get-buffer-window (current-buffer))
(car (window-text-pixel-size
nil (line-beginning-position) (point-max)))
(set-window-buffer nil (current-buffer))
(car (window-text-pixel-size
nil (line-beginning-position) (point-max)))))
(let ((dedicatedp (window-dedicated-p))
(oldbuffer (window-buffer)))
(unwind-protect
(progn
;; Do not throw error in dedicated windows.
(set-window-dedicated-p nil nil)
(set-window-buffer nil (current-buffer))
(car (window-text-pixel-size
nil (line-beginning-position) (point-max))))
(set-window-buffer nil oldbuffer)
(set-window-dedicated-p nil dedicatedp)))))
(unless pixels
(erase-buffer)
(insert "a")
@ -1110,9 +1118,17 @@ Return width in pixels when PIXELS is non-nil."
(if (get-buffer-window (current-buffer))
(car (window-text-pixel-size
nil (line-beginning-position) (point-max)))
(set-window-buffer nil (current-buffer))
(car (window-text-pixel-size
nil (line-beginning-position) (point-max)))))))
(let ((dedicatedp (window-dedicated-p))
(oldbuffer (window-buffer)))
(unwind-protect
(progn
;; Do not throw error in dedicated windows.
(set-window-dedicated-p nil nil)
(set-window-buffer nil (current-buffer))
(car (window-text-pixel-size
nil (line-beginning-position) (point-max))))
(set-window-buffer nil oldbuffer)
(set-window-dedicated-p nil dedicatedp)))))))
(if pixels
pixel-width
(/ pixel-width symbol-width)))))))