caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Jumping to matching keywords with % in Vim
@ 2003-11-17 11:30 Issac Trotts
  2003-11-17 16:15 ` Aleksey Nogin
  2003-11-17 16:40 ` [Caml-list] vim - switching between .ml and .mli Stefano Zacchiroli
  0 siblings, 2 replies; 4+ messages in thread
From: Issac Trotts @ 2003-11-17 11:30 UTC (permalink / raw)
  To: caml-list

For those who use Vim and have the matchit.vim plugin installed,
here are a few lines to put in $HOME/.vim/ftplugin/ocaml.vim :

let b:mw='\<let\>:\<and\>:\(\<in\>\|;;\),'
let b:mw=b:mw . '\<if\>:\<then\>:\<else\>,\<do\>:\<done\>,'
let b:mw=b:mw . '\<\(object\|sig\|struct\|begin\)\>:\<end\>'
let b:match_words=mw

Then the percent key jumps between begin...end, let...in, etc.  

The only problem I've encountered with it is that it doesn't
go back to 'if' from 'then' when the 'else' clause is missing.
If someone knows how to fix this, I'd like to know.

-- 
Issac Trotts
Programmer
Center for Neuroscience
University of California, Davis 

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Jumping to matching keywords with % in Vim
  2003-11-17 11:30 [Caml-list] Jumping to matching keywords with % in Vim Issac Trotts
@ 2003-11-17 16:15 ` Aleksey Nogin
  2003-11-17 16:48   ` Issac Trotts
  2003-11-17 16:40 ` [Caml-list] vim - switching between .ml and .mli Stefano Zacchiroli
  1 sibling, 1 reply; 4+ messages in thread
From: Aleksey Nogin @ 2003-11-17 16:15 UTC (permalink / raw)
  To: Caml List

On 17.11.2003 03:30, Issac Trotts wrote:

> For those who use Vim and have the matchit.vim plugin installed,
> here are a few lines to put in $HOME/.vim/ftplugin/ocaml.vim :
> 
> let b:mw='\<let\>:\<and\>:\(\<in\>\|;;\),'
> let b:mw=b:mw . '\<if\>:\<then\>:\<else\>,\<do\>:\<done\>,'
> let b:mw=b:mw . '\<\(object\|sig\|struct\|begin\)\>:\<end\>'
> let b:match_words=mw
> 
> Then the percent key jumps between begin...end, let...in, etc.  

Thanks, it's really cool! The only thing - it should be "let 
b:match_words=b:mw", not "let b:match_words=mw" (at least for me in vim 
6.2.121 it does not work otherwise).

-- 
Aleksey Nogin

Home Page: http://nogin.org/
E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal)
Office: Jorgensen 70, tel: (626) 395-2907

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Caml-list] vim - switching between .ml and .mli
  2003-11-17 11:30 [Caml-list] Jumping to matching keywords with % in Vim Issac Trotts
  2003-11-17 16:15 ` Aleksey Nogin
@ 2003-11-17 16:40 ` Stefano Zacchiroli
  1 sibling, 0 replies; 4+ messages in thread
From: Stefano Zacchiroli @ 2003-11-17 16:40 UTC (permalink / raw)
  To: caml-list

On Mon, Nov 17, 2003 at 03:30:30AM -0800, Issac Trotts wrote:
> For those who use Vim and have the matchit.vim plugin installed,
> here are a few lines to put in $HOME/.vim/ftplugin/ocaml.vim :

Thanks! This is what I offer in exchange: support for switching from .ml
to .mli with ",s" and ",S" (the latter split a new window). It requires
vim-python in order to remember the previous position in a file:

    " switching between interfaces (.mli) and implementations (.ml)
  if !exists("g:did_ocaml_switch") && has("python")
    let g:did_ocaml_switch = 1
    map ,s :call OCaml_switch_switch()<CR>
    map ,S :call OCaml_switch_switch_new()<CR>
    fun OCaml_switch_pynit()
      python << EOF
  import vim
  positions = {}
  def ocaml_save_position():
      positions[vim.current.buffer.name] = vim.current.window.cursor
  def ocaml_restore_position():
      try:
          vim.current.window.cursor = positions[vim.current.buffer.name]
      except KeyError:
          pass
  EOF
    endfun
    call OCaml_switch_pynit()
    fun OCaml_switch_switch()
      if (match(bufname(""), "\\.mli$") >= 0)
        python ocaml_save_position()
        exec "edit " . substitute(bufname(""), "\\.mli$", ".ml", "")
        python ocaml_restore_position()
      elseif (match(bufname(""), "\\.ml$") >= 0)
        python ocaml_save_position()
        exec "edit " . bufname("") . "i"
        python ocaml_restore_position()
      endif
    endfun
    fun OCaml_switch_switch_new()  " as above but in a new window
      if (match(bufname(""), "\\.mli$") >= 0)
        python ocaml_save_position()
        exec "new " . substitute(bufname(""), "\\.mli$", ".ml", "")
        python ocaml_restore_position()
      elseif (match(bufname(""), "\\.ml$") >= 0)
        python ocaml_save_position()
        exec "new " . bufname("") . "i"
        python ocaml_restore_position()
      endif
    endfun
  endif

-- 
^Stefano Zacchiroli -- Master in Computer Science @ Uni. Bologna, Italy$
^zack@{cs.unibo.it,debian.org,bononia.it} -- http://www.bononia.it/zack$
^Frequentando il mio maestro mi ero reso conto [.] che la logica poteva$
^servire a molto a condizione di entrarci dentro e poi di uscirne -Adso$

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Jumping to matching keywords with % in Vim
  2003-11-17 16:15 ` Aleksey Nogin
@ 2003-11-17 16:48   ` Issac Trotts
  0 siblings, 0 replies; 4+ messages in thread
From: Issac Trotts @ 2003-11-17 16:48 UTC (permalink / raw)
  To: caml-list

On Mon, Nov 17, 2003 at 08:15:03AM -0800, Aleksey Nogin wrote:
> On 17.11.2003 03:30, Issac Trotts wrote:
> 
> >For those who use Vim and have the matchit.vim plugin installed,
> >here are a few lines to put in $HOME/.vim/ftplugin/ocaml.vim :
> >
> >let b:mw='\<let\>:\<and\>:\(\<in\>\|;;\),'
> >let b:mw=b:mw . '\<if\>:\<then\>:\<else\>,\<do\>:\<done\>,'
> >let b:mw=b:mw . '\<\(object\|sig\|struct\|begin\)\>:\<end\>'
> >let b:match_words=mw
> >
> >Then the percent key jumps between begin...end, let...in, etc.  
> 
> Thanks, it's really cool! The only thing - it should be "let 
> b:match_words=b:mw", not "let b:match_words=mw" (at least for me in vim 
> 6.2.121 it does not work otherwise).

Sure.  Thanks for pointing out my typo.  I forgot to fix it.

-- 
Issac Trotts
Programmer
Center for Neuroscience
University of California, Davis 

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-11-17 16:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-17 11:30 [Caml-list] Jumping to matching keywords with % in Vim Issac Trotts
2003-11-17 16:15 ` Aleksey Nogin
2003-11-17 16:48   ` Issac Trotts
2003-11-17 16:40 ` [Caml-list] vim - switching between .ml and .mli Stefano Zacchiroli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).