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

#49 Don't flyspell links #50

Merged
merged 5 commits into from
Feb 8, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- [#21](https://github.com/bbatsov/adoc-mode/pull/21): Add support for native font-locking in code blocks.

### Bugs fixed

- [#49](https://github.com/bbatsov/adoc-mode/issues/49) Flyspell generates overlays for links and alike

## 0.7.0 (2023-03-09)

### New features
Expand Down
53 changes: 35 additions & 18 deletions adoc-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1846,13 +1846,17 @@ TEXTPROPS is an additional plist with textproperties."
(list
`(lambda (end) (adoc-kwf-std end ,(adoc-re-inline-macro cmd-name nil unconstrained attribute-list-constraints) '(1 2 4 5) '(0)))
`(0 '(face nil . ,textprops) t)
`(1 '(face ,(or cmd-face adoc-command-face) adoc-reserved t) t) ; cmd-name
`(1 '(face ,(or cmd-face adoc-command-face) adoc-reserved t adoc-flyspell-ignore t) t) ; cmd-name
'(2 '(face adoc-meta-face adoc-reserved t . ,textprops) t) ; :
`(3 ,(cond ((not target-faces) adoc-meta-face) ; target
((listp target-faces) `(if (string= (match-string 5) "") ; 5=attribute-list
,(car target-faces)
,(cadr target-faces)))
(t target-faces))
`(3 (list 'face
,(cond
((not target-faces) adoc-meta-face) ; target
((listp target-faces)
`(if (string= (match-string 5) "") ; 5=attribute-list
,(car target-faces)
,(cadr target-faces)))
(t target-faces))
'adoc-flyspell-ignore t)
,(if target-meta-p t 'append))
'(4 '(face adoc-meta-face adoc-reserved t . ,textprops) t) ; [
`(5 '(face adoc-meta-face adoc-attribute-list ,(or attribute-list t) . ,textprops) t)
Expand All @@ -1864,9 +1868,9 @@ TEXTPROPS is an additional plist with textproperties."
(let ((cmd-name (regexp-opt '("http" "https" "ftp" "file" "irc" "mailto" "callto" "link"))))
(list
`(lambda (end) (adoc-kwf-std end ,(adoc-re-inline-macro cmd-name) '(0) '(0)))
`(1 '(face adoc-internal-reference-face adoc-reserved t) t) ; cmd-name
`(1 '(face adoc-internal-reference-face adoc-reserved t adoc-flyspell-ignore t) t) ; cmd-name
`(2 '(face adoc-internal-reference-face adoc-reserved t) t) ; :
`(3 '(face adoc-internal-reference-face adoc-reserved t) t) ; target
`(3 '(face adoc-internal-reference-face adoc-reserved t adoc-flyspell-ignore t) t) ; target
'(4 '(face adoc-meta-face adoc-reserved t) t) ; [
`(5 '(face adoc-reference-face adoc-attribute-list adoc-reference-face) append)
'(6 '(face adoc-meta-face adoc-reserved t) t)))) ; ]
Expand All @@ -1875,9 +1879,9 @@ TEXTPROPS is an additional plist with textproperties."
(let ((cmd-name (regexp-opt '("http" "https" "ftp" "file" "irc" "mailto" "callto" "link"))))
(list
`(lambda (end) (adoc-kwf-std end ,(adoc-re-inline-macro cmd-name nil nil 'empty) '(0) '(0)))
'(1 '(face adoc-reference-face adoc-reserved t) append) ; cmd-name
'(1 '(face adoc-reference-face adoc-reserved t adoc-flyspell-ignore t) append) ; cmd-name
'(2 '(face adoc-reference-face adoc-reserved t) append) ; :
'(3 '(face adoc-reference-face adoc-reserved t) append) ; target
'(3 '(face adoc-reference-face adoc-reserved t adoc-flyspell-ignore t) append) ; target
'(4 '(face adoc-meta-face adoc-reserved t) t) ; [
; 5 = attriblist is empty
'(6 '(face adoc-meta-face adoc-reserved t) t)))) ; ]
Expand Down Expand Up @@ -1918,7 +1922,7 @@ TEXTPROPS is an additional plist with textproperties."
(both (concat "\\(?:" url "\\)\\|\\(?:" url<> "\\)\\|\\(?:" email "\\)")))
(list
`(lambda (end) (adoc-kwf-std end ,both '(0) '(0)))
'(0 '(face adoc-reference-face adoc-reserved t) append t))))
'(0 '(face adoc-reference-face adoc-reserved t adoc-flyspell-ignore t) append t))))

