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

Modernize the plugin internals #19

Closed
wants to merge 62 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
8548333
Use json api instead of xml api
vigoux Aug 13, 2019
942553a
Change last change date
vigoux Aug 13, 2019
fcb0a0c
Tidy unused functions
vigoux Aug 14, 2019
13914ce
Use LT server to check
vigoux Aug 14, 2019
f245507
Remove custom buffer to use location list
vigoux Aug 14, 2019
0b75a64
refactor: moved functions to autoload
vigoux Aug 30, 2019
bf4bafc
feat: show error in preview window
vigoux Aug 30, 2019
7ab5e30
docs: update documentation
vigoux Aug 30, 2019
382d7d9
feat: better syntax highlighting
vigoux Aug 30, 2019
6acc7e2
docs: update README
vigoux Aug 31, 2019
5193f8f
perf: enhance setup process
vigoux Aug 31, 2019
4907bde
refactor: change function definitions
vigoux Aug 31, 2019
5851aaf
fix(syntax): fix Correction not highlighting
vigoux Aug 31, 2019
ec55418
fix(server): escape $
vigoux Aug 31, 2019
f470f36
refactor: improve error highlighting
vigoux Sep 3, 2019
3b45920
refactor(server): function to send request
vigoux Sep 3, 2019
2ff117e
feat: use server to know supported languages
vigoux Sep 3, 2019
136f543
feat: ability to fix the error at point
vigoux Sep 3, 2019
2cf56f0
docs: clarify :LanguageToolFixAtPoint doc
vigoux Sep 3, 2019
c690e0c
refactor(syntax): move hightlights to syntax file
vigoux Sep 3, 2019
298a4b4
docs: add tags file
vigoux Sep 3, 2019
c42716e
docs: fix spelling mistakes
vigoux Sep 3, 2019
925e65b
feat: add summary window
vigoux Sep 3, 2019
fdea04a
docs: add documentation to :LanguageToolSummary
vigoux Sep 3, 2019
2d0a470
fix(highlighting): fix wrong offsets
vigoux Sep 3, 2019
0b1b02b
fix: multiple use of :LanguageToolErrorAtPoint
vigoux Sep 3, 2019
dfbc356
fix: fixing errors at wrong lines
vigoux Sep 3, 2019
c92d6b1
fix: enhance error highlighting
vigoux Sep 4, 2019
75b79a4
feat: async check text
vigoux Sep 4, 2019
6090737
Update README.md
vigoux Sep 4, 2019
cdb9392
feat: navigate summary window more easily
vigoux Sep 4, 2019
f3b8533
Merge branch 'master' of github.com:vigoux/vim-LanguageTool
vigoux Sep 4, 2019
4ac7607
Update README.md
vigoux Sep 4, 2019
b6d7a24
Add asciinema example video
vigoux Sep 4, 2019
cb0d12e
Add usage example gif
vigoux Sep 4, 2019
fad9a41
Include usage example gif
vigoux Sep 4, 2019
f0c24fd
Rename LanguageTool.nvim
vigoux Sep 4, 2019
3b1e6a5
Change example gif to use asciinema url
vigoux Sep 4, 2019
0f8af31
Remove languagetool.gif
vigoux Sep 4, 2019
ed58a2e
feat: use data field for the server
vigoux Sep 4, 2019
1793b52
Merge branch 'master' of github.com:vigoux/LanguageTool.nvim
vigoux Sep 4, 2019
533136f
feat!(config): use dict as LT config tool
vigoux Sep 9, 2019
950b213
feat: add `<Plug>` mappings
vigoux Sep 10, 2019
b354908
feat: use LT data field instead of text
vigoux Sep 10, 2019
ab43c7b
feat: add test file
vigoux Sep 10, 2019
aec653f
feat: start using GitHub actions
vigoux Sep 10, 2019
bfb77a1
config: use docker to test
vigoux Sep 10, 2019
0d9e8b4
config: link plugin using env
vigoux Sep 10, 2019
06454eb
fix: update doc tags
vigoux Sep 10, 2019
e1c3ea4
config: enhance tests
vigoux Sep 10, 2019
035f6bd
config: don't use actions/checkout
vigoux Sep 10, 2019
e4b949a
config: output Vader to stdout
vigoux Sep 10, 2019
118f049
fix: ln not working
vigoux Sep 10, 2019
9cc5531
fix: stop trying using github actions
vigoux Sep 10, 2019
595f271
fix: remove tests folder
vigoux Sep 10, 2019
f6f0539
docs: update README.md
vigoux Sep 10, 2019
7c7a061
fix: fix lists in README.md
vigoux Sep 10, 2019
7e53272
fix: rename preview buffer
vigoux Sep 10, 2019
eeb3ef6
feat: add More category to errors
vigoux Sep 11, 2019
04a8607
feat: options to set summary/preview aspect
vigoux Sep 11, 2019
362634a
docs: add new options
vigoux Sep 11, 2019
3469f7f
docs: rename repo and changed maintainer
vigoux Sep 11, 2019
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
232 changes: 73 additions & 159 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vim-LanguageTool
----------------
LanguageTool.nvim
-----------------
[![asciicast](https://asciinema.org/a/265931.svg)](https://asciinema.org/a/265931)

This plugin integrates the LanguageTool grammar checker into Vim.
LanguageTool is an Open Source style and grammar checker for English,
Expand All @@ -15,79 +16,55 @@ LanguageTool. One advantage of the spelling checker of LanguageTool over
Vim spelling checker, is that it uses the native Hunspell dictionary directly,
so it works even with the latest Hunspell dictionaries containing features
not supported by Vim. For example, the latest French Hunspell dictionaries
from http://www.dicollecte.org are not supported by Vim but they work well
from http://www.dicollecte.org are not supported by Vim, but they work well
with LanguageTool. On the other hand, the Vim native spelling checker is
faster and better integrated with Vim.

See http://www.languagetool.org/ for more information about LanguageTool.

# Screenshots

These screenshots will give you an idea of what the LanguageTool plugin does:
English

![English](http://dominique.pelle.free.fr/pic/LanguageToolVimPlugin_en.png)

![French](http://dominique.pelle.free.fr/pic/LanguageToolVimPlugin_fr.png)

# Usage

* Use `:LanguageToolCheck` to check grammar in the current buffer.
This will check for grammar mistakes and highlight grammar or
spelling mistakes. It also opens a new scratch window with the
list of errors with further explanations about each error.
Pressing <Enter> in an error in the scratch buffer will jump to
that error in the text. The location list for the buffer being
spelling mistakes. The location list for the buffer being
checked is also populated, so you can use location commands
such as `:lopen` to open the location list window, `:lne` to
jump to the next error, etc.
The `:LanguageToolCheck` command accepts a range. You can for example check
grammar between lines 100 and 200 in buffer with `:100,200LanguageToolCheck`,
or check grammar in the visual selection with `:<',>'LanguageToolCheck`.
The default range is 1,$ (whole buffer).

* Use `:LanguageToolSummary` to open a summary window where you can navigate
errors using `]]` and `[[`, jump to them by hit `<CR>` and fix them by hitting
`f` on a suggestion.

* Use `:LanguageToolClear` to remove highlighting of grammar
mistakes, close the scratch window containing the list of errors,
clear and close the location list.

* Use `:help LanguageTool` to get more details on various commands
and configuration information.

The two commands are also available from the menu in gvim:
Some commands are also available from the menu in gvim:
```
Plugin -> LanguageTool -> Check
-> Clear
```

# Installing the Vim plugin
# Install

## Installing vim-LanguageTool with a plugin manager
## Installing LanguageTool.nvim

You can use any popular plugin manager according to your preference.
For example, with [Vundle](https://github.com/VundleVim/Vundle.vim),
For example, with [vim-plug](https://github.com/junegunn/vim-plug),
add this line in your `.vimrc`:
```
Plugin 'dpelle/vim-LanguageTool'

```

## Installing vim-LanguageTool without a plugin manager

If you don't use a plugin manager, copy those files in your `$HOME/.vim/`
directory:
```
.vim/plugin/LanguageTool.vim
.vim/doc/LanguageToo.doc

Plug 'vigoux/LanguageTool.nvim'
```
And run `vim -c 'helptags ~/.vim/doc'`.

# Download LanguageTool
## Download LanguageTool

To use this plugin, you need to install the Java LanguageTool grammar
checker. You can chose to:
checker. You can choose to:

* Download the stand-alone version of
* Download the standalone version of
LanguageTool(LanguageTool-\*.zip) from
[here](http://www.languagetool.org/) using the orange button labeled
"LanguageTool for standalone for your desktop".
Expand All @@ -102,138 +79,49 @@ checker. You can chose to:

Recent versions of LanguageTool require Java-8.

## Download the stand-alone version of LanguageTool

Download the stand-alone version of LanguageTool (LanguageTool-*.zip)
from http://www.languagetool.org/, click on "LanguageTool stand-alone
for your desktop" to download it. Unzip it:
```
$ unzip LanguageTool-3.6.zip
```
This should extract the file LanguageTool-3.6/languagetool-commandline.jar
among several other files.

## Build LanguageTool from sources in git

If you prefer to build LanguageTool yourself from sources, you first need
to install the pre-requisite packages. On Ubuntu, you need to install the
following packages:
```
$ sudo apt-get install openjdk-8-jdk mvn git
```
LanguageTool can then be downloaded and built with Maven as follows:
```
$ git clone https://github.com/languagetool-org/languagetool.git
$ cd languagetool
$ mvn clean package
```
After the build, the command line version of LanguageTool can be found in:
```
./languagetool-standalone/target/LanguageTool-3.7-SNAPSHOT/LanguageTool-3.7-SNAPSHOT/languagetool-commandline.jar
```
The version number in the path can vary.

# Configuration

LanguageTool plugin uses the character encoding from the 'fenc' option or from
the 'enc' option if 'fenc' is empty.

Several global variables can be set in your `.vimrc` to configure the behavior
of the LanguageTool plugin.

## `g:languagetool_jar`
## `g:languagetool_server`

This variable specifies the location of the LanguageTool java grammar
checker program. Default is empty.
Example:

```
:let g:languagetool_jar='$HOME/languagetool/languagetool-standalone/target/LanguageTool-3.7-SNAPSHOT/LanguageTool-3.7-SNAPSHOT/languagetool-commandline.jar'
```vim
:let g:languagetool_server='$HOME/languagetool/languagetool-standalone/target/LanguageTool-3.7-SNAPSHOT/LanguageTool-3.7-SNAPSHOT/languagetool-server.jar'
```

## `g:languagetool_lang`
## `g:languagetool`

This variable specifies the language code to use for the language tool checker.
If undefined, plugin tries to guess the language of the Vim spelling checker
'spelllang' or v:lang. If neither works, plugin defaults to English US (en-US).
For languages with variants (currently English German and Portuguese), it is
necessary to specify the variant in order for LanguageTool to signal spelling
errors. In other words, with :set spelllang=en LanguageTool only signals
grammar mistakes whereas with :set spellllang=en_us LanguageTool signals
spelling mistakes and grammar mistakes. The valid language codes are:
All LanguageTool configuration goes through this varaible, which is organized
as follows (all lists are comma separated):

```
ast Asturian
be Belarusian
br Breton
ca Catalan
cs Czech
da Danish
de German
de-AT German (Austria)
de-CH German (Switzerland)
de-DE German (Germany)
el Greek
en English
en-AU English (Australia)
en-CA English (Canada)
en-GB English (Great Britain)
en-NZ English (New Zealand)
en-US English (US)
en-ZA English (South Africa)
eo Esperanto
es Spanish
fa Persian
fr French
gl Galician
is Icelandic
it Italian
ja Japanese
km Khmer
lt Lithuanian
ml Malayalam
nl Dutch
pl Polish
pt Portuguese
pt-BR Portuguese (Brazil)
pt-PT Portuguese (Portugal)
ro Romanian
ru Russian
sk Slovak
sl Slovenian
sv Swedish
ta Tamil
tl Tagalog
uk Ukrainian
zh Chinese
```

## `g:languagetool_disable_rules`

This variable specifies checker rules which are disabled. Each disabled
rule must be comma separated.

Default value set by plugin is: WHITESPACE_RULE,EN_QUOTES

## `g:languagetool_enable_rules`
```vim
g:languagetool = {
'.' : {
{model1} for all filetypes
},
'my_filetype' : {
{model1} for my_filetype
}
}

This variable specifies checker rules which are enabled.

## `g:languagetool_disable_categories`

This variable specifies checker rule-categories which are disabled.

## `g:languagetool_enable_categories`

This variable specifies checker rule-categories which are enabled.

## `g:languagetool_win_height`
{model1} = {
'enabledRules' : list of enabled rules,
'disabledRules' : list of disabled rules,
'enabledCategories' : list of enabled categories,
'disabledCategories' : list of disabled categories,
'language' : the code of the language to check,
as given by :LanguageToolSupportedLanguages
}
```

This variable specifies the height of the scratch window which contains
all grammatical mistakes with some explanations. You can use a negative
value to disable opening the scratch window. You can also make it empty ''
to let Vim pick a default size.
Default is: 14
Actually, there is more options than those found here, you can found an
exhaustive list here :
https://languagetool.org/http-api/swagger-ui/#!/default/post_check

## Colors

Expand All @@ -250,14 +138,40 @@ For example, to highlight grammar mistakes in blue, and spelling mistakes in
red, with a curly underline in vim GUIs that support it, add this into your
colorscheme:

```
```vim
hi LanguageToolGrammarError guisp=blue gui=undercurl guifg=NONE guibg=NONE ctermfg=white ctermbg=blue term=underline cterm=none
hi LanguageToolSpellingError guisp=red gui=undercurl guifg=NONE guibg=NONE ctermfg=white ctermbg=red term=underline cterm=none
```

## Mappings

LanguageTool.nvim provides `<Plug>` mappings for a more convenient usage.

`<Plug>(LanguageToolCheck)` can be used in both normal and insert modes to run a check on current buffer.

## Events

`LanguageTool.nvim` triggers some `User` events:
- `LanguageToolCheckDone`, which is triggered right after a check is done
- `LanguageToolServerStarted`, which is triggered right after the server has started

# FAQ

## I want the summary window to open whenever a check is done.
Just add the following lines to you `.vimrc`:
```vim
autocmd User LanguageToolCheckDone LanguageToolSummary
```

## I want the server to start whenever I open a certain filetype
Add this to your `.vimrc` (this example is for `latex` files)
```vim
autocmd Filetype tex LanguageToolSetUp
```

# License

The VIM LICENSE applies to the LanguageTool.vim plugin (see
`:help copyright` but replace "LanguageTool.vim with "Vim").
The VIM LICENSE applies to the LanguageTool.nvim plugin (see
`:help copyright` but replace "LanguageTool.nvim" with "Vim").

LanguageTool is freely available under LGPL.
24 changes: 24 additions & 0 deletions after/ftplugin/languagetool.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
" LanguageTool: Grammar checker in Vim for English, French, German, etc.
" Maintainer: Thomas Vigouroux <[email protected]>
" Last Change: 2019 Sep 11
" Version: 1.0
"
" License: {{{1
"
" The VIM LICENSE applies to LanguageTool.nvim plugin
" (see ":help copyright" except use "LanguageTool.nvim" instead of "Vim").
"
" }}} 1

setlocal foldmethod=syntax
let b:undo_ftplugin += "setlocal foldmethod<"

nnoremap <buffer><silent> <CR> :call LanguageTool#errors#jumpToCurrentError()<CR>
nnoremap <buffer><silent> f
\ :call LanguageTool#errors#fix(
\ LanguageTool#errors#errorAtPoint(),
\ LanguageTool#errors#suggestionAtPoint())<CR>
nnoremap <buffer><silent> ]] :execute LanguageTool#errors#nextSummary()<CR>
nnoremap <buffer><silent> [[ :execute LanguageTool#errors#previousSummary()<CR>

normal zx
Loading