Re: [proposal] Project Information for vim

2019-02-22 Fir de Conversatie skywind3000

> ### Modifiers
> 
> ```
> %:j- same as v:projectroot, project root directory of current buffer
> %:i- file path relative to current project root
> ```
> 
> These modifiers can be used in command line or passing to `expand(xxx)`.

More about modifiers:

- cd to the project root:

:cd %:j

- open netrw in the project root:

:Explore %:j

- open nerdtree in the project root:

:NERDTree %:j

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [proposal] Project Information for vim

2019-02-22 Fir de Conversatie Luc Hermitte
Hi

Very good initiative!

> ## Project Information
> 
> Vim can introduce a way to provide following information:
> [...]
> - buffer-local options
> [...]
> ### Locating project root
> 
> The project root of current file is the nearest parent directory with
> a folder named `.vimprj` (can be changed by set rootmarker=xxx) in
> it.
> 
> A buffer-specific variable `v:project` is used to store the project
> root directory of current buffer, it is initialized when you open a
> file as:
> 
> ```VimL
> let v:projectroot = fnamemodify(find(, '.;'), ':h')
> ```


I've experimented on the subject: 
https://github.com/luchermitte/lh-vim-lib/blob/master/doc/Project.md


What will be interesting is different than "buffer-local", it's 
"project-local". An option (/variable) changed in one buffer belonging to a 
project needs to be propagated to (or better shared with!) all buffers 
belonging to the same project.

This way, instead of a v:projectroot, it would be a p:projectroot, a 
p:where_the_build_directory_is, a p:where_ctags_plugin_will_build_tags_files, a 
p:naming_policy, and so on.


Regarding the remark about editor-config: there is no neat way to specify 
values for vim variables or options if need be. With the main editorconfig 
plugin for vim, we cannot be sure a variable will be set before another one 
which could be tedious to introduce dependencies.

-- 
Luc Hermitte

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [proposal] Project Information for vim

2019-02-22 Fir de Conversatie skywind3000
在 2019年2月22日星期五 UTC+8下午8:32:40,lith写道:
> While a basically agree, wrt
> 
> - root directory
> 
> Why not allow many root markers? Since a VCS directory is usually created in 
> the project's root directory, these VCS directories would be a natural 
> choice. The autoproject plugin[1] does it this way, and IMHO (but I'm biased 
> :-)) it works quite well. I think it would be a mistake to require the 
> existence of some magic marker.

The `.vimprj` folder is not only for root locating, but also used for storing 
project local setting files. Plugins will look into it for project-specific 
configuration.

Storing these files inside a VCS directory will pollute them. That's why vscode 
use a standalong `.vscode` folder.

But if you insist, you can also `set rootmarker=.git` and save configurations 
in your `.git` folder.

> 
> - file list
> 
> I'm not sure this should be provided by vim. Sooner or later you'd want to 
> cache this information. Then you'd have to check if the info is still up to 
> date. I'm not sure if this is within the scope of the standard vim 
> distribution. In this respect, one could ask whether vim should actually 
> provide the functionality or just define a standard api that is provided for 
> by a user-chosen plugin -- i.e. let one plugin provide filelists for 
> projects. One plugin uses more clever chaching, the other relies on this or 
> that external tool.
> 

This can be done by a vim script shipped with vim, including:

- return the file list.
- apis to manipulate the filelist (add/remove with glob).
- if `filelist` absents, but the project is inside a git repository, use `git 
ls-tree` to generate file list.


-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [proposal] Project Information for vim

2019-02-22 Fir de Conversatie lith
While a basically agree, wrt

- root directory

