Subject: 31.0.50; Fontification malfunction

From: Johan Ekenberg <[email-masked]>
Date: Tue, 7 Jan 2025 21:08:09 +0100

--text follows this line--

- Start emacs: 'emacs -Q'
- Paste this function into the scratch buffer and evaluate it:
  (defun test-org-insertion-fontification ()
    (interactive)
    (let* ((chunks
            '("#+begin_src elisp\n"
              "(+ 1 2)"
              "\n#+end_src\n")))
      (insert "* NOTE: You need to run this with org-mode enabled and point
at end of buffer\n\n")
      (insert "** This code block is fontified correctly\n")
      (insert (car chunks))
      (dolist (chunk (cdr chunks))
        (insert chunk))

      (insert "\n** But not this code block\n")
      (insert (car chunks))
      (dolist (chunk (cdr chunks))
        (sit-for (/ 10 1000.0)) ; simulate chunks received over network and
streamed into buffer
        ;; The following were also tested one by one instead of the sit-for
line above:
        ;; (redisplay) ; this triggers the bug
        ;; (force-mode-line-update) ; this does not trigger the bug
        ;; (read-event nil nil 0) ; this triggers the bug
        (insert chunk))
      ))
- Open an existing or new file/buffer with org-mode enabled (C-x C-f foo.org
)
- Place point at end of buffer
- M-x test-org-insertion-fontification
- Optional: replace the line (sit-for...) with any of the lines below it.

- Additional information: The problem was discovered when receiving
streamed data responses via the package gptel which is an Emacs LLM
Client. Here is the reported issue:
https://github.com/karthink/gptel/issues/550

- Also replicated on Emacs 29.3

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.33, cairo version 1.16.0) of 2025-01-07 built on piano
Repository revision: 4bf0f6655142b9e216325d051943b7b7ca4d2cd7
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Linux Mint 21.3

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LC_MONETARY: sv_SE.UTF-8
  value of $LC_NUMERIC: sv_SE.UTF-8
  value of $LC_TIME: en_GB.UTF-8
  value of $LANG: C.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Org

Minor modes in effect:
  tooltip-mode: t
  global-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
  minibuffer-regexp-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 face-remap help-macro oc-basic cl-extra
help-mode org-element org-persist org-id org-refile org-element-ast
inline avl-tree generator ol-eww eww vtable mule-util url-queue mm-url
ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect gnus-art mm-uu mml2015
mm-view mml-smime smime gnutls dig gnus-sum shr pixel-fill kinsoku
url-file svg dom gnus-group gnus-undo gnus-start gnus-dbus dbus xml
gnus-cloud nnimap nnmail browse-url xdg url url-proxy url-privacy
url-expand url-methods url-history url-cookie generate-lisp-file
url-domsuf url-util url-parse auth-source cl-seq eieio eieio-core
cl-macs json map url-vars mail-source utf7 nnoo parse-time gnus-spec
gnus-int gnus-range message sendmail mailcap yank-media puny rfc822 mml
mml-sec password-cache epa derived epg rfc6068 epg-config mm-decode
mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045 ietf-drums
mailabbrev gmm-utils mailheader gnus-win gnus nnheader gnus-util
text-property-search mail-utils range mm-util mail-prsvr wid-edit
ol-docview doc-view byte-opt gv bytecomp byte-compile filenotify
jka-compr image-mode exif dired dired-loaddefs ol-bibtex bibtex iso8601
ol-bbdb ol-w3m ol-doi org-link-doi org ob ob-tangle ob-ref ob-lob
ob-table ob-exp org-macro org-src sh-script smie treesit executable
ob-comint org-pcomplete pcomplete comint ansi-osc ansi-color ring
org-list org-footnote org-faces org-entities time-date subr-x noutline
outline icons org-version ob-emacs-lisp ob-core ob-eval org-cycle
org-table ol rx org-fold org-fold-core org-keys oc org-loaddefs
thingatpt find-func cal-menu calendar cal-loaddefs org-compat org-macs
format-spec cl-loaddefs cl-lib rmc iso-transl tooltip cconv eldoc paren
electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd touch-screen 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 dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo gtk
x-toolkit xinput2 x multi-tty move-toolbar make-network-process
tty-child-frames emacs)

Memory information:
((conses 16 203329 36256) (symbols 48 21221 0) (strings 32 66951 3884)
 (string-bytes 1 1766656) (vectors 16 37794)
 (vector-slots 8 363252 21163) (floats 8 281 90) (intervals 56 804 0)
 (buffers 992 14))