Difference between revisions of "Vim"

From HaskellWiki
Jump to navigation Jump to search
(Created page, filled it with plugins "module section", "module header")
 
m
Line 32: Line 32:
   
 
== Module Headers ==
 
== Module Headers ==
The following code prompts for module name, a note, a description of module, and places a section with that name at top, when key sequence "--h":
+
The following code prompts for module name, a note, a description of module, and places a module comment at top, when key sequence "--h":
 
<pre>
 
<pre>
 
let s:width = 80
 
let s:width = 80

Revision as of 11:43, 7 August 2011

This page intended Haskell vim-users.


Plugins

Put code in file ~/.vim/plugin/Haskell.vim, or in multiple files in that directory.

Module Sections

The following code prompts for a name, and places a section with that name at current position, when key sequence "--s":

let s:width = 80

function! HaskellModuleSection(...)
    let name = 0 < a:0 ? a:1 : inputdialog("Section name: ")

    return  repeat('-', s:width) . "\n"
    \       . "--  " . name . "\n"
    \       . "\n"

endfunction

nmap <silent> --s "=HaskellModuleSection()<CR>gp

Like so:

--------------------------------------------------------------------------------
--  my section


Module Headers

The following code prompts for module name, a note, a description of module, and places a module comment at top, when key sequence "--h":

let s:width = 80


function! HaskellModuleHeader(...)
    let name = 0 < a:0 ? a:1 : inputdialog("Module: ")
    let note = 1 < a:0 ? a:2 : inputdialog("Note: ")
    let description = 2 < a:0 ? a:3 : inputdialog("Describe this module: ")
    
    return  repeat('-', s:width) . "\n" 
    \       . "-- | \n" 
    \       . "-- Module      : " . name . "\n"
    \       . "-- Note        : " . note . "\n"
    \       . "-- \n"
    \       . "-- " . description . "\n"
    \       . "-- \n"
    \       . repeat('-', s:width) . "\n"
    \       . "\n"

endfunction


nmap <silent> --h "=HaskellModuleHeader()<CR>:0put =<CR>

like so:

--------------------------------------------------------------------------------
-- | 
-- Module      : MyModule
-- Note        : This is a preview
-- 
-- This is an empty module, to show the headercomment produced. 
-- 
--------------------------------------------------------------------------------