Skip to content

Commit

Permalink
Improve vim script, use autoload, improve instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Jun 5, 2015
1 parent 45a1b67 commit c455fe5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
6 changes: 6 additions & 0 deletions Makefile
Expand Up @@ -43,6 +43,12 @@ install: $(PROJECTS) man
tools/emacs-setup.sh $(datarootdir)/emacs/site-lisp; \
echo; \
fi
@if $$(which vim >/dev/null); then \
echo "== Vim configuration =="; \
echo "Add the following to your .vimrc:"; \
echo " set rtp+=$(datarootdir)/ocp-index/vim"; \
echo; \
fi

.PHONY: clean
clean: ocp-build.root
Expand Down
7 changes: 5 additions & 2 deletions ocp-index.install
Expand Up @@ -18,7 +18,10 @@ man: [
"?man/man1/ocp-index.1"
"?man/man1/ocp-browser.1"
]
share_root: [
"tools/ocp-index.el" {"emacs/site-lisp/ocp-index.el"}
]
share: [
"tools/ocp-index.el" {"../emacs/site-lisp/ocp-index.el"}
"tools/ocp-index.vim" {"../vim/syntax/ocpindex.vim"}
"tools/ocp-index.vim" {"vim/autoload/ocpindex.vim"}
"tools/autoload.vim" {"vim/ftplugin/ocaml.vim"}
]
13 changes: 10 additions & 3 deletions opam
Expand Up @@ -28,6 +28,13 @@ depopts: "lambda-term"
conflicts: "lambda-term" {< "1.7"}
available: [ocaml-version >= "4.00.0"]
messages: "To install ocp-browser, please install lambda-term" {! lambda-term:installed}
post-messages: "To use ocp-index from emacs, add the following to your .emacs:
(add-to-list 'load-path \"%{share}%/emacs/site-lisp\")
(require 'ocp-index)" {success}
post-messages:
"This package requires additional configuration for use in editors. Either install package 'user-setup', or manually:

* for Emacs, add these lines to ~/.emacs:
(add-to-list 'load-path \"%{prefix}%/share/emacs/site-lisp\")
(require 'ocp-index)

* for Vim, add the following line to ~/.vimrc:
set rtp+=%{share}%/ocp-index/vim
" {success & !user-setup:installed}
2 changes: 2 additions & 0 deletions tools/autoload.vim
@@ -0,0 +1,2 @@
" Activate ocp-index on current buffer
call ocpindex#init()
3 changes: 2 additions & 1 deletion tools/emacs-setup.sh
Expand Up @@ -26,7 +26,8 @@ if ! check_eldir; then
exit 2
fi

echo "To setup tuareg-mode (or ocaml-mode) to use ocp-index for completion,"
echo "== Emacs configuration =="
echo "To setup tuareg-mode (or caml-mode) to use ocp-index for completion,"
echo "please add the following to your .emacs :"
echo
if [ "${eldir#/usr/}" = "$eldir" ]; then
Expand Down
18 changes: 4 additions & 14 deletions tools/ocp-index.vim
Expand Up @@ -2,7 +2,10 @@
" Maintainer: INAJIMA Daisuke <inajima@sopht.jp>
" Version: 0.1

let s:ocaml_lib_dir = ""
if exists("g:loaded_ocpindex")
finish
endif
let g:loaded_ocpindex = 1

let s:jump_history = []
let s:max_jump_history = 100
Expand All @@ -13,10 +16,6 @@ function! ocpindex#init()
return
endif

if executable("ocamlc") == 1
let s:ocaml_lib_dir = substitute(system('ocamlc -where'), '\n$', '', '')
endif

setlocal omnifunc=ocpindex#complete
endfunction

Expand All @@ -36,15 +35,6 @@ function! s:ocp_index(cmd, arg)
\ '--context', ':', '-F',
\ shellescape(substitute(expand('%:t:r'), '^\w', '\u\0', ''))]

" If build directory is not found, specify ocaml lib directory as both
" build and root directory. ocp-index's build/root path detection routine
" seems to be broken.
if finddir('_build', '.;') == "" && finddir('_obuild', '.;') == "" &&
\ findfile('OMakeroot', '.;') == ""
let d = shellescape(s:ocaml_lib_dir)
call extend(cmdline, ['--build', d, '--root', d])
endif

call add(cmdline, shellescape(a:arg))
return system(join(cmdline), context)
endfunction
Expand Down

0 comments on commit c455fe5

Please sign in to comment.