vim-orgmode icon indicating copy to clipboard operation
vim-orgmode copied to clipboard

Vim spell checking does not work when filetype is set to org

Open tsahyt opened this issue 10 years ago • 6 comments

When setting up spell checking using setlocal spell spelllang=... as documented in the vim help files (spell.txt.gz, or :help spell) doesn't have an effect when the filetype is set to org. Once the spell checking is set with the above command, using :set ft= to disable orgmode enables the spell checking. Setting it back to org disables spell checking again. The commands related to spell checking don't have an effect when orgmode is enabled either.

This is a bit of a letdown, since I've found a nice use case for orgmode when outlining and drafting papers, and spell checking is an important step for me. I'm at a bit of a loss here since I don't know enough vimscript to track the problem down, but I thought I should report it anyway, since I'm pretty sure that this is not the intended behavior.

The problem occurs with Vim 7.4 on Fedora 22, vim-orgmode is installed via Vundle from this repository.

tsahyt avatar Jul 27 '15 09:07 tsahyt

Sorry for the late reply. I also noticed that spell highlighting doesn't work with orgmode as yet, possibly caused by the overlapping pattern in syntax highlighting. But spell correction command z= works fine in my case. May I ask if you are using the spell provided by vim or some other third-party spell plugin?

Ron89 avatar Mar 13 '16 15:03 Ron89

I'm using the spell checking provided by vim. I've just tried and z= does work for me as well. Some other commands like ]s do not work in general. I've noticed that ]s does jump to text misspelled inside of a TeX environment though.

tsahyt avatar Mar 15 '16 09:03 tsahyt

I see. I am pretty sure it's caused by conflict with the syntax file now. Because if I comment out everything in it, the misspell show corretly, and the keybindings you mention work again. I'll look into it when I'm available and fix it as soon as possible.

Ron89 avatar Mar 15 '16 09:03 Ron89

The issue is with SyntaxRange. As long as it is active, it will disable spell check unless the word is in the comment part of the code.

sdfasdf asdfasdf

#+BEGIN_SRC python
import numpy as np
np.linspace(1., 100, 50)
sdfas asfas
#wwwss asdfasdf
#+END_SRC

The randomly typed text outside of the code block will not be checked. Neither will the randomly texted code in the codeblock. Only the randomly texted code in the comment session of the code session will be recognized.

Since the issue is not caused by orgmode. We cannot fix the issue on our end. You may choose to uninstall SyntaxRange to avoid the issue from happening.

(Note: there was an independent issue in the syntax file undermining the code recognition of SyntaxRange. I discovered it while debugging your issue and that issue is fixed just now with the latest commit.)

Ron89 avatar Mar 17 '16 11:03 Ron89

The spell checking issue can be partially fixed by executing syntax spell toplevel(vim doc link) after the SyntaxRange#Include calls. Everything that is not syntax highlighted will then be spell checked.

Spellchecking for headers/list/code/verbatim can be achieve by adding contains=@Spell (or appending @Spell to the relevant syntax section in the org syntax file.

Kazy avatar Jul 27 '16 12:07 Kazy

I created bash script fixing syntax files. IT IS NOT PERFECT BUT IT IS GOOD. It can be reversed by running it again. It adds contains=@Spell to syn match and syn region definitions in all files in given directory.

To use it:

Save the script as fix_syntax_files.sh

  1. Give it permissions
  2. Change path at the bottom of the script to one corresponding to your vim plugins location
  3. Run the script
  4. (OPTIONAL) Run script again to revert the changes

The script makes a backup of all files before modification so you can assume it is safe to run it. I anyway do not take any responsibility for potential problems caused by the script.

Edit: You can leave feedback to the script in the following repository: https://github.com/dominikduda/config_files/blob/master/fix_syntax_files.sh

#!/bin/bash

function fix_file {
  sed -i -e '/exe/! {s/contains=/contains=@Spell,/g}' $1
  sed -i -e 's/contains=@Spell,ALL/contains=ALL/g' $1
  sed -i -e 's/contains=@Spell,ALLBUT/contains=ALLBUT/g' $1
  sed -i -e 's/contains=@Spell,TOP/contains=TOP/g' $1
  sed -i -e 's/contains=@Spell,CONTAINED/contains=CONTAINED/g' $1
  sed -i -e 's/contains=@Spell,NONE/contains=@Spell/g' $1
  sed -i -e '/^ *syn match/ {/contains=/! s/$/ contains=@Spell/g}' $1
  sed -i -e '/^ *syn region/ {/contains=/! s/$/ contains=@Spell/g}' $1
  return 0
}

function revert_file {
  mv "$1/$2.spellfix-backup" "$1/$2"
  return 0
}

function fix_recursively_in_catalog {
  syntax_catalogs_paths="$(find $1 -type d ! -name '*.*' -not -path '*git*' -print)"
  syntax_catalogs_count="$(echo "${syntax_catalogs_paths}" | wc -l)"

  echo "${syntax_catalogs_count} syntax catalogs found and will be scanned for files"

  echo "${syntax_catalogs_paths}" | while read -r catalog_path ; do
      echo "    Scanning $catalog_path"
      ls -p "${catalog_path}" | grep -v / | grep -v .spellfix-backup | grep .vim | while read -r file_name ; do
          cp "${catalog_path}/${file_name}" "${catalog_path}/${file_name}.spellfix-backup"
          fix_file "${catalog_path}/${file_name}"
          echo "        Fixing ${file_name} (backup created as ${file_name}.spellfix-backup)"
      done
  done
  echo 'Fix done.'
  echo 'Remember to REVERT FIX before updating vim plugins'
  return 0
}

function revert_recursively_in_catalog {
  syntax_catalogs_paths="$(find $1 -type d ! -name '*.*' -not -path '*git*' -print)"
  syntax_catalogs_count="$(echo "${syntax_catalogs_paths}" | wc -l)"

  echo "${syntax_catalogs_count} syntax catalogs found and will be scanned for spellfix-backup files"

  echo "${syntax_catalogs_paths}" | while read -r catalog_path ; do
      echo "    Scanning $catalog_path"
      ls -p "${catalog_path}" | grep -v / | grep -v .spellfix-backup | grep .vim | while read -r file_name ; do
          revert_file "${catalog_path}" "${file_name}"
          echo "        Reverting ${file_name} (from file ${file_name}.spellfix-backup)"
      done
  done
  echo 'Revert done.'
  echo 'Remember to FIX AGAIN after plugins update (or set it as a post update hook)'
  return 0
}

function main {
  syntax_catalogs_paths="$(find $1 -type d ! -name '*.*' -not -path '*git*' -print)"
  while read -r catalog_path ; do
      if ls -p "${catalog_path}" | grep -v / | grep .spellfix-backup; then
        echo ".spellfix-backup files found, reverting fix!"
        echo "--------------------------------------------"
        revert_recursively_in_catalog $1
        return 0
      fi
  done < <(echo "${syntax_catalogs_paths}")
  echo ".spellfix-backup files NOT found, fixing!"
  echo "-----------------------------------------"
  fix_recursively_in_catalog $1
}

main ~/PATH/TO/VIM/PLUGINS/

dominikduda avatar May 25 '17 18:05 dominikduda