Die namespace, die

85 views
Skip to first unread message

Dave Ray

unread,
Jan 12, 2013, 9:09:13 PM1/12/13
to vimcl...@googlegroups.com
Hi,

Often when testing or working with multi-methods, I want to completely
obliterate a namespace and start from scratch. So I added this to my
.vim/after/ftplugin/clojure.vim:

function! s:ResetNamespace()
let ns = foreplay#ns()
" switch to neutral ground, kill the ns, switch back to the ns.
let cmd = "(in-ns 'clojure.core)(remove-ns '" . ns . ")(ns " . ns . ")"
echo cmd
try
call foreplay#eval(cmd)
catch /^Clojure:.*/
return ''
endtry
endfunction

" Command that brutally guts a namespace.
command! -buffer -bar ResetNamespace :call s:ResetNamespace()

It leaves the ns empty so you'll have to re-require.

Anyway, I've found it very useful, so I thought I'd share and solicit
feedback, especially on the lame VimL cribbed from foreplay.

Cheers,

Dave

Meikel Brandmeyer

unread,
Jan 14, 2013, 2:58:44 AM1/14/13
to vimcl...@googlegroups.com
Hi,

you might want to use in-ns instead of ns to switch back. Using ns sets up all reference to clojure.core which will lead to trouble in case you want special treatment there:

(ns foo.bar
  (:refer-clojure :exclude (==)))

Meikel

Meikel Brandmeyer

unread,
Jan 14, 2013, 2:59:18 AM1/14/13
to vimcl...@googlegroups.com
As a rule of thumb: ns is not about namespace switching.

Meikel

Dave Ray

unread,
Jan 14, 2013, 10:41:14 AM1/14/13
to vimcl...@googlegroups.com
Thanks Meikel. Good point. I try to avoid needing :refer-clojure if I
can help it so I don't think about it much :)

On Sun, Jan 13, 2013 at 11:59 PM, Meikel Brandmeyer <m...@kotka.de> wrote:
> As a rule of thumb: ns is not about namespace switching.
>
> Meikel
>
> --
> You received this message because you are subscribed to the Google Groups
> "vimclojure" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/vimclojure/-/gi070-uaqSAJ.
>
> To post to this group, send email to vimcl...@googlegroups.com.
> To unsubscribe from this group, send email to
> vimclojure+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/vimclojure?hl=en.

Oskar Kvist

unread,
Sep 11, 2013, 4:29:07 PM9/11/13
to vimcl...@googlegroups.com
I think you could also use https://github.com/clojure/tools.namespace 
I use it and it works great so far.
Reply all
Reply to author
Forward
0 new messages