chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Scheme Code beautifier


From: Imran Rafique
Subject: Re: [Chicken-users] Scheme Code beautifier
Date: Fri, 3 Dec 2010 15:56:10 -0800

Christian,

I don't think calling an outside script is really necessary for vim.
When the cursor is on the opening parenthesis of an sexpr, then =%
will reformat the entire sexpr correctly (of course, you need to make
sure that 'lispwords' setting is up to date)

If it helps, here are a couple of vimscript functions I use to quickly
reformat code. As I code in different lisp dialects (chicken, and
clojure), these functions are in
~/.vim/after/ftplugin/common/lisp.vim, which is sourced by
after/ftplugin/scheme.vim or after/ftplugin/clojure.vim.

(PS: I stick my name in variables and functions I define in vim, to
avoid possible namespace clashes with other plugins)
(PPS: It feels somehow dirty posting some vimscript to a scheme mailing list)


----{ ~/.vim/after/ftplugin/scheme.vim }----
let b:imran_lisp_funcname = "define"
source $HOME/.vim/after/ftplugin/common/lisp.vim
----{ end snippet }----


----{ ~/.vim/after/ftplugin/common/lisp.vim }----
" ==== init 
===================================================================={{{1
" common ftplugin code for all lisps
" requires the following variables to be set
" b:imran_lisp_funcname = (string) lowest common denominator string
which matches command to create definitions

" ==== indentation
============================================================={{{1
" fix indentation for everything, starting from the topmost sexpr
function! ImranLispIndentAll()
        let l:cursor = getpos('.')
        silent! exec "normal! 999[(=%"
        call setpos('.', l:cursor)
endfunction
nmap <Leader>=t :call ImranLispIndentAll()<CR>

" fix indention for the current function only
function! ImranLispIndentCurrentFunction()
        let l:cursor = getpos('.')
        call search('(' . b:imran_lisp_funcname , 'bcW')
        silent! exec "normal! =%"
        call setpos('.', l:cursor)
endfunction
nmap <Leader>=f :call ImranLispIndentCurrentFunction()<CR>
nmap <Leader>== :call ImranLispIndentCurrentFunction()<CR>

----{ end snippet }----


--
Regards,
       Imran Rafique

(skype: imran_rafique)



On 1 December 2010 00:12, Christian Kellermann <address@hidden> wrote:
> Hi,
>
> funny this also came up in a discussion with a friend that uses vi.
> So for him this snippet now does the job:
>
> $ cat scheme-indent.scm
> (use extras)
> (let loop ((sexpr (read)))
>  (unless (equal? sexpr #!eof)
>    (pp sexpr)(newline)
>    (loop (read))))
>
> Called with {!}scheme-indent on a paragraph.
>
> HTH,
>
> Christian
>
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/chicken-users
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]