all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 36492@debbugs.gnu.org
Subject: bug#36492: c-mode fails with errors during fontification
Date: Wed, 03 Jul 2019 23:56:19 +0300	[thread overview]
Message-ID: <87imsikh64.fsf@mail.linkov.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 5094 bytes --]

Opening this message in Gnus fails with the following backtrace
after setting (setq diff-font-lock-syntax 'hunk-also)
because c-mode fails to fontify the attachment.

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  c-forward-decl-or-cast-1(0 top nil)
  (setq decl-or-cast (c-forward-decl-or-cast-1 match-pos context last-cast-end))
  (if (eq context 'not-decl) ...)
  (if (or (and (eq (get-text-property (point) 'face) 'font-lock-keyword-face) ...) ...) t ...)
  (if (if (or (and (eq (get-text-property (point) 'face) 'font-lock-keyword-face) ...) ...) t ...) ...)
  (lambda (match-pos inside-macro &optional toplev) ...)(0 nil t)
  c-find-decl-spots(11 "[[:alpha:]_]" (nil font-lock-type-face font-lock-constant-face font-lock-keyword-face) ...)
  (let (start-pos context ...) ... nil)
  (save-restriction (let (start-pos context ...) ... nil))
  (progn (save-restriction (let (start-pos context ...) ... nil)))
  (if (< (point) limit) (progn (save-restriction (let (start-pos context ...) ... nil))))
  c-font-lock-declarations(11)
  font-lock-fontify-keywords-region(1 11 nil)
  font-lock-default-fontify-region(1 11 nil)
  funcall(font-lock-default-fontify-region 1 11 nil)
  (let (new-beg new-end new-region case-fold-search) ...)
  c-font-lock-fontify-region(1 11 nil)
  font-lock-fontify-region(1 11)
  #f(compiled-function (beg end) #<bytecode 0x1fd6e1a05171>)(1 11)
  font-lock-ensure(1 11)
  diff-syntax-fontify-props(#("a/test.c" 0 8 (face (diff-file-header diff-header))) "int i)\n{\n1" (1 3) t)
  diff-syntax-fontify-hunk(78 111 t)
  diff-syntax-fontify(78 111)
  #f(compiled-function (beg end) #<bytecode 0x158f39208a39>)(78 111)
  diff--iterate-hunks(113 #f(compiled-function (beg end) #<bytecode 0x158f39208a39>))
  diff--font-lock-syntax(113)
  font-lock-fontify-keywords-region(1 113 nil)
  font-lock-default-fontify-region(1 113 nil)
  font-lock-fontify-region(1 113)
  #f(compiled-function (beg end) #<bytecode 0x1fd6e1a05171>)(1 113)
  font-lock-ensure()
  (if (eq major-mode 'fundamental-mode) nil (font-lock-ensure))
  (progn (if mode (let ((#:wconfig (current-window-configuration))) ...) ...) ...)
  (condition-case #:err (progn ...) ((debug error) (message "Error: %S" #:err) nil))
  (let ((font-lock-verbose nil) (enable-local-variables nil)) ...)
  (progn (buffer-disable-undo) (mm-enable-multibyte) ...)
  (unwind-protect (progn (buffer-disable-undo) (mm-enable-multibyte) ...) ...)
  (save-current-buffer (set-buffer #:temp-buffer) (unwind-protect ...))
  (let ((#:temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer ...))
  (let ((charset (mail-content-type-get (nth 1 handle) 'charset)) text coding-system ovs) ...)
  mm-display-inline-fontify(... diff-mode)
  mm-display-patch-inline(...)
  mm-display-inline(...)
  gnus-mime-display-single(...)
  gnus-mime-display-part(...)
  mapcar(gnus-mime-display-part (...))
  gnus-mime-display-mixed((...))
  gnus-mime-display-part((#("multipart/mixed" 0 15 ...) ...))
  gnus-display-mime()
  gnus-article-prepare-display()
  gnus-article-prepare(5460 nil)
  funcall(gnus-article-prepare 5460 nil)
  (prog1 (funcall (or gnus-summary-display-article-function ...) article all-header) ...)
  (if (null article) nil (prog1 (funcall (or gnus-summary-display-article-function ...) article all-header)))
  gnus-summary-display-article(5460 nil)
  (progn (gnus-summary-display-article article all-headers) ...)
  (if (or (and gnus-single-article-buffer ...)) ... 'old)
  (save-current-buffer (set-buffer gnus-summary-buffer) ...)
  (let ((article (or article (gnus-summary-article-number))) ...) ...)
  gnus-summary-select-article(nil nil pseudo)
  (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
  (if (eq (gnus-summary-select-article nil nil 'pseudo) 'old) ...)
  gnus-summary-scroll-up(1)
  funcall-interactively(gnus-summary-scroll-up 1)
  call-interactively(gnus-summary-scroll-up nil nil)
  command-execute(gnus-summary-scroll-up)

I don't know if it's possible to fix c-mode to not raise the error
during fontification.  But at least the patch below will avoid this error
while displaying such attachments in Gnus.  Normally calling font-lock-ensure
ignores the fontification errors when called from font-lock.
But in mm-display-inline-fontify font-lock-ensure is called directly
from top-level, so this patch ignores its errors.

diff --git a/lisp/gnus/mm-view.el b/lisp/gnus/mm-view.el
index 6ffa1fc168..ebaf8435c0 100644
--- a/lisp/gnus/mm-view.el
+++ b/lisp/gnus/mm-view.el
@@ -500,7 +500,7 @@ mm-display-inline-fontify
 	      (setq mode major-mode)))
 	  ;; Do not fontify if the guess mode is fundamental.
 	  (unless (eq major-mode 'fundamental-mode)
-	    (font-lock-ensure))))
+	    (ignore-errors (font-lock-ensure)))))
       (setq text (buffer-string))
       (when (eq mode 'diff-mode)
 	(setq ovs (mapcar (lambda (ov) (list ov (overlay-start ov)

Then visiting such attachments will just leave this line in *Messages*
without wreaking much havoc:

  Error during redisplay: (jit-lock-function 1) signaled (wrong-type-argument integer-or-marker-p nil)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test.diff --]
[-- Type: text/x-diff, Size: 112 bytes --]

diff --git a/test.c b/test.c
index aaa..bbb 100644
--- a/test.c
+++ b/test.c
@@ -1,3 +2,3 @@
 int i)
 {
-1
+2



             reply	other threads:[~2019-07-03 20:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-03 20:56 Juri Linkov [this message]
2019-07-04 20:08 ` bug#36492: c-mode fails with errors during fontification Juri Linkov
     [not found] ` <mailman.154.1562272763.2688.bug-gnu-emacs@gnu.org>
2019-07-04 21:19   ` Alan Mackenzie
2019-07-06 14:27   ` Alan Mackenzie
2019-07-07 21:52     ` Juri Linkov
2019-07-08 12:53       ` Alan Mackenzie
2019-07-08 13:16         ` Noam Postavsky
2019-07-08 21:46           ` Juri Linkov
2019-07-08 21:58             ` Noam Postavsky
2019-07-08 13:47         ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imsikh64.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=36492@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.