Skip to content

Fix issue with fontification when markdown-inline is enabled #80

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

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [#74](https://github.com/clojure-emacs/clojure-ts-mode/issues/74): Add imenu support for keywords definitions.
- [#77](https://github.com/clojure-emacs/clojure-ts-mode/issues/77): Update grammars to the latest versions.
- [#79](https://github.com/clojure-emacs/clojure-ts-mode/pull/79): Improve markdown highlighting in the docstrings.
- [#60](https://github.com/clojure-emacs/clojure-ts-mode/issues/60): Fix issue with incorrect fontification, when `markdown-inline` is enabled.

## 0.2.3 (2025-03-04)

Expand Down
15 changes: 12 additions & 3 deletions clojure-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ if a third argument (the value) is provided.
(treesit-range-rules
:embed 'markdown-inline
:host 'clojure
:local t
(clojure-ts--docstring-query '@capture)))

(defun clojure-ts--font-lock-settings (markdown-available)
Expand Down Expand Up @@ -1230,7 +1231,7 @@ It is simply `clojure-ts-docstring-fill-prefix-width' number of spaces."
(defun clojure-ts--fill-paragraph (&optional justify)
"Like `fill-paragraph', but can handler Clojure docstrings.
If JUSTIFY is non-nil, justify as well as fill the paragraph."
(let ((current-node (treesit-node-at (point))))
(let ((current-node (treesit-node-at (point) 'clojure)))
(if (clojure-ts--match-docstring nil current-node nil)
(let ((fill-column (or clojure-ts-docstring-fill-column fill-column))
(fill-prefix (clojure-ts--docstring-fill-prefix))
Expand Down Expand Up @@ -1260,11 +1261,20 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
"map_lit" "ns_map_lit" "vec_lit" "set_lit")
"A regular expression that matches nodes that can be treated as lists.")

(defconst clojure-ts--markdown-inline-sexp-nodes
'("inline_link" "full_reference_link" "collapsed_reference_link"
"uri_autolink" "email_autolink" "shortcut_link" "image"
"code_span")
"Nodes representing s-expressions in the `markdown-inline' parser.")

(defconst clojure-ts--thing-settings
`((clojure
(sexp ,(regexp-opt clojure-ts--sexp-nodes))
(list ,(regexp-opt clojure-ts--list-nodes))
(text ,(regexp-opt '("comment"))))))
(text ,(regexp-opt '("comment"))))
(when clojure-ts-use-markdown-inline
(markdown-inline
(sexp ,(regexp-opt clojure-ts--markdown-inline-sexp-nodes))))))

(defvar clojure-ts-mode-map
(let ((map (make-sparse-keymap)))
Expand Down Expand Up @@ -1380,7 +1390,6 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE."
(let ((use-markdown-inline (and clojure-ts-use-markdown-inline
(treesit-ready-p 'markdown-inline t))))
(when use-markdown-inline
(treesit-parser-create 'markdown-inline)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so this was not supposed to be used in this manner. Good to know!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I actually tried to pass :local t to the range function but it didn't work because I didn't remove this line as well. It was a good idea to ask for help in Emacs-bugs mailing list.

(setq-local treesit-range-settings clojure-ts--treesit-range-settings))

(when (treesit-ready-p 'clojure)
Expand Down