Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svg-tag for begin_src destroy the font lock in emacs 29 #48

Open
TimotheeMathieu opened this issue Aug 14, 2023 · 23 comments
Open

svg-tag for begin_src destroy the font lock in emacs 29 #48

TimotheeMathieu opened this issue Aug 14, 2023 · 23 comments

Comments

@TimotheeMathieu
Copy link

TimotheeMathieu commented Aug 14, 2023

Hello,

I recently updated to emacs 29.1 (GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.17.8)) and I noticed that svg-tag seemd to conflict with org font-lock in my config.

Here is a minimal reproduction example:

init.el

(setq straight-use-package-by-default t)

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(setq straight-use-package-by-default t)

(use-package svg-tag-mode)

(setq svg-tag-tags
      `(
         ;; source block from notebook-mode
 ("^#\\+begin_src\\( [a-zA-Z\-]+\\)" .  ((lambda (tag)
                                                  (svg-tag-make (upcase tag)
                                                                :face 'org-meta-line
                                                                :crop-left t))))
)
)

(add-hook 'text-mode-hook 'svg-tag-mode)

And then the file test.org

* Test
#+begin_src emacs-lisp
(message "Hello world")
#+end_src

#+RESULTS:
: Hello world

appears like this with svg-tag:

image

and like this if I have no svg-tag activated (which is equivalent to what I have with emacs -q)

image

This happens only with this src tag that worked well before the update to emacs 29, I also have a TODO svg-tag in my config and this one works well.

This may be linked with #47 as I have the same

Error during redisplay: (jit-lock-function 1) signaled (wrong-type-argument stringp nil)

poping up in the messages buffer.

@yaqubroli
Copy link

Having a similar issue on mitsuharu's emacs-mac (railwaycat Homebrew tap, emacs 29), although it also resembles #27 (partially renders some formatting, leaves a large chunk of the file plain).

Here is the section of my config that sets up svg-tag-mode: https://github.com/yaqubroli/yaqubmacs/blob/master/rougier_tmp.org

Screenshot 2023-08-19 at 2 48 06 pm

Initially I was going to say that it only renders partially when I evaluate the config section that installs svg-tag-mode, but don't restart emacs. When I restarted emacs before, it would show this file without any formatting whatsoever. However, in trying to replicate the issue, I haven't been able to get this specific file to display completely plainly. It does it with some files though (maybe shorter ones?)

I also get the jit-lock-function error like above and #47. Maybe, since the file is only rendering partially, there's some memory leak/allocation issue? It seems weird that it would start at the bottom of the file though.

@yaqubroli
Copy link

yaqubroli commented Aug 19, 2023

Ah, it appears that the file renders plainly when I enable jit-lock-debug-mode. Infuriatingly, I don't get the jit-lock error when this mode is enabled, so there's not even anything to debug. This is very weird; probably a bug in emacs itself?

Screenshot 2023-08-19 at 3 21 45 pm

@rougier
Copy link
Owner

rougier commented Aug 24, 2023

I think the jit-lock error comes from the added "display" property to font lock: (add-to-list 'font-lock-extra-managed-props 'display).

If you comment it (you won't get tag obviously), do you still get errors?

@TimotheeMathieu
Copy link
Author

I tried to comment out the "display" property that you linked to but I still have the same problem.

Remark that, if that helps, using tags without regexp seems to not cause problem, i.e. using only this tag instead of the one from my first post:

 ("^#\\+begin_src" .  ((lambda (tag)
                                                  (svg-tag-make (upcase tag)
                                                                :face 'org-meta-line
                                                                :crop-left t))))

So the problem seems to come from regexp computation.

@rougier
Copy link
Owner

rougier commented Sep 11, 2023

Can you try using the same regex without svg-tag (replace text with another string) ?

@TimotheeMathieu
Copy link
Author

Yes, I tried and if I replace with string then the font lock works, there is no problem.

@rougier
Copy link
Owner

rougier commented Oct 12, 2023

Could you try:

;; TODO: test
(add-to-list 'font-lock-extra-managed-props 'display)
(font-lock-add-keywords nil
  `(("\\(TODO\\):" 1 '(face nil display ,(svg-lib-tag "TODO")) prepend)))

@TimotheeMathieu
Copy link
Author

From what I see it is meant to act on TODO, but with your code I don't see anything changing for TODO's.

I tried with and without begin_src svg-tags.

@rougier
Copy link
Owner

rougier commented Nov 16, 2023

Sorry for delay. If you paste the above code in the scratch buffer and call eval-buffer, you see no change ?

@TimotheeMathieu
Copy link
Author

No I see no change.
I am not sure what your code was meant to do but I guess you wanted to test that the TODO became an svg but it does not and there is nothing in the Message buffer.

@rougier
Copy link
Owner

rougier commented Nov 22, 2023

Weird. Do you have SVG support? Can you try:

;; TODO: test
(add-to-list 'font-lock-extra-managed-props 'display)
(font-lock-add-keywords nil
  `(("\\(TODO\\):" 1 '(face nil display "WORKS") prepend)))

If you edit the TODO, it shoudl display "WORKS". Maybe you'll need to setup a mode such as text-mode or lisp-mode (to have font-lock enabled)

@TimotheeMathieu
Copy link
Author

TimotheeMathieu commented Nov 26, 2023

I tried and indeed this replaces TODO with WORKS. It works, as you said it should.
Also, I have SVG support because if I just use the usual TODO svg tag it gives me an SVG.

@rougier
Copy link
Owner

rougier commented Dec 4, 2023

Can you try:

(setq svg-tag-tags
      `(
         ;; source block from notebook-mode
 ("^#\\+begin_src\\( [a-zA-Z\-]+\\)" .  ((lambda (tag)
                                                  (svg-tag-make "TEST"
                                                                :face 'org-meta-line
                                                                :crop-left t))))))```

@TimotheeMathieu
Copy link
Author

Yes. This one works and transform the language of the source code in an svg with TEST written in it:
image

@rougier
Copy link
Owner

rougier commented Dec 4, 2023

This probably means the tag is nil is some situation. Can you try:

(setq svg-tag-tags
      `(
         ;; source block from notebook-mode
 ("^#\\+begin_src\\( [a-zA-Z\-]+\\)" .  ((lambda (tag)
     (message "Tag value: %s" tag)
                                                  (svg-tag-make (or tag "FAIL")
                                                                :face 'org-meta-line
                                                                :crop-left t))))))```

@TimotheeMathieu
Copy link
Author

I tried it: I got the message Tag value: emacs-lisp in the messsage buffer for my emacs-lisp source code but on the other hand, the text was without any font lock and there was not FAIL and no svg.

@rougier
Copy link
Owner

rougier commented Dec 13, 2023

Can you try to using it with your original org file (the one that shows SVG errors)?

@TimotheeMathieu
Copy link
Author

Yes.
I added the code to the init.el and when I do M-x svg-tag-mode while in the org-mode file, the font-lock disappear from my test org-mode file and I get the following messages in the *Messages* buffer:

Svg-Tag mode enabled in current buffer
Tag value:  emacs-lisp
Error during redisplay: (jit-lock-function 1) signaled (wrong-type-argument stringp nil)
You can run the command ‘svg-tag-mode’ with M-x sv
Tag value:  emacs-lisp

@rougier
Copy link
Owner

rougier commented Jan 9, 2024

Another try:

#+begin_src emacs-lisp
(font-lock-add-keywords nil
         `(("lisp"
            0 `(face nil
                display (svg-lib-tag "LISP"))
        prepend)) 'append)
(font-lock-update)
#+end_src

@TimotheeMathieu
Copy link
Author

This works, transform the lisp to LISP when executed and message is (jit-lock-bounds 1 . some-number) with the some-number being an integer different every time I execute.

@rougier
Copy link
Owner

rougier commented Jan 10, 2024

Cool. This means I need to make the same prepend/append trick to svg-tag-mode.el. Do you want to try to make a PR?

@TimotheeMathieu
Copy link
Author

I tried to change the library with some intuition of what things should do, but I am really not fluent enough in elisp and in particular in font lock to be able to do a PR.
So thanks for asking, but I don't know how to solve it, so I can't do a PR.
I am available to test any PR that comes up though.

@rougier
Copy link
Owner

rougier commented Jan 15, 2024

No problem. I'll try to make the PR. I leave the issue open until it is fixed. Don't hesitate to remind me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants