)
call LaunchEasyHtml('\s')
elseif n == 3
" CSS Attributes (Example: margin: ;)
call LaunchEasyHtml('\(\s\\|"\\|;\)[a-zA-Z-]\+:')
else
return
endif
" remember what buffer we're in
let mybufnr = bufnr("%")
" reset window configuration
call Cream_window_setup()
" restore cursor to buffer's new window
call MoveCursorToWindow(bufwinnr(mybufnr))
endfunction
"+++
" Description {{{1
"
" Please don't hesitate to correct my english :)
" Send corrections to
"
"-----------------------------------------------------------------------------
" Description: With EasyHtml, you no longer need to look for tags attributes,
" attributes values or CSS properties values while editing HTML files.
" EasyHtml let you select the right attribute or value by showing you an
" attributes/values list for the tag/attribute/CSS property under the cursor.
"
"-----------------------------------------------------------------------------
" To Enable: Normally, this file will reside in your plugins directory and be
" automatically sourced. If not, you must manually source this file" using :
" source EasyHtml.vim
"
"-----------------------------------------------------------------------------
" Usage: Move the text cursor on the tag, attribute, or CSS property word
" then :
" - Press key to display attributes for the tag before/under the
" cursor
" - Press key to display values for the attribute before/under the
" cursor
" - Press ket to display values for the CSS Property befor/under
" the cursor
"
"
" In the EasyHtml buffer, use :
",,, keys to change selected
" item.
" - / or , keys to scroll list one page
" downward/forward.
" - or to select the first item.
" - or to select the last item.
" - to add selected item WITHOUT exiting from items list.
" - to add selected item AND exit from items list.
" - q or to exit without adding selected item.
"
" Deprecated attributes as declared by W3C are red highlighted, while right
" attributes are blue highlighted.
"
" Set g:easyHtmlSplitRight variable to 0 or 1 to open items list at left
" or right of current window. By default, use splitright setting.
"
" Set g:eh_singlequote variable to 0 (default) or 1 to use double or single
" quote when adding attributes (For example id="" or id='')
"
" Set g:eh_incsearch variable to 0 (default) or 1 to dis- or en-able
" incremental list search. This feature allows to select an item by typing its
" beginning. When this is enable, 'q', 'h', 'j', 'k' and 'l' keys aren't used
" to exit from list and to move highlighting. Use 'Q', '', '',
" '' and '' instead.
"
" Set g:eh_atfirstplace to 0 (default) or 1 to indicate if attributes must be
" added at the end or at the beginning of the tag.
"
" Useful mappings :
" . d : delete tag before/under cursor
" . d : delete attribute before/under cursor
"
"-----------------------------------------------------------------------------
" Updates:
" in version 0.5.1
" - No longer use of the modifiable option.
"
" in version 0.5
" - Now use liblist.vim script to handle lists and genutils.vim script to
" handle windows (Thanks to Hari Krishna Dara for this script).
" Download them at
" http://vim.sourceforge.net/scripts/script.php?script_id=166
" and
" http://vim.sourceforge.net/scripts/script.php?script_id=197
" Make script smaller.
" - Mapping changed !
" displays tag attributes
" displays attributes values
" displays CSS Properties values
" no longer close list after item addition. Use to add and
" exit from list.
" - More user friendly : you no longer need to move cursor exactly on the
" keyword. Cursor may stay on '=', ':' or '"' signs just after keyword while
" hitting , or keys.
" For example,
" . Tags :
key works while cursor is at '<' sign.
" . Attributes : style=""
" Hitting key works while cursor is at '=' or '"' signs.
" . CSS properties : background-color:;
" Hitting key works while cursor is at ':' or ';' signs.
" - New mappings :
" . d : delete tag before/under cursor
" . d : delete attribute before/under cursor
" - New g:eh_atfirstplace variable. See Usage section above.
" - Fix modifiable setting again
" - Fix syntax error for the "frame" attribute of tag which causes
" "border" attribute to not been seen in attributes list.
"
" in version 0.4.1
" - Fix infinite loop to find window when easyhtml buffer is hidden. Thanks to
" Jonathon Merz who pointed out the bug and send me the patch.
"
" in version 0.4
" - Added values for the "style" attribute (CSS2 properties)
" - Added values for CSS2 properties
" - and are now usable to move highlight through the list
" - When adding a value for an attribute, current attribute value (if exists)
" is replaced by the selected one, except for "style" attribute for which
" values are append
" - Set g:eh_singlequote variable to 0 or 1 to use double or single quote when
" adding attributes (For example id="" or id='')
"
" in version 0.3
" - Attributes list updated
" - Don't display attributes list for closing tags
" - Now, display values list when hitting with cursor on attribute word
" (for some attributes only).
"
" in version 0.2.1
" - Fix global modifiable setting instead of local
"
" in version 0.2
" - Attributes list is now alphabetically sorted
" - Hitting allows to display attributes list in Insert mode too
" - Allows to select an attribute by incremental search :-)
" For example, with tag, typing "onk" (normal mode) in the attributes
" list buffer automatically select "onkeydown" attribute. Use backspace
" () to remove characters. This behavior is enable by setting
" g:eh_incsearch variable to 1. Warning : when incremental attribute search
" is on, 'q', 'h', 'j', 'k' and 'l' keys aren't used to exit from list and
" to move highlighting. Use 'Q', '', '', '' and ''
" instead.
" - Check for attributes list already opened, and reuse it
"
" in version 0.1
" - First version
" 1}}}
" Init {{{1
" Has this already been loaded ?
if exists("loaded_easyhtml")
fini
en
let loaded_easyhtml=1
if !exists("g:easyHtmlSplitRight")
let g:easyHtmlSplitRight = &spr
en
if !exists("g:eh_incsearch")
let g:eh_incsearch = 0
en
if !exists("g:eh_singlequote")
let g:eh_singlequote = 0
en
if !exists("g:eh_atfirstplace")
let g:eh_atfirstplace = 0
en
" **
" Mappings: {{{1
" **
"+++ Cream: don't use these insert mode mappings
" Tag deletion
nm d lF
" Attribut deletion
nm d lF d2f"
" Left move attribut
nm d
" Right move attribut
nm d/ \\|>:nohlP
" Tag attributes list
nm :cal LaunchEasyHtml('<')
"im a
" Attributes values list
nm :cal LaunchEasyHtml('\s')
"im a
" Style attribut values list
nm :cal LaunchEasyHtml('\(\s\\|"\\|;\)[a-zA-Z-]\+:')
"im a
"+++
" 1}}}
"**
" Script Variables:
"**
let s:srch = ""
let s:maxAttrLength = 0
let s:currentPos = 2
let s:itemAdded = 0
" HTML tags attributes (original) {{{1
let s:coreattrs = "id=\"\" class=\"\" style=\"\" title=\"\""
let s:i18n = "lang=\"\" dir=\"\""
let s:events = "onclick=\"\" ondblclick=\"\" onmousedown=\"\" onmouseup=\"\" onmouseover=\"\" onmousemove=\"\" onmouseout=\"\" onkeypress=\"\" onkeydown=\"\" onkeyup=\"\""
let s:cellhalign = "align=\"\" char=\"\" charoff=\"\""
let s:cellvalign = "valign=\"\""
let s:attrs = "%coreattrs %i18n %events"
let s:HTMLTags = "")."."
"echoh NONE
if s:itemtype == "H"
let myentity = "HTML Tag"
elseif s:itemtype == "A"
let myentity = "HTML Tag Attribute"
elseif s:itemtype == "C"
let myentity = "CSS Property"
else
let myentity = "Word"
endif
call confirm(
\ myentity . " at cursor not in list dictionary.\n" .
\ "\n", "&Ok", 1, "Info")
""+++
exe s:eh_curLine
exe "norm ".s:eh_curCol."|"
retu
en
" Is there an attributes list already running and is it in a window?
let BufNr = bufnr( '--\ EasyHtml\ --' )
if BufNr != -1 && bufwinnr(BufNr) != -1
let CurBufNr = bufnr("%")
wh CurBufNr != BufNr
winc w
let CurBufNr = bufnr("%")
endw
let BufNr = bufnr( '--\ EasyHtml\ --' )
el
" Save the user's settings for splitright
let savesplitright = &spr
" Configure vertical splitting side
let &spr = g:easyHtmlSplitRight
" Open new vertical window with right size
"exe s:maxAttrLength . 'vnew --\ EasyHtml\ --'
if s:maxAttrLength < &wiw
let s:maxAttrLength = &wiw
en
exe s:maxAttrLength . 'vnew --\ EasyHtml\ --'
" Restore user settings
let &spr = savesplitright
" Turn off the swapfile, set the buffer type so that it won't get
" written, and so that it will get deleted when it gets hidden.
"setl modifiable
setl noswapfile
setl buftype=nowrite
"+++ Cream: our window manager might like to recover it!
"setl bufhidden=delete
"+++
setl nonumber
" Don't wrap around long lines
setl nowrap
" No need for any insertmode abbreviations, since we don't allow
" insertions anyway!
iabc
" Highlighting
sy match selectedAttribut /^<.*>$/
sy match deprecatedAttribut /^(.*)$/
sy match hiddenX /X/
hi selectedAttribut guibg=lightblue guifg=black
hi deprecatedAttribut guibg=lightred guifg=black
let color= s:GetBgColor()
if color != ""
exe "hi hiddenX guibg=" . color . " guifg=" . color
en
" Set up mappings for this buffer
nn :cal MoveSelect( line(".")-1 )
nn :cal MoveSelect( line(".")-1 )
nn :cal MoveSelect( line(".")+1 )
nn :cal MoveSelect( line(".")+1 )
nn :cal PageUp()
nn :cal PageDown()
nn :cal MoveSelect( 1 )
nn :cal MoveSelect( line("$") )
nn :cal MoveSelect( 1 )
nn :cal MoveSelect( line("$") )
nn :cal AddItem()
nn :cal AddItem() \| cal CloseWindow()
nn <2-LeftMouse> :cal AddItem()
nn :cal CloseWindow()
"+++ Cream:
" Set up mappings for this buffer
imap :cal MoveSelect( line(".")-1 )
imap :cal MoveSelect( line(".")-1 )
imap :cal MoveSelect( line(".")+1 )
imap :cal MoveSelect( line(".")+1 )
imap :cal PageUp()
imap :cal PageDown()
imap :cal MoveSelect( 1 )
imap :cal MoveSelect( line("$") )
imap :cal MoveSelect( 1 )
imap :cal MoveSelect( line("$") )
imap :cal AddItem()
" Windows Return
imap :cal AddItem()
imap :cal AddItem() \| cal CloseWindow()
imap <2-LeftMouse> :cal AddItem()
imap :cal CloseWindow()
"+++
" If incremental search required, initialize it
if( g:eh_incsearch == 1 )
nn Q :cal CloseWindow()
nn :cal SelectSearch( "" )
let char = 97
wh char < 123
exe "nn " . nr2char(char) . " :cal SelectSearch( '" . nr2char(char) . "' )"
let char = char + 1
endw
el
nn h :cal MoveSelect( line(".")-1 )
nn k :cal MoveSelect( line(".")-1 )
nn l :cal MoveSelect( line(".")+1 )
nn j :cal MoveSelect( line(".")+1 )
nn q :cal CloseWindow()
en
en
" Reset incremental search
let s:srch = ""
" Fill attributs list
cal s:ShowAttributes()
" User don't need to modify content
"setl nomodifiable
endf
"**
" SearchAttributes: {{{1
" Look for attributs for word under cursor. tr
"**
fu! s:SearchAttributes()
" Ignore case
let l:CurrentCase = &ic
set ignorecase
let l:CurrentIkw = &isk
let s:attributs = ""
let s:maxAttrLength = 0
"+++ Cream: remove dependency on libList
"let g:listSep = ","
"+++
let l:attributsLine = ""
setl iskeyword +=<
"if match( expand(""), '^<' ) == 0 " Is it a tag ?
if match( expand(""), '<' ) == 0 " Is it a tag ?
let s:itemtype = "T" " Yes, a tag
"+++ Cream: remove dependency on libList
"let l:attributsLine = GetListMatchItem( s:HTMLTags, expand("") . ' ' )
let l:attributsLine = matchstr( s:HTMLTags, '[^,]*' . expand("") . ' ' . '[^,]*' )
"+++
el
setl iskeyword -=<
setl iskeyword +=-,=
if match( expand(""), '=$' ) != -1 " or an attribute ?
let s:itemtype = "A" " Yes, an attribute
"let l:attributsLine = GetListMatchItem( s:TagsAttributs, expand("") . '" ' )
let l:attributsLine = matchstr( s:TagsAttributs, '[^,]*' . expand("") . '" ' . '[^,]*' )
el
setl iskeyword -==
setl iskeyword +=:
if match( expand(""), ':' ) != -1 " or a CSS property ?
let s:itemtype = "C" " Yes, a CSS property
"+++ Cream: remove dependency on libList
" and split into two steps
"let l:attributsLine = GetListMatchItem( s:CSSProperties, '\<' . matchstr( expand(""), '^.\{-}:' ) . ' ' )
let item = '\<' . matchstr( expand(""), '^.\{-}:' ) . ' '
"let l:attributsLine = GetListMatchItem( s:CSSProperties, item )
let l:attributsLine = matchstr( s:CSSProperties, '[^,]*' . item . '[^,]*' )
"+++
en
en
en
if l:attributsLine != ""
"+++ Cream: remove dependency on libList
"let g:listSep = " "
"let l:attributsLine = RemoveListItem( l:attributsLine, 0 )
let l:attributsLine = substitute( l:attributsLine, '^[^ ]\+\( \|$\)', "", "" )
"+++
if l:attributsLine != ""
" Attributes values are already sorted and expanded
if s:itemtype != "A"
" Insert %xxxx variables content
let l:attribut = matchstr( l:attributsLine, '%[^ ]\+' )
wh l:attribut != ""
exe "let l:attributsLine = substitute( l:attributsLine, '" .l:attribut. "', s:" . strpart( l:attribut, 1 ) . ", '')"
let l:attribut = matchstr( l:attributsLine, '%[^ ]\+' )
endw " Sort items
"+++ Cream: remove dependency on libList
"let l:attributsLine = QuickSortList( l:attributsLine, 0, GetListCount(l:attributsLine)-1 )
"*** Requires globally exposed CmpByString() function! ***
let l:attributsLine = MvQSortElements(l:attributsLine, ",", "CmpByString", 1)
"+++
en
"+++ Cream: remove dependency on libList
"let l:attribut = GetListItem( l:attributsLine, 0 )
let l:attribut = matchstr( l:attributsLine, '^[^ ]\+' )
"+++
wh l:attribut != ""
" Keep max length
if s:maxAttrLength < strlen( l:attribut )
let s:maxAttrLength = strlen( l:attribut )
en
" Remove current attribut
"+++ Cream: remove dependency on libList
"let l:attributsLine = RemoveListItem( l:attributsLine, 0 )
let l:attributsLine = substitute( l:attributsLine, '^[^ ]\+\( \|$\)', "", "" )
"+++
" Is it a depracated attribute ?
set noignorecase
if l:attribut =~ "-D"
let l:attribut = substitute( l:attribut, "-D", "", "")
let s:attributs = s:attributs . "X" . l:attribut . " \n"
el
let s:attributs = s:attributs . " " . l:attribut . " \n"
en
" Next attribut
"+++ Cream: remove dependency on libList
"let l:attribut = GetListItem( l:attributsLine, 0 )
let l:attribut = matchstr( l:attributsLine, '^[^ ]\+' )
"+++
endw
en
" If longest attribute size is zero, then there is no attribute
" for this tag
if s:maxAttrLength != 0
let s:maxAttrLength = s:maxAttrLength + 2
en
en
let &isk = l:CurrentIkw
let &ic = l:CurrentCase
endf
"**
" ShowAttributes: {{{1
" Display attributs list in current buffer.
"**
fu! s:ShowAttributes()
" Prevent a report of our actions from showing up
let oldRep=&report
let save_sc = &sc
set report=10000 nosc
"setl modifiable
" Erase content
%delete
" Put content of register f after the cursor
put! =s:attributs
" Erase last line
norm G
delete
" Move to first item
cal s:MoveSelect(1)
"setl nomodifiable
" Restore config
let &report=oldRep
let &sc = save_sc
endf
"**
" AddItem: {{{1
" Add selected item to tag/attribute/CSS2 property.
"**
fu! s:AddItem()
" At least one item is added
let s:itemAdded = 1
let l:CurrentCase = &ic
set noignorecase
" Get item and clean it
let save_f=@f
let @f = substitute( getline("."), '[<>X() ]', '', "g" )
let &ic = l:CurrentCase
" Go to previous window
winc p
" if it's a tag, put attribute at end of tag
if s:itemtype == "T"
" User wants single quotes ?
if g:eh_singlequote == 1
let @f = substitute( @f , '"', "'", 'g' )
en
let @f = ' ' . @f
" Add attribute just after tag ?
if g:eh_atfirstplace == 1
cal search( ' \|>' )
norm "fP
el
norm f>"fP
en
elsei s:itemtype == "A" " If it's an attribute ...
if g:eh_singlequote == 0
let quote = '"'
el
let quote = "'"
en
if expand("") !~ 'style' " ... replace current value by selected value
exec 'norm 2f' .quote. 'dT' .quote. '"fPB'
el " ... or append selected value to it for style
exec 'norm f' .quote. '"fp'
en
elsei s:itemtype == "C" " If it's an CSS property, add value to it
norm f:"fgp
en
" Return to attributes window
winc p
let @f=save_f
endf
"**
" MoveSelect: {{{1
" Move highlight to line newLineNumber.
"
" Parameter:
" newLineNumber line number to highlight.
"**
fu! s:MoveSelect( newLineNumber )
if( a:newLineNumber < 1 || a:newLineNumber > line("$") )
retu
en
"setl modifiable
" Restore current line
if( exists("s:currentLine") )
cal setline( ".", s:currentLine )
en
" Go to new line
let s:currentPos = a:newLineNumber
exe s:currentPos
" Save new current line
let s:currentLine = getline(".")
let modifiedLine = s:currentLine
" Complete string with spaces
let len = strlen(l:modifiedLine)
wh len < s:maxAttrLength
let modifiedLine = modifiedLine . " "
let len = len + 1
endw
" Is it a deprecated attribute marked with 'X' ?
if l:modifiedLine =~ "^X"
let modifiedLine = substitute( modifiedLine, "^X", "(", "" )
let modifiedLine = substitute( modifiedLine, " $", ")", "" )
el
let modifiedLine = substitute( modifiedLine, "^ ", "<", "" )
let modifiedLine = substitute( modifiedLine, " $", ">", "" )
en
cal setline( ".", l:modifiedLine )
"setl nomodifiable
endf
"**
" PageDown: {{{1
" Move highlight one page down.
"**
fu! s:PageDown()
norm L
let pos = line(".")
norm ''
cal s:MoveSelect( pos )
norm zt
endf
"**
" PageUp: {{{1
" Move highlight one page up.
"**
fu! s:PageUp()
norm H
let pos = line(".")
norm ''
cal s:MoveSelect( pos )
norm zb
endf
"**
" CloseWindow: {{{1
" Clear unused variables and highlights, reinit variables for next use and
" close current window.
"**
fu! s:CloseWindow()
unl s:currentLine
unl s:attributs
let s:maxAttrLength = 0
let s:currentPos = 2
hi clear selectedAttribut
hi clear deprecatedAttribut
hi clear hiddenX
"setl modifiable
winc p
if s:itemAdded == 0
exe s:eh_curLine
echom s:eh_curLine
exe "norm ".s:eh_curCol."|"
el
let s:itemAdded = 0
startinsert
en
winc p
winc q
endf
"**
" GetBgColor: {{{1
" Try to get background color (may be not sure)
"**
fu! s:GetBgColor()
let bgColor = synIDattr(synIDtrans(synID(1, 1, 1)), "bg")
if bgColor == ""
if &bg == "light"
let bgColor = "white"
el
let bgColor = "black"
en
en
retu bgColor
endf
"**
" SelectSearch: {{{1
" Used for incremental attribut search
"
" Parameter:
" Char character to add to current search pattern
"**
fu! s:SelectSearch( char )
if a:char == "" && s:srch != ""
let s:srch = strpart( s:srch, 0, strlen( s:srch )-1 )
el
let s:srch = s:srch . a:char
en
let linenr = line(".")
if s:srch != ""
1
let findlinenr = search( '\(\<\|X\)'.s:srch, "W" )
exe ":".linenr
if findlinenr != 0
ec "Attributs search : " . s:srch
cal s:MoveSelect( findlinenr )
el
echoh ErrorMsg
ec "No attribut for \"" . s:srch . "\" (use backspace)"
echoh NONE
en
en
endf
" 1}}}
" vim:foldmethod=marker