2

Web pages are rendered with the simple html renderer shr in the Emacs webbrowser EWW. Pitingly, images in tables are displayed below the tables.

The source code of shr contains the following comment about that:

    ;; Finally, insert all the images after the table.  The Emacs buffer
    ;; model isn't strong enough to allow us to put the images actually
    ;; into the tables.  It inserts also non-td/th objects.

Is that actually true? Shr already uses window-text-pixel-size for calculating the width of columns.

Furthermore, one can adjust column positions fine grained with the help of the :align-to space width specifiction.

The following code shows that window-text-pixel-size and :align-to work well with images:

(with-current-buffer (get-buffer-create "*test*")
  (unless (and
           (intern-soft "img")
           (boundp 'img)
           (stringp img))
    (setq-local
     img
     (with-current-buffer
         (url-retrieve-synchronously
          "https://cdn.sstatic.net/Sites/emacs/img/logo.svg?v=ceb7969787d0")
       (buffer-string))))
  (delete-region (point-min) (point-max))
  (insert
   "initial string"
   (propertize " " 'display '(space :align-to (10 . cm)))
   "second column"
   "\nImg: ")
  (insert-image (create-image
                 img
                 nil
                 t))
  (insert
   " text behind "
   (propertize " " 'display '(space :align-to (10 . cm)))
   "2nd column")
  (let ((wnd (display-buffer (current-buffer))))
    (cons
     (car
      (window-text-pixel-size
       wnd
       (goto-char (point-min))
       (progn
         (search-forward "second column")
         (match-beginning 0))))
     (car
      (window-text-pixel-size
       wnd
       (progn
         (forward-line)
         (point))
       (progn
         (search-forward "2nd column")
         (match-beginning 0)))))))

The code returns (377 . 377) meaning that x-window-text-pixel-width perfectly calculates the width of the rows belonging to the first column.

A screenshot of the produced buffer:

buffer with :align-to and window-text-pixel-size

It shows that the rows of the second column are perfectly aligned.

Question: What is the actual limitation that is addressed in the above quotation?

Emacs-Version: GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-09-16

1
  • Yes this would be nice if emacs could do that, it is at least capable of showing images side by side. – jue Oct 25 '19 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.