Skip to content

Discuss about InitPurescript #80

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 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sw?
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
180 changes: 1 addition & 179 deletions doc/purescript-vim.txt
Original file line number Diff line number Diff line change
@@ -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*



Expand Down
54 changes: 22 additions & 32 deletions ftplugin/purescript.vim
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions generate-doc.sh
Original file line number Diff line number Diff line change
@@ -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