Skip to content

how to pass filetype to func for user-variables #146

@zzs213

Description

@zzs213

When generate modeline using user-variable. The func to generate custom modeline should know which filetype to generate.

So howto pass the filetype to the func. My code as flowwing

`
let g:templates_user_variables = [
\ ['MODELINE', 'Modeline_str'],
\ ]
function! Modeline_str(type)
let modeline = {
\ 'c' : [printf('/* vi: set ft=c fo=%s tw=100 sw=8 ts=8 sts=8 fenc=utf-8 ai noet: /', s:my_formatoptions), ''],
\ 'cpp' : [printf('/
vi: set ft=cpp fo=%s tw=100 sw=8 ts=8 sts=8 fenc=utf-8 ai noet: */', s:my_formatoptions), ''],
\ 'sh' : ['#!/bin/bash',
\ printf('# vi: set ft=sh fo=%s tw=100 sw=4 ts=4 sts=4 fenc=utf-8 isk-=. ai et:', s:my_formatoptions),
\ ''],
\ 'make' : [printf('# vi: set ft=make fo=%s tw=100 sw=8 ts=8 sts=8 fenc=utf-8 ai noet:', s:my_formatoptions), ''],
\ }

if !has_key(modeline, a:type)
    return ''
endif

return modeline[a:type]

endfunction
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions