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

Issues with flyspell mode in code blocks #311

Closed
phst opened this issue Jan 24, 2018 · 5 comments
Closed

Issues with flyspell mode in code blocks #311

phst opened this issue Jan 24, 2018 · 5 comments

Comments

@phst
Copy link
Contributor

phst commented Jan 24, 2018

Code in code blocks is incorrectly treated as spelling error by Flyspell.

Expected Behavior

Code in code blocks is never treated as spelling error.

Actual Behavior

Code in code blocks is occasionally treated as spelling error (see reproduction steps below).

Steps to Reproduce

  1. Start Emacs and load markdown-mode.
  2. Visit a nonexisting Markdown file.
  3. Enable flyspell-mode (M-x flyspell-mode)
  4. Insert a code block with nonexisting words, such as
    ```aaa
    bbb
    ```

"aaa" and "bbb" will now get the red Flyspell underline because they are spelling errors, but Flyspell should ignore code. Interestingly, markdown-flyspell-check-word-p returns nil inside the code block, i.e. it's detected correctly. Saving and then reverting the buffer using M-x revert-buffer doesn't help. Only turning Flyspell mode off and on again (by hitting M-x flyspell-mode twice) works.

Software Versions

  • Markdown Mode: From Git on 2018-01-24, version 2.4-dev
  • Emacs: GNU Emacs 27.0.50 (build 5, x86_64-pc-linux-gnu, GTK+ Version 3.22.24) of 2018-01-24
  • OS: Debian testing
@jrblevin
Copy link
Owner

Thanks for the report, however, I can't reproduce this. I tried first with my usual local configuration, which enables flyspell during my markdown-mode hook. Then I tried starting from emacs -Q -l markdown-mode.el. Both times, the code block was ignored. One difference is that I'm using Emacs 26.0.91, but that seems unlikely to make a difference.

@saf-dmitry
Copy link
Contributor

saf-dmitry commented Jan 26, 2018

I would assume (maybe I'm wrong), that when you type the code block symbol-by-symbol (instead copying and pasting is as a whole), then until the closing ticks have matched the opening ticks, it is still not recognized as a code block by Font Lock, and the corresponding text properties (e.g., markdown-pre) are not set. Flyspell puts its overlays over the "misspelled" words and those overlays will be removed by Flyspell when you toggle it off.

My suggestion is to define a function like

(defun markdown-remove-flyspell-overlays-in (begin end)
  "Remove Flyspell overlays in region between BEGIN and END."
  (and (bound-and-true-p flyspell-mode)
       (fboundp 'flyspell-delete-region-overlays)
       (flyspell-delete-region-overlays begin end)))

This function should be plugged into the Font Lock machinery and called after a code block (or other constructs, which should not be spell-checked) is fontified with the boundaries of this block.

@jrblevin
Copy link
Owner

I yanked the code block in, so it was recognized immediately, so this is probably why I couldn’t reproduce. I’ll double check. Thanks Dmitry for the function.

@saf-dmitry
Copy link
Contributor

I use a similar function in the TaskPaper mode (sorry for the shameless plug) to remove Flyspell overlays from the hashtags after their fontification. It does the job without any fuss.

@syohex
Copy link
Collaborator

syohex commented Jun 2, 2020

I have merged #501. Please check latest version.

@syohex syohex closed this as completed Jun 2, 2020
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

4 participants