emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/org 946abeb49a: org-sting-width: Do no err in dedicated


From: ELPA Syncer
Subject: [elpa] externals/org 946abeb49a: org-sting-width: Do no err in dedicated windows
Date: Sat, 5 Nov 2022 05:57:55 -0400 (EDT)

branch: externals/org
commit 946abeb49a73d7d04233a53fbb7fd422c7e294b6
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    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
---
 lisp/org-macs.el | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 2eb1a8b628..541413a64a 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -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)))))))



reply via email to

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