;; bug: escapes are not handled yet
;; TODO: give the inserted character a specific face. But I fear that is not
Expand Down Expand Up @@ -2258,8 +2262,8 @@ Use this function as matching function MATCHER in `font-lock-keywords'."
;; include
(list "^\\(\\(include1?::\\)\\([^ \t\n]*?\\)\\(\\[\\)\\(.*?\\)\\(\\]\\)\\)[ \t]*$"
'(1 '(face nil adoc-reserved block-del)) ; the whole match
'(2 adoc-preprocessor-face) ; macro name
'(3 adoc-delimiter) ; file name
'(2 '(face adoc-preprocessor-face adoc-flyspell-ignore t)) ; macro name
'(3 '(face adoc-delimiter adoc-flyspell-ignore t)) ; file name
'(4 adoc-hide-delimiter) ; [
'(5 adoc-delimiter) ; attribute list content
'(6 adoc-hide-delimiter)) ; ]
Expand All @@ -2284,9 +2288,9 @@ Use this function as matching function MATCHER in `font-lock-keywords'."
;; image. The first positional attribute is per definition 'alt', see
;; asciidoc manual, sub chapter 'Image macro attributes'.
(list `(lambda (end) (adoc-kwf-std end ,(adoc-re-block-macro "image") '(0)))
'(0 '(face adoc-meta-face adoc-reserved block-del keymap adoc-image-link-map) t) ; whole match
'(1 adoc-complex-replacement-face t) ; 'image'
'(2 adoc-internal-reference-face t) ; file name
'(0 '(face adoc-meta-face adoc-reserved block-del keymap adoc-image-link-map)) ; whole match
'(1 '(face adoc-complex-replacement-face adoc-flyspell-ignore t) t) ; 'image'
'(2 '(face adoc-internal-reference-face adoc-flyspell-ignore t) t) ; file name
'(3 '(face adoc-meta-face adoc-reserved nil adoc-attribute-list ("alt")) t)) ; attribute list

;; passthrough: (?u)^(?P<name>pass)::(?P<subslist>\S*?)(\[(?P<passtext>.*?)\])$
Expand All @@ -2295,7 +2299,7 @@ Use this function as matching function MATCHER in `font-lock-keywords'."
;; -- general block macro
(list `(lambda (end) (adoc-kwf-std end ,(adoc-re-block-macro) '(0)))
'(0 '(face adoc-meta-face adoc-reserved block-del)) ; whole match
'(1 adoc-command-face t) ; command name
'(1 '(face adoc-command-face adoc-flyspell-ignore t) t) ; command name
'(3 '(face adoc-meta-face adoc-reserved nil adoc-attribute-list t) t)) ; attribute list

;; lists
Expand Down Expand Up @@ -3745,7 +3749,7 @@ Turning on Adoc mode runs the normal hook `adoc-mode-hook'."
nil nil nil nil
(font-lock-multiline . t)
(font-lock-mark-block-function . adoc-font-lock-mark-block-function)))
(setq-local font-lock-extra-managed-props '(adoc-reserved adoc-attribute-list adoc-code-block))
(setq-local font-lock-extra-managed-props '(adoc-reserved adoc-attribute-list adoc-code-block adoc-flyspell-ignore))
(setq-local font-lock-unfontify-region-function 'adoc-unfontify-region-function)
(setq-local font-lock-extend-after-change-region-function #'adoc-font-lock-extend-after-change-region)

Expand Down Expand Up @@ -3783,6 +3787,19 @@ Turning on Adoc mode runs the normal hook `adoc-mode-hook'."
;;;; non-definitions evaluated during load
(adoc-calc)


;; Flyspell

(defun adoc-flyspell-p ()
"Function for `flyspell-mode-predicate' property of `adoc-mode'.
Returns t if word at point should be checked, nil otherwise."
(font-lock-ensure (line-beginning-position) (line-end-position))
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this needed? Seems kind of redundant to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Jit-Lock version of Font-lock is free to fontify only the visible part of the buffer if large yanks of text are inserted. flycheck-buffer on the other hand does not care about visibility. So we ensure that the adoc-flycheck-ignore property is correctly applied by font-lock-ensure.

Copy link
Owner

Choose a reason for hiding this comment

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

That would come with a performance hit, though, that's why I was wondering if it's really needed. I'm also not sure how often people use flyspell-buffer - e.g. I never use it myself.

I think at the very least we should add some note explaining the need for this, as I don't think that's obvious.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The performance hit is minimized by that junk of jit-lock-fontify-now:

	   (setq next (or (text-property-any start end 'fontified t)
			  end))

           ;; Avoid unnecessary work if the chunk is empty (bug#23278).
           (when (> next start)

(not (get-text-property
(1- (point)) ;; preceding word is checked, so 1- should do no harm
'adoc-flyspell-ignore)))

(put 'adoc-mode 'flyspell-mode-predicate 'adoc-flyspell-p)

(provide 'adoc-mode)

;; Local Variables:
Expand Down
Loading