Skip to content

Commit

Permalink
tcomment#GuessCommentType(): Make filetype guessing accessible for ot…
Browse files Browse the repository at this point in the history
…her plugins
  • Loading branch information
tomtom committed Dec 5, 2012
1 parent df3f28f commit 8b6dcc0
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion autoload/tcomment.vim
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-09-17. " @Created: 2007-09-17.
" @Last Change: 2012-09-22. " @Last Change: 2012-09-22.
" @Revision: 0.0.577 " @Revision: 0.0.591


" call tlog#Log('Load: '. expand('<sfile>')) " vimtlib-sfile " call tlog#Log('Load: '. expand('<sfile>')) " vimtlib-sfile


Expand Down Expand Up @@ -1082,6 +1082,33 @@ function! s:Filetype(...) "{{{3
endf endf




" A function that makes the s:GuessFileType() function usable for other
" library developers.
"
" The argument is a dictionary with the following keys:
"
" beg ................ (default = line("."))
" end ................ (default = line("."))
" commentMode ........ (default = "G")
" filetype ........... (default = &filetype)
" fallbackFiletype ... (default = "")
"
" This function return a dictionary that contains information about how
" to make comments. The information about the filetype of the text
" between lines "beg" and "end" is in the "filetype" key of the return
" value. It returns the first discernible filetype it encounters.
" :display: tcomment#GuessFileType(?options={})
function! tcomment#GuessCommentType(...) "{{{3
let options = a:0 >= 1 ? a:1 : {}
let beg = get(options, 'beg', line('.'))
let end = get(options, 'end', line('.'))
let commentMode = get(options, 'commentMode', '')
let filetype = get(options, 'filetype', &filetype)
let fallbackFiletype = get(options, 'filetype', '')
return s:GuessFileType(beg, end, commentMode, filetype, fallbackFiletype)
endf


" inspired by Meikel Brandmeyer's EnhancedCommentify.vim " inspired by Meikel Brandmeyer's EnhancedCommentify.vim
" this requires that a syntax names are prefixed by the filetype name " this requires that a syntax names are prefixed by the filetype name
" s:GuessFileType(beg, end, commentMode, filetype, ?fallbackFiletype) " s:GuessFileType(beg, end, commentMode, filetype, ?fallbackFiletype)
Expand Down Expand Up @@ -1232,6 +1259,7 @@ function! s:GetCustomCommentString(ft, commentMode, ...)
endif endif
let cdef = copy(def) let cdef = copy(def)
let cdef.mode = commentMode let cdef.mode = commentMode
let cdef.filetype = a:ft
" TLogVAR cdef " TLogVAR cdef
return cdef return cdef
endf endf
Expand Down

0 comments on commit 8b6dcc0

Please sign in to comment.