diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..45d62d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.sw? diff --git a/README.md b/README.md index cb4b2c1..fb71b92 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,14 @@ Save and restart (neo)vim and run `:PlugInstall`. To configure indentation in `purescript-vim` you can use the following variables: +#### g:purescript_set_root + +if set to true, the `path` option and `K` command will be set properly. + +```vim +let g:purescript_disable_indent = v:true +``` + #### g:purescript_disable_indent Disable indentation altogether. diff --git a/doc/purescript-vim.txt b/doc/purescript-vim.txt index 3307536..6e79316 100644 --- a/doc/purescript-vim.txt +++ b/doc/purescript-vim.txt @@ -1,182 +1,4 @@ -*purescript-vim.txt* [![Maintainer: vladciobanu](https://img.shields.io/badge/maintainer-vladciobanu-lightgrey.svg)](http://github.com/vladciobanu) - -|purescript-intro| purescript-vim -|purescript-Installation| Installation -|purescript-Manual-Installation-no-plugin-manager| Manual Installation (no plugin manager) -|purescript-Vim-8-packages| Vim 8 packages -|purescript-Pathogen| Pathogen -|purescript-vim-plug| vim-plug -|purescript-Configuration| Configuration -|purescript-Indentation| Indentation -|purescript-g-purescript_disable_indent| g:purescript_disable_indent -|purescript-g-purescript_indent_case| g:purescript_indent_case -|purescript-g-purescript_indent_let| g:purescript_indent_let -|purescript-g-purescript_indent_in| g:purescript_indent_in -|purescript-g-purescript_indent_where| g:purescript_indent_where -|purescript-g-purescript_indent_do| g:purescript_indent_do -|purescript-g-purescript_indent_dot| g:purescript_indent_dot -|purescript-Contributing| Contributing - -PURESCRIPT-VIM *purescript-intro* - -[![Maintainer: vladciobanu](https://img.shields.io/badge/maintainer-vladciobanu-lightgrey.svg)](http://github.com/vladciobanu) - -[Purescript][] language support for vim and neovim providing syntax highlighting and indentation based on based on [idris-vim][] and [haskell-vim][]. - -See [purescript-language-server][] for details on how to set up language server support for [Purescript][]. - - -INSTALLATION *purescript-Installation* - - -MANUAL INSTALLATION (NO PLUGIN MANAGER) *purescript-Manual-Installation-no-plugin-manager* - -Copy content of this repository into your `~/.vim` directory (or `%HOME%\vimfiles` on Windows). - -Be sure that the following lines are in your `.vimrc` - -> - syntax on - filetype on - filetype plugin indent on -< - - -VIM 8 PACKAGES *purescript-Vim-8-packages* - -If you have vim version 8 (`vim --version | head -n1`), you can install plugins with the native pack system: - -> - mkdir -p ~/.vim/pack/plugins/start/ - cd ~/.vim/pack/plugins/start/ - git clone https://github.com/purescript-contrib/purescript-vim.git -< - - -PATHOGEN *purescript-Pathogen* - -If you are using [Pathogen][], clone this repo into your `~/.vim/bundle` directory and you are ready to go. - -> - cd ~/.vim/bundle - git clone https://github.com/purescript-contrib/purescript-vim.git -< - - -VIM-PLUG *purescript-vim-plug* - -If you are using [vim-plug][], add the following line in between your `plug#begin` and `plug#end` calls for your vim config file: - -> - Plug 'purescript-contrib/purescript-vim' -< - -Save and restart (neo)vim and run `:PlugInstall`. - - -CONFIGURATION *purescript-Configuration* - - -INDENTATION *purescript-Indentation* - -To configure indentation in `purescript-vim` you can use the following variables: - - -G:PURESCRIPT_DISABLE_INDENT *purescript-g-purescript_disable_indent* - -Disable indentation altogether. - -> - let g:purescript_disable_indent = 1 -< - - -G:PURESCRIPT_INDENT_CASE *purescript-g-purescript_indent_case* - -> - let g:purescript_indent_case = 5 -< - -> - case xs of - >>>>>[] -> ... - >>>>>(y:ys) -> ... -< - - -G:PURESCRIPT_INDENT_LET *purescript-g-purescript_indent_let* - -> - let g:purescript_indent_let = 4 -< - -> - let x = 0 in - >>>>x -< - - -G:PURESCRIPT_INDENT_IN *purescript-g-purescript_indent_in* - -> - let g:purescript_indent_in = 1 -< - -> - let x = 0 - >in x -< - - -G:PURESCRIPT_INDENT_WHERE *purescript-g-purescript_indent_where* - -> - let g:purescript_indent_where = 6 -< - -> - where f :: Int -> Int - >>>>>>f x = x -< - - -G:PURESCRIPT_INDENT_DO *purescript-g-purescript_indent_do* - -> - let g:purescript_indent_do = 3 -< - -> - do x <- a - >>>y <- b -< - - -G:PURESCRIPT_INDENT_DOT *purescript-g-purescript_indent_dot* - -> - let g:purescript_indent_dot = 1 -< - -> - unsnoc - :: forall a - >. List a - -> Maybe (List a, a) -< - - -CONTRIBUTING *purescript-Contributing* - -Contributing checklist: - -[ ] Opened an issue before investing a significant amount of work into changes - -[ ] Update README.md with any new configuration options and behavior - -[ ] Update CHANGELOG.md with the proposed changes - -[ ] Run `generate-doc.sh` to re-generate the documentation +*.txt* diff --git a/ftplugin/purescript.vim b/ftplugin/purescript.vim index be2760a..91c9728 100644 --- a/ftplugin/purescript.vim +++ b/ftplugin/purescript.vim @@ -1,39 +1,29 @@ +" vim: sw=2 et + +if exists("*PureScriptSetRoot") | finish | endif + setlocal comments=s1fl:{-,mb:\ \ ,ex:-},:--\ \|,:-- setlocal commentstring=--\ %s setlocal include=^import -setlocal includeexpr=printf('%s.purs',substitute(v:fname,'\\.','/','g')) - -let s:PS = [] -fun! InitPureScript() - let dirs = map( - \ findfile("psc-package.json", expand("%:p:h") . ";/", -1), - \ { idx, val -> fnamemodify(val, ":p:h") } - \ ) - if empty(dirs) - let dirs = map( - \ findfile("bower.json", expand("%:p:h") . ";/", -1), - \ { idx, val -> fnamemodify(val, ":p:h") } - \ ) - if empty(dirs) - return - endif - endif +setlocal includeexpr=substitute(v:fname,'\\.','/','g')).'.purs' +setlocal efm=%Eat\ %f:%l:%c\ -\ %m - let path = expand("%:p") - for p in s:PS - if stridx(path, p[0], 0) == 0 - let &l:path=p[1] - return - endif +fun PureScriptSetRoot() + " search forward and backward (;) for the root of the project + " (a dir containing any configuration file) + let l:from_here = expand("%:p:h") . ";" + for l:conf in ["spago.dhall"] + let l:root = get(map( + \ findfile(l:conf,l:from_here, -1) , + \ { name -> fnamemodify(name,":p:h") } ),-1,'') + if !empty(l:root) | continue | endif endfor + if empty(l:root) | return | endif + exec 'setlocal path+='.l:root.'/src/**' +endfun - let dir = dirs[len(dirs) - 1] - let gp = globpath(dir, "src/**/*.purs", v:true, v:true) - if empty(gp) - return +if exists('g:purescript_set_root') + if g:purescript_set_root + call InitPureScript() endif - - let &l:path=join([dir, dir . "/bower_components/**", dir . "/src/**"], ",") - call add(s:PS, [dir, &l:path]) -endfun -call InitPureScript() +endif diff --git a/generate-doc.sh b/generate-doc.sh index a75ea18..b32c6cf 100755 --- a/generate-doc.sh +++ b/generate-doc.sh @@ -1,2 +1,2 @@ -#!/usr/bin/env sh -cat README.md | npx github:mklabs/vim-markdown-helpfile > doc/purescript-vim.txt +#!/bin/sh +< README.md npx github:mklabs/vim-markdown-helpfile > doc/purescript-vim.txt