Skip to content

use grammalecte-cli.py if available as a command #34

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 18 additions & 12 deletions autoload/grammalecte.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,24 @@ function s:GrammalecteSetUp() "{{{1
\ ? g:grammalecte_cli_py
\ : $HOME . '/grammalecte/pythonpath/cli.py'

if !filereadable(s:grammalecte_cli_py)
" Hmmm, can't find the python file. Try again with expand() in case user
" set it up as: let g:python_cli_py = '$HOME/grammalecte/pythonpath/cli.py'
let l:grammalecte_cli_py = expand(s:grammalecte_cli_py)
if !filereadable(expand(l:grammalecte_cli_py))
echomsg "Grammalecte cannot be found at: " . s:grammalecte_cli_py
echomsg "You need to install Grammalecte and/or set up g:grammalecte_cli_py"
echomsg "to indicate the location of the Grammalecte pythonpath/cli.py script."
return -1
if executable('grammalecte-cli.py')
" check if grammalecte-cli.py is available as an executable. if it is,
" there is no need to build a function like `python3 /path/to/cli.py`
let s:grammalecte_cmd = 'grammalecte-cli.py'
else
if !filereadable(s:grammalecte_cli_py)
" Hmmm, can't find the python file. Try again with expand() in case user
" set it up as: let g:python_cli_py = '$HOME/grammalecte/pythonpath/cli.py'
let l:grammalecte_cli_py = expand(s:grammalecte_cli_py)
if !filereadable(expand(l:grammalecte_cli_py))
echomsg "Grammalecte cannot be found at: " . s:grammalecte_cli_py
echomsg "You need to install Grammalecte and/or set up g:grammalecte_cli_py"
echomsg "to indicate the location of the Grammalecte pythonpath/cli.py script."
return -1
endif
let s:grammalecte_cli_py = l:grammalecte_cli_py
endif
let s:grammalecte_cli_py = l:grammalecte_cli_py
let s:grammalecte_cmd = 'python3 ' . l:grammalecte_cli_py
endif

endfunction
Expand Down Expand Up @@ -120,8 +127,7 @@ function grammalecte#Check(line1, line2) "{{{1
let l:range = a:line1 . ',' . a:line2
silent exe l:range . 'w! ++enc=utf8 ' . l:GrammalecteInputFile

let l:python = executable('python3') ? 'python3 ' : ''
let l:grammalecte_cmd = l:python . s:grammalecte_cli_py
let l:grammalecte_cmd = s:grammalecte_cmd
\ . ' --file_to_file ' . l:GrammalecteInputFile
\ . (empty(s:grammalecte_disable_rules) ? ' ' : (' --rule_off ' . s:grammalecte_disable_rules))
\ . ' --json --concat_lines --only_when_errors --context 2> ' . l:tmperror
Expand Down