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

Add new GoProject command #14

Open
wants to merge 1 commit into
base: master
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
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
## News
* New command ``GoProject`` to select a project from the ``cmdline mode``
* [New feature](#callbacks) ``project#utils#alternate``. To alternate between `file.ext` and
``file_suffix.ext`` or ``fileSuffix.ext`` with the command ``:A``
* [Windows support added](https://twitter.com/amiorin/status/336003331984076800)

## Introduction
A Project is made of :
* One directory (the ``root of the project``)
* One title (by default the last part of the the ``root of the project``)
* One title (by default the last part of the ``root of the project``)
* One or more ``callbacks``

Everytime you open a file nested in the ``root of the project``
Every time you open a file nested in the ``root of the project``
* the ``local current directory`` is changed to the ``root of the project``
* the ``guitablabel`` is set to the ``title`` of the project
* the ``callbacks`` of the project are executed

![img][0]

## Commands
There are four commands :
There are five commands :
* ``Project``
It's used inside the ``.vimrc``. The first parameter is the ``path`` to the
project. The second parameter is optional and it is the ``title`` of the
Expand Down Expand Up @@ -48,9 +49,13 @@ doesn't change the ``local current directory``.
It's used inside the ``.vimrc``. The first parameter is the ``title`` of a
project already defined with ``Project`` or ``File``. The second parameter is
the name a function or an array of function names. This function or these
functions are callbacks and they are executed everytime a file nested in the
functions are callbacks and they are executed every time a file nested in the
``root of the project`` is opened with **one parameter** that is the ``title``
of the project.
* ``GoProject``
It's used inside the ``cmdline mode`` to switch to one of the defined projects.
The required parameter is the ``title`` of the project without quotation. Completion
is supported.
* ``Welcome`` It's the [``Startify``](https://github.com/mhinz/vim-startify) equivalent.
If you don't want ``Welcome`` to appear when you start vim:

Expand Down Expand Up @@ -88,7 +93,7 @@ Project 'nugg.ad/nuggad-compiler'

" project#utils#alternate returns a dictionary with a method ``invoke(title)``.
"
" everytime we open a file inside the project if the path starts with
" every time we open a file inside the project if the path starts with
" ``spec`` or ``src`` the commands :A are defined.
"
" +_spec means add _spec to the file
Expand Down
3 changes: 3 additions & 0 deletions autoload/project.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ command! -complete=file -nargs=+ ProjectPath
command! -nargs=0 -bar Welcome
\ enew | call project#config#welcome()

command! -nargs=1 -complete=custom,project#config#choices GoProject
\ call project#config#goto(<q-args>)

if has("gui_running")
function! TabTitle()
let title = expand("%:p:t")
Expand Down
24 changes: 24 additions & 0 deletions autoload/project/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ function! project#config#welcome() abort
call cursor(special ? 4 : 2, 5)
endfunction

function! project#config#goto(title) abort
if has_key(s:projects, a:title)
let v = s:projects[a:title]
if v["type"] == "project"
let file = v["project"]
let lcd = " | lcd ".v["project"]
else
let file = v["event"]
let lcd = ""
endif
if get(g:, 'project_use_nerdtree', 0) && isdirectory(file)
execute 'enew | NERDTree '. s:escape(file).lcd
else
execute 'edit '. s:escape(file).lcd
endif
else
echo 'Unknown project ' . a:title
endif
endfunction

function! project#config#choices(ArgLead, CmdLine, CursorPos) abort
return join(sort(keys(s:projects)), "\n")
endfunction

function! s:escape(path) abort
return !exists('+shellslash') || &shellslash ? fnameescape(a:path) : escape(a:path, '\')
endfunction
Expand Down