emacs-devel
[Top][All Lists]
Advanced

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

Re: [Emacs-diffs] emacs-26 f274cbd: Avoid reordering of output in 'shr-i


From: martin rudalics
Subject: Re: [Emacs-diffs] emacs-26 f274cbd: Avoid reordering of output in 'shr-insert-document'
Date: Sun, 17 Dec 2017 22:20:59 +0100

> If we do that, then why use save-window-excursion in the first place?
> That's what it's supposed to preserve (among other things), right?

Not really.  The Elisp manual says about `save-window-excursion' that

     This macro records the window configuration of the selected frame,
     executes FORMS in sequence, then restores the earlier window
     configuration.

and about window configurations

    As a special exception, the window
  configuration does not record the value of point in the selected window
  for the current buffer.

so the point of the selected window is not necessarily restored.

> If it doesn't do that much, let's do its job by hand altogether.  (And
> then, of course, a few years down the line someone will come and ask
> herself why don't they just use save-window-excursion.)

Well, `set-window-buffer' isn't that innocuous either.

Note that `shr-pixel-column' will also fail when the current buffer is
not shown in the selected window.  Hence, a more correct version should
do:

(defun shr-pixel-column ()
  (cond
   ((not shr-use-fonts)
    (current-column))
   ((not (eq (window-buffer) (current-buffer)))
    (let ((window-point (window-point)))
      (prog1
          (save-window-excursion
            ;; Avoid errors if the selected window is a dedicated one,
            ;; and they just want to insert a document into it.
            (set-window-dedicated-p nil nil)
            (set-window-buffer nil (current-buffer))
            (car (window-text-pixel-size nil (line-beginning-position) 
(point))))
        (set-window-point nil window-point))))
   (t
    (car (window-text-pixel-size nil (line-beginning-position) (point))))))

But without a doc-string I obviously can't tell for sure.

martin



reply via email to

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