Subject: 29.0.60; Issues when displaying images

From: Abdul-Lateef Haji-Ali <[email-masked]>
Date: Sun, 02 Apr 2023 14:31:12 +0100

It seems that `mm-inline-image` switched to using `insert-image` instead of `put-image` which resulted in some regressions in notmuch that I noticed between emacs 29 and emacs 28.2. However, I tracked down the discrepancy to the following issues in displaying images in emacs-29. 

First the following code (assuming some image in /tmp/tmp.png), executed in "emacs -Q" on either emacs 28.2 or emacs 29:

(let (content-begin
      content-end)
  (goto-char (point-max))
  (insert "\n")
  (setq content-begin (point))
  (insert-image (create-image "/tmp/tmp.png"))
  (setq content-end (point))

  ;; I expect the following line to indent the image (or not).
  ;; instead the image is removed completely
  ;;(indent-rigidly content-begin content-end 1)

  ;; This line should hide the image, but it doesn't
  ;;(overlay-put (make-overlay content-begin content-end) 'invisible t)
  )

Uncommenting each of the two lines of code shows the two issues (explained in comments). These issues appear in both emacs 29 and 28.2 (though they might be specific to MacOS).

Similar code to this example is executed in notmuch when displaying message, but using `mm-inline-image` instead of insert-image:

(let* ((buffer (find-file-noselect "/tmp/tmp.png" t t))
       (handle (list
                buffer '("image/jpeg" (charset))
                nil nil nil nil
                `(image :type jpeg
                        :data ,(with-current-buffer buffer
                                 (buffer-string))
                        :scale 1
                        :transform-smoothing t)
                nil))
       content-begin
       content-end)
  (goto-char (point-max))
  (insert "\n")
  (setq content-begin (point))
  (require 'mm-view)
  (mm-inline-image handle)
  (setq content-end (point))

  ;; I expect the following line to indent the image (or not).
  ;; instead the image is removed completely
  ;;(indent-rigidly content-begin content-end 1)

  ;; This line should hide the image, but it doesn't
  ;;(overlay-put (make-overlay content-begin content-end) 'invisible t)
  )

In this case, in Emacs 29, the behaviour is similar to the "wrong" behaviour of the first example. In Emacs 28.2 on the other hand, the behaviour is what I would expect in both cases (though the undo stack gets messed up and I cannot undo inserting the image. Indenting also doesn't work, but at least the image is not removed)

As a last test, in case it is helpful, I tried the following in emacs 29 using `put-image` instead of `insert-image` (`mm-inline-image` uses in Emacs 28.2 uses `put-image` while in Emacs 29 it uses 'insert-image'), and noticed an equally puzzling behaviour:

(let (content-begin
      content-end)
  (goto-char (point-max))
  (insert "\n")

  (setq content-begin (point))
  (put-image (create-image "/tmp/tmp.png") (point-marker))  
  (setq content-end (point))

  ;; I expect the following line to indent the image (or not).
  ;; instead the image is removed completely
  ;;(indent-rigidly content-begin content-end 1)

  ;; This line should hide the image, but it doesn't
  ;;(overlay-put (make-overlay content-begin content-end) 'invisible t)
)

In this case, `indent-rigidly` does not remove the image, but hiding the overlay does not work.

Best regards,
-- Al

----------------------------------------------------------------------------
In GNU Emacs 29.0.60 (build 1, aarch64-apple-darwin22.3.0, NS
 appkit-2299.40 Version 13.2.1 (Build 22D68)) of 2023-03-22 built on
 HW-R9XXWKPJ4D
Windowing system distributor 'Apple', version 10.3.2299
System Description:  macOS 13.2.1

Configured using:
 'configure --disable-dependency-tracking --disable-silent-rules
 --enable-locallisppath=/opt/homebrew/share/emacs/site-lisp
 --infodir=/opt/homebrew/Cellar/emacs-plus@29/29.0.60/share/info/emacs
 --prefix=/opt/homebrew/Cellar/emacs-plus@29/29.0.60 --with-xml2
 --with-gnutls --with-native-compilation --without-compress-install
 --without-dbus --with-imagemagick --with-modules --with-rsvg --with-ns
 --disable-ns-self-contained 'CFLAGS=-Os -w -pipe
 -mmacosx-version-min=13
 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk
 -DFD_SETSIZE=10000 -DDARWIN_UNLIMITED_SELECT'
 'CPPFLAGS=-I/opt/homebrew/opt/zlib/include
 -I/opt/homebrew/opt/jpeg/include -I/opt/homebrew/opt/libomp/include
 -I/opt/homebrew/opt/icu4c/include
 -I/opt/homebrew/opt/[email-masked]/include -isystem/opt/homebrew/include
 -F/opt/homebrew/Frameworks
 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk'
 'LDFLAGS=-L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/jpeg/lib
 -L/opt/homebrew/opt/libomp/lib -L/opt/homebrew/opt/icu4c/lib
 -L/opt/homebrew/opt/[email-masked]/lib -L/opt/homebrew/lib
 -F/opt/homebrew/Frameworks -Wl,-headerpad_max_install_names
 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk''

Configured features:
ACL GIF GLIB GMP GNUTLS IMAGEMAGICK JPEG JSON LCMS2 LIBXML2 MODULES
NATIVE_COMP NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM ZLIB

Important settings:
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv cl-extra
help-mode bytecomp byte-compile cl-lib sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils rmc iso-transl tooltip cconv
eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/ns-win ns-win ucs-normalize mule-util
term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads kqueue cocoa ns lcms2 multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 77309 5714)

________________________________
Heriot-Watt University was founded in 1821 and is a registered Scottish charity (SC000278).
 (symbols 48 7039 0)
 (strings 32 18694 2727)
 (string-bytes 1 577061)
 (vectors 16 16292)
 (vector-slots 8 324373 10025)
 (floats 8 27 46)
 (intervals 56 297 0)
 (buffers 984 10))