Why not allow many root markers? Since a VCS directory is usually created in 
the project's root directory, these VCS directories would be a natural choice. 
The autoproject plugin[1] does it this way, and IMHO (but I'm biased :-)) it 
works quite well. I think it would be a mistake to require the existence of 
some magic marker.

- file list

I'm not sure this should be provided by vim. Sooner or later you'd want to 
cache this information. Then you'd have to check if the info is still up to 
date. I'm not sure if this is within the scope of the standard vim 
distribution. In this respect, one could ask whether vim should actually 
provide the functionality or just define a standard api that is provided for by 
a user-chosen plugin -- i.e. let one plugin provide filelists for projects. One 
plugin uses more clever chaching, the other relies on this or that external 
tool.

E.g.

set project_roots_provider=foobar#GetProjectRoots
set project_filelist_provider=foobar#GetFileList
echo project_filelist(project_root("project name"))
" which would actually call foobar#GetFilelist()

- buffer-local options

If I got it right, the vim team tends towards EditorConfig for this?


[1] https://github.com/tomtom/autoproject_vim

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[proposal] Project Information for vim

2019-02-22 Fir de Conversatie skywind3000
Readable Page: 
https://github.com/skywind3000/vim-proposal/blob/master/project_info.md

Markdown plain text:

# Introducing VSCode's workspace mechanism

## Problem

https://github.com/vim/vim/issues/3573#issuecomment-433705924

> It would be great to have a standardized APIs for project-related information 
> (e.g. file lists, root directory, VCS type, a way to set project-specific 
> buffer-local options / variables etc.). Much of this can be implemented in 
> vim plugins but it would be preferable if vim provided a standard way to do 
> this.


## Project Information

Vim can introduce a way to provide following information:

- root directory
- file list
- buffer-local options

Plugins can have a place to store project-specific configurations:

- ctags/cscope parameters
- linter parameters
- include folders (c/c++)
- CFLAG / CXXFLAG / LDFLAGS (c/c++)
- actions: command to run, debug etc.


## Goals

- A way to locate project root (use root markers).
- A place for plugins to read project local configurations (like `.vscode` 
folder in vscode).
- A standard that plugins can follow even if running in old vims.
- Very simple to implement.


## Solution

Use something like vscode's `.vscode` folder:

```
project1
├── include
├── src
│   ├── module1
│   └── module2
└── .vscode  <- located in the project root directory
├── settings.json<- project-specific settings
└── tasks.json   <- how to "debug" this project or "build" this 
project
```

The `.vscode` folder in vscode is used to store project local settings and it 
locates in the project root directory. Every file inside `project1` will use 
the settings defined in `.vscode/settings.json`. And the `.vscode` folder can 
be used to locate project root for current file.

Similar to `.vscode`, this solution will start by defining a new `.vimprj` 
folder (the name is configurable).


### Root marker

Introduce a new option `rootmarker` for locating project root of current file, 
it defaults to `.vimprj` and can be set:

```VimL
set rootmarker=.vimprj
set rootmarker=.vscode
set rootmarker=.git
set rootmarker=.project
```

By default, there will be an `.vimprj` folder (can be renamed by `set 
rootmarker=xxx`) in your project root directory. Like vscode use a `.vscode` 
folder in every project root to store workspace settings. Plugins can put their 
project related configuration file in the `.vimprj` folder.


### Locating project root

The project root of current file is the nearest parent directory with a folder 
named `.vimprj` (can be changed by set rootmarker=xxx) in it.

A buffer-specific variable `v:project` is used to store the project root 
directory of current buffer, it is initialized when you open a file as:

```VimL
let v:projectroot = fnamemodify(find(, '.;'), ':h')
```

If `.vimprj` can not be found in the parent directories, an empty string will 
be used. For files already opened by vim, `v:projectroot` can be updated when 
you close the file and open again.

**Plugins can use the same algorithm to calculate project root directory even 
if running in old vims.**


### Modifiers

```
%:j- same as v:projectroot, project root directory of current buffer
%:i- file path relative to current project root
```

These modifiers can be used in command line or passing to `expand(xxx)`.


### Buffer local settings

Like `.vscode/settings.json` in vscode, if there is a `settings.json` file 
located in `.vimprj` folder, it will be loaded when you open a file in this 
project:

```json
{
"shiftwidth": 2,
"tabstop": 2,
"expandtab": false
}
```

Each key/value pair in `settings.json` will be initialized as a buffer local 
setting. 

**Alternative way** for this is to create a `local.vim` in the `.vimprj` folder 
and it will be sourced in `sandbox` for every file in the project.

This can be done by a vimscript shipped with vim (like matchit.vim).


### Old vim compatibility

Plugins running in old vims can calculate project root themself:

```VimL
if !exists('g:rootmarker')
let g:rootmarker = exists('+rootmarker')?  : ".vimprj"
endif
if !exists('v:projectroot')
let b:_project_root = fnamemodify(find(g:rootmarker, '.;'), ':h')
else
let b:_project_root = v:projectroot
endif
```

With this standard, even if running in old vims, plugin can get the project 
root directory of current file.


### File list

There can be a `.vimprj/filelist` file to describe the filelist in this project:

```
inc/interface.h
src/hello.c
src/world.c
src/module/xp.c
```

This file is optional, if it doesn't exist, all files inside root directory 
will be considered as project files.

If a plugin need generate ctags database for current project or need grep 
symbol in current project, the filelist can be used for that.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You