editorconfig.vim 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. " Copyright (c) 2011-2015 EditorConfig Team
  2. " All rights reserved.
  3. "
  4. " Redistribution and use in source and binary forms, with or without
  5. " modification, are permitted provided that the following conditions are met:
  6. "
  7. " 1. Redistributions of source code must retain the above copyright notice,
  8. " this list of conditions and the following disclaimer.
  9. " 2. Redistributions in binary form must reproduce the above copyright notice,
  10. " this list of conditions and the following disclaimer in the documentation
  11. " and/or other materials provided with the distribution.
  12. "
  13. " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  14. " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. " IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. " ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  17. " LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. " CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. " SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. " INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. " CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. " ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. " POSSIBILITY OF SUCH DAMAGE.
  24. "
  25. if v:version < 700
  26. finish
  27. endif
  28. " check whether this script is already loaded
  29. if exists("g:loaded_EditorConfig")
  30. finish
  31. endif
  32. let g:loaded_EditorConfig = 1
  33. let s:saved_cpo = &cpo
  34. set cpo&vim
  35. let s:pyscript_path = expand('<sfile>:p:r') . '.py'
  36. " variables {{{1
  37. if !exists('g:EditorConfig_exec_path')
  38. let g:EditorConfig_exec_path = ''
  39. endif
  40. if !exists('g:EditorConfig_python_files_dir')
  41. let g:EditorConfig_python_files_dir = 'plugin/editorconfig-core-py'
  42. endif
  43. if !exists('g:EditorConfig_verbose')
  44. let g:EditorConfig_verbose = 0
  45. endif
  46. if !exists('g:EditorConfig_preserve_formatoptions')
  47. let g:EditorConfig_preserve_formatoptions = 0
  48. endif
  49. if !exists('g:EditorConfig_max_line_indicator')
  50. let g:EditorConfig_max_line_indicator = 'line'
  51. endif
  52. if !exists('g:EditorConfig_exclude_patterns')
  53. let g:EditorConfig_exclude_patterns = []
  54. endif
  55. if !exists('g:EditorConfig_disable_rules')
  56. let g:EditorConfig_disable_rules = []
  57. endif
  58. if exists('g:EditorConfig_core_mode') && !empty(g:EditorConfig_core_mode)
  59. let s:editorconfig_core_mode = g:EditorConfig_core_mode
  60. else
  61. let s:editorconfig_core_mode = ''
  62. endif
  63. let s:initialized = 0
  64. " shellslash handling {{{1
  65. function! s:DisableShellSlash() " {{{2
  66. " disable shellslash for proper escaping of Windows paths
  67. " In Windows, 'shellslash' also changes the behavior of 'shellescape'.
  68. " It makes 'shellescape' behave like in UNIX environment. So ':setl
  69. " noshellslash' before evaluating 'shellescape' and restore the
  70. " settings afterwards when 'shell' does not contain 'sh' somewhere.
  71. if has('win32') && empty(matchstr(&shell, 'sh'))
  72. let s:old_shellslash = &l:shellslash
  73. setlocal noshellslash
  74. endif
  75. endfunction " }}}
  76. function! s:ResetShellSlash() " {{{2
  77. " reset shellslash to the user-set value, if any
  78. if exists('s:old_shellslash')
  79. let &l:shellslash = s:old_shellslash
  80. unlet! s:old_shellslash
  81. endif
  82. endfunction " }}}
  83. " }}}
  84. function! s:FindPythonInterp() " {{{1
  85. " Find python interp. If found, return python command; if not found, return ''
  86. if has('unix')
  87. let l:searching_list = [
  88. \ 'python',
  89. \ 'python27',
  90. \ 'python26',
  91. \ 'python25',
  92. \ 'python24',
  93. \ '/usr/local/bin/python',
  94. \ '/usr/local/bin/python27',
  95. \ '/usr/local/bin/python26',
  96. \ '/usr/local/bin/python25',
  97. \ '/usr/local/bin/python24',
  98. \ '/usr/bin/python',
  99. \ '/usr/bin/python27',
  100. \ '/usr/bin/python26',
  101. \ '/usr/bin/python25',
  102. \ '/usr/bin/python24']
  103. elseif has('win32')
  104. let l:searching_list = [
  105. \ 'python',
  106. \ 'python27',
  107. \ 'python26',
  108. \ 'python25',
  109. \ 'python24',
  110. \ 'C:\Python27\python.exe',
  111. \ 'C:\Python26\python.exe',
  112. \ 'C:\Python25\python.exe',
  113. \ 'C:\Python24\python.exe']
  114. endif
  115. for possible_python_interp in l:searching_list
  116. if executable(possible_python_interp)
  117. return possible_python_interp
  118. endif
  119. endfor
  120. return ''
  121. endfunction
  122. function! s:FindPythonFiles() " {{{1
  123. " Find EditorConfig Core python files
  124. call s:DisableShellSlash()
  125. let l:python_core_files_dir = fnamemodify(
  126. \ findfile(g:EditorConfig_python_files_dir . '/main.py',
  127. \ ','.&runtimepath), ':p:h')
  128. if empty(l:python_core_files_dir)
  129. let l:python_core_files_dir = ''
  130. else
  131. " expand python core file path to full path, and remove the appending '/'
  132. let l:python_core_files_dir = substitute(
  133. \ fnamemodify(l:python_core_files_dir, ':p'), '/$', '', '')
  134. endif
  135. call s:ResetShellSlash()
  136. return l:python_core_files_dir
  137. endfunction
  138. " Mode initialization functions {{{1
  139. function! s:InitializeExternalCommand() " {{{2
  140. " Initialize external_command mode
  141. let s:EditorConfig_exec_path = ''
  142. " User has specified an EditorConfig command. Use that one.
  143. if exists('g:EditorConfig_exec_path') &&
  144. \ !empty(g:EditorConfig_exec_path)
  145. if executable(g:EditorConfig_exec_path)
  146. let s:EditorConfig_exec_path = g:EditorConfig_exec_path
  147. return 0
  148. else
  149. return 1
  150. endif
  151. endif
  152. " User does not specify an EditorConfig command. Let's search for it.
  153. if has('unix')
  154. let l:searching_list = [
  155. \ 'editorconfig',
  156. \ '/usr/local/bin/editorconfig',
  157. \ '/usr/bin/editorconfig',
  158. \ '/opt/bin/editorconfig',
  159. \ '/opt/editorconfig/bin/editorconfig',
  160. \ 'editorconfig.py',
  161. \ '/usr/local/bin/editorconfig.py',
  162. \ '/usr/bin/editorconfig.py',
  163. \ '/opt/bin/editorconfig.py',
  164. \ '/opt/editorconfig/bin/editorconfig.py']
  165. elseif has('win32')
  166. let l:searching_list = [
  167. \ 'editorconfig',
  168. \ 'C:\editorconfig\bin\editorconfig',
  169. \ 'D:\editorconfig\bin\editorconfig',
  170. \ 'E:\editorconfig\bin\editorconfig',
  171. \ 'F:\editorconfig\bin\editorconfig',
  172. \ 'C:\Program Files\editorconfig\bin\editorconfig',
  173. \ 'D:\Program Files\editorconfig\bin\editorconfig',
  174. \ 'E:\Program Files\editorconfig\bin\editorconfig',
  175. \ 'F:\Program Files\editorconfig\bin\editorconfig',
  176. \ 'C:\Program Files (x86)\editorconfig\bin\editorconfig',
  177. \ 'D:\Program Files (x86)\editorconfig\bin\editorconfig',
  178. \ 'E:\Program Files (x86)\editorconfig\bin\editorconfig',
  179. \ 'F:\Program Files (x86)\editorconfig\bin\editorconfig',
  180. \ 'editorconfig.py']
  181. endif
  182. " search for editorconfig core executable
  183. for possible_cmd in l:searching_list
  184. if executable(possible_cmd)
  185. let s:EditorConfig_exec_path = possible_cmd
  186. break
  187. endif
  188. endfor
  189. if empty(s:EditorConfig_exec_path)
  190. return 2
  191. endif
  192. return 0
  193. endfunction
  194. function! s:InitializePythonExternal() " {{{2
  195. " Initialize external python. Before calling this function, please make sure
  196. " s:FindPythonFiles is called and the return value is set to
  197. " s:editorconfig_core_py_dir
  198. if !exists('s:editorconfig_core_py_dir') ||
  199. \ empty(s:editorconfig_core_py_dir)
  200. return 2
  201. endif
  202. " Find python interp
  203. if !exists('g:editorconfig_python_interp') ||
  204. \ empty('g:editorconfig_python_interp')
  205. let s:editorconfig_python_interp = s:FindPythonInterp()
  206. endif
  207. if empty(s:editorconfig_python_interp) ||
  208. \ !executable(s:editorconfig_python_interp)
  209. return 1
  210. endif
  211. return 0
  212. endfunction
  213. function! s:InitializePythonBuiltin(editorconfig_core_py_dir) " {{{2
  214. " Initialize builtin python. The parameter is the Python Core directory
  215. if exists('s:builtin_python_initialized') && s:builtin_python_initialized
  216. return 0
  217. endif
  218. let s:builtin_python_initialized = 1
  219. if has('python')
  220. let s:pyfile_cmd = 'pyfile'
  221. let s:py_cmd = 'py'
  222. elseif has('python3')
  223. let s:pyfile_cmd = 'py3file'
  224. let s:py_cmd = 'py3'
  225. else
  226. return 1
  227. endif
  228. let l:ret = 0
  229. " The following line modifies l:ret. This is a bit confusing but
  230. " unfortunately to be compatible with Vim 7.3, we cannot use pyeval. This
  231. " should be changed in the future.
  232. execute s:pyfile_cmd fnameescape(s:pyscript_path)
  233. return l:ret
  234. endfunction
  235. function! s:Initialize() " {{{1
  236. " Do some initalization for the case that the user has specified core mode {{{2
  237. if !empty(s:editorconfig_core_mode)
  238. if s:editorconfig_core_mode == 'external_command'
  239. if s:InitializeExternalCommand()
  240. echo 'EditorConfig: Failed to initialize external_command mode'
  241. return 1
  242. endif
  243. else
  244. let s:editorconfig_core_py_dir = s:FindPythonFiles()
  245. if empty(s:editorconfig_core_py_dir)
  246. echo 'EditorConfig: '.
  247. \ 'EditorConfig Python Core files could not be found.'
  248. return 1
  249. endif
  250. if s:editorconfig_core_mode == 'python_builtin' &&
  251. \ s:InitializePythonBuiltin(s:editorconfig_core_py_dir)
  252. echo 'EditorConfig: Failed to initialize vim built-in python.'
  253. return 1
  254. elseif s:editorconfig_core_mode == 'python_external' &&
  255. \ s:InitializePythonExternal()
  256. echo 'EditorConfig: Failed to find external Python interpreter.'
  257. return 1
  258. endif
  259. endif
  260. endif
  261. " Determine the editorconfig_core_mode we should use {{{2
  262. while 1
  263. " If user has specified a mode, just break
  264. if exists('s:editorconfig_core_mode') && !empty(s:editorconfig_core_mode)
  265. break
  266. endif
  267. " Find Python core files. If not found, we try external_command mode
  268. let s:editorconfig_core_py_dir = s:FindPythonFiles()
  269. if empty(s:editorconfig_core_py_dir) " python files are not found
  270. if !s:InitializeExternalCommand()
  271. let s:editorconfig_core_mode = 'external_command'
  272. endif
  273. break
  274. endif
  275. " Builtin python mode first
  276. if !s:InitializePythonBuiltin(s:editorconfig_core_py_dir)
  277. let s:editorconfig_core_mode = 'python_builtin'
  278. break
  279. endif
  280. " Then external_command mode
  281. if !s:InitializeExternalCommand()
  282. let s:editorconfig_core_mode = 'external_command'
  283. break
  284. endif
  285. " Finally external python mode
  286. if !s:InitializePythonExternal()
  287. let s:editorconfig_core_mode = 'python_external'
  288. break
  289. endif
  290. break
  291. endwhile
  292. " No EditorConfig Core is available
  293. if empty(s:editorconfig_core_mode)
  294. echo "EditorConfig: ".
  295. \ "No EditorConfig Core is available. The plugin won't work."
  296. return 1
  297. endif
  298. " }}}
  299. let s:initialized = 1
  300. return 0
  301. endfunction
  302. function! s:GetFilenames(path, filename)
  303. " Yield full filepath for filename in each directory in and above path
  304. let l:path_list = []
  305. let l:path = a:path
  306. while 1
  307. let l:path_list += [l:path . '/' . a:filename]
  308. let l:newpath = fnamemodify(l:path, ':h')
  309. if l:path == l:newpath
  310. break
  311. endif
  312. let l:path = l:newpath
  313. endwhile
  314. return l:path_list
  315. endfunction
  316. function! s:UseConfigFiles()
  317. let l:buffer_name = expand('%:p')
  318. " ignore buffers without a name
  319. if empty(l:buffer_name)
  320. return
  321. endif
  322. " Check if any .editorconfig does exist
  323. let l:conf_files = s:GetFilenames(expand('%:p:h'), '.editorconfig')
  324. let l:conf_found = 0
  325. for conf_file in conf_files
  326. if filereadable(conf_file)
  327. let l:conf_found = 1
  328. break
  329. endif
  330. endfor
  331. if !l:conf_found
  332. return
  333. endif
  334. if g:EditorConfig_verbose
  335. echo 'Applying EditorConfig on file "' . l:buffer_name . '"'
  336. endif
  337. if !s:initialized
  338. if s:Initialize()
  339. return
  340. endif
  341. endif
  342. " Ignore specific patterns
  343. for pattern in g:EditorConfig_exclude_patterns
  344. if l:buffer_name =~ pattern
  345. return
  346. endif
  347. endfor
  348. if s:editorconfig_core_mode == 'external_command'
  349. call s:UseConfigFiles_ExternalCommand()
  350. elseif s:editorconfig_core_mode == 'python_builtin'
  351. call s:UseConfigFiles_Python_Builtin()
  352. elseif s:editorconfig_core_mode == 'python_external'
  353. call s:UseConfigFiles_Python_External()
  354. else
  355. echohl Error |
  356. \ echo "Unknown EditorConfig Core: " .
  357. \ s:editorconfig_core_mode |
  358. \ echohl None
  359. endif
  360. endfunction
  361. " command, autoload {{{1
  362. command! EditorConfigReload call s:UseConfigFiles() " Reload EditorConfig files
  363. augroup editorconfig
  364. autocmd!
  365. autocmd BufNewFile,BufReadPost,BufFilePost * call s:UseConfigFiles()
  366. autocmd BufNewFile,BufRead .editorconfig set filetype=dosini
  367. augroup END
  368. " UseConfigFiles function for different mode {{{1
  369. function! s:UseConfigFiles_Python_Builtin() " {{{2
  370. " Use built-in python to run the python EditorConfig core
  371. let l:config = {}
  372. let l:ret = 0
  373. execute s:py_cmd 'ec_UseConfigFiles()'
  374. if l:ret != 0
  375. return l:ret
  376. endif
  377. call s:ApplyConfig(l:config)
  378. return l:ret
  379. endfunction
  380. function! s:UseConfigFiles_Python_External() " {{{2
  381. " Use external python interp to run the python EditorConfig Core
  382. call s:DisableShellSlash()
  383. let l:cmd = shellescape(s:editorconfig_python_interp) . ' ' .
  384. \ shellescape(s:editorconfig_core_py_dir . '/main.py')
  385. call s:ResetShellSlash()
  386. call s:SpawnExternalParser(l:cmd)
  387. return 0
  388. endfunction
  389. function! s:UseConfigFiles_ExternalCommand() " {{{2
  390. " Use external EditorConfig core (The C core, or editorconfig.py)
  391. call s:DisableShellSlash()
  392. let l:exec_path = shellescape(s:EditorConfig_exec_path)
  393. call s:ResetShellSlash()
  394. call s:SpawnExternalParser(l:exec_path)
  395. endfunction
  396. function! s:SpawnExternalParser(cmd) " {{{2
  397. " Spawn external EditorConfig. Used by s:UseConfigFiles_Python_External() and
  398. " s:UseConfigFiles_ExternalCommand()
  399. let l:cmd = a:cmd
  400. " if editorconfig is present, we use this as our parser
  401. if !empty(l:cmd)
  402. let l:config = {}
  403. call s:DisableShellSlash()
  404. let l:cmd = l:cmd . ' ' . shellescape(expand('%:p'))
  405. call s:ResetShellSlash()
  406. let l:parsing_result = split(system(l:cmd), '[\r\n]')
  407. " if editorconfig core's exit code is not zero, give out an error
  408. " message
  409. if v:shell_error != 0
  410. echohl ErrorMsg
  411. echo 'Failed to execute "' . l:cmd . '". Exit code: ' .
  412. \ v:shell_error
  413. echo ''
  414. echo 'Message:'
  415. echo l:parsing_result
  416. echohl None
  417. return
  418. endif
  419. if g:EditorConfig_verbose
  420. echo 'Output from EditorConfig core executable:'
  421. echo l:parsing_result
  422. endif
  423. for one_line in l:parsing_result
  424. let l:eq_pos = stridx(one_line, '=')
  425. if l:eq_pos == -1 " = is not found. Skip this line
  426. continue
  427. endif
  428. let l:eq_left = strpart(one_line, 0, l:eq_pos)
  429. if l:eq_pos + 1 < strlen(one_line)
  430. let l:eq_right = strpart(one_line, l:eq_pos + 1)
  431. else
  432. let l:eq_right = ''
  433. endif
  434. let l:config[l:eq_left] = l:eq_right
  435. endfor
  436. call s:ApplyConfig(l:config)
  437. endif
  438. endfunction
  439. function! s:ApplyConfig(config) " {{{1
  440. " Only process normal buffers (do not treat help files as '.txt' files)
  441. if !empty(&buftype)
  442. return
  443. endif
  444. " Set the indentation style according to the config values
  445. if s:IsRuleActive('indent_style', a:config)
  446. if a:config["indent_style"] == "tab"
  447. setl noexpandtab
  448. elseif a:config["indent_style"] == "space"
  449. setl expandtab
  450. endif
  451. endif
  452. if s:IsRuleActive('tab_width', a:config)
  453. let &l:tabstop = str2nr(a:config["tab_width"])
  454. endif
  455. if s:IsRuleActive('indent_size', a:config)
  456. " if indent_size is 'tab', set shiftwidth to tabstop;
  457. " if indent_size is a positive integer, set shiftwidth to the integer
  458. " value
  459. if a:config["indent_size"] == "tab"
  460. let &l:shiftwidth = &l:tabstop
  461. let &l:softtabstop = &l:shiftwidth
  462. else
  463. let l:indent_size = str2nr(a:config["indent_size"])
  464. if l:indent_size > 0
  465. let &l:shiftwidth = l:indent_size
  466. let &l:softtabstop = &l:shiftwidth
  467. endif
  468. endif
  469. endif
  470. if s:IsRuleActive('end_of_line', a:config) &&
  471. \ &l:modifiable
  472. if a:config["end_of_line"] == "lf"
  473. setl fileformat=unix
  474. elseif a:config["end_of_line"] == "crlf"
  475. setl fileformat=dos
  476. elseif a:config["end_of_line"] == "cr"
  477. setl fileformat=mac
  478. endif
  479. endif
  480. if s:IsRuleActive('charset', a:config) &&
  481. \ &l:modifiable
  482. if a:config["charset"] == "utf-8"
  483. setl fileencoding=utf-8
  484. setl nobomb
  485. elseif a:config["charset"] == "utf-8-bom"
  486. setl fileencoding=utf-8
  487. setl bomb
  488. elseif a:config["charset"] == "latin1"
  489. setl fileencoding=latin1
  490. setl nobomb
  491. elseif a:config["charset"] == "utf-16be"
  492. setl fileencoding=utf-16be
  493. setl bomb
  494. elseif a:config["charset"] == "utf-16le"
  495. setl fileencoding=utf-16le
  496. setl bomb
  497. endif
  498. endif
  499. augroup editorconfig_trim_trailing_whitespace
  500. autocmd! BufWritePre <buffer>
  501. if s:IsRuleActive('trim_trailing_whitespace', a:config) &&
  502. \ get(a:config, 'trim_trailing_whitespace', 'false') ==# 'true'
  503. autocmd BufWritePre <buffer> call s:TrimTrailingWhitespace()
  504. endif
  505. augroup END
  506. if s:IsRuleActive('insert_final_newline', a:config)
  507. if exists('+fixendofline')
  508. if a:config["insert_final_newline"] == "false"
  509. setl nofixendofline
  510. else
  511. setl fixendofline
  512. endif
  513. elseif exists(':SetNoEOL') == 2
  514. if a:config["insert_final_newline"] == "false"
  515. silent! SetNoEOL " Use the PreserveNoEOL plugin to accomplish it
  516. endif
  517. endif
  518. endif
  519. " highlight the columns following max_line_length
  520. if s:IsRuleActive('max_line_length', a:config) &&
  521. \ a:config['max_line_length'] != 'off'
  522. let l:max_line_length = str2nr(a:config['max_line_length'])
  523. if l:max_line_length >= 0
  524. let &l:textwidth = l:max_line_length
  525. if g:EditorConfig_preserve_formatoptions == 0
  526. setlocal formatoptions+=tc
  527. endif
  528. endif
  529. if exists('+colorcolumn')
  530. if l:max_line_length > 0
  531. if g:EditorConfig_max_line_indicator == 'line'
  532. let &l:colorcolumn = l:max_line_length + 1
  533. elseif g:EditorConfig_max_line_indicator == 'fill' &&
  534. \ l:max_line_length < &l:columns
  535. " Fill only if the columns of screen is large enough
  536. let &l:colorcolumn = join(
  537. \ range(l:max_line_length+1,&l:columns),',')
  538. elseif g:EditorConfig_max_line_indicator == 'exceeding'
  539. let &l:colorcolumn = ''
  540. for l:match in getmatches()
  541. if get(l:match, 'group', '') == 'ColorColumn'
  542. call matchdelete(get(l:match, 'id'))
  543. endif
  544. endfor
  545. call matchadd('ColorColumn',
  546. \ '\%' . (l:max_line_length + 1) . 'v', 100)
  547. endif
  548. endif
  549. endif
  550. endif
  551. call editorconfig#ApplyHooks(a:config)
  552. endfunction
  553. " }}}
  554. function! s:TrimTrailingWhitespace() " {{{{
  555. if &l:modifiable
  556. " don't lose user position when trimming trailing whitespace
  557. let s:view = winsaveview()
  558. try
  559. silent! %s/\s\+$//e
  560. finally
  561. call winrestview(s:view)
  562. endtry
  563. endif
  564. endfunction " }}}
  565. function! s:IsRuleActive(name, config) " {{{{
  566. return index(g:EditorConfig_disable_rules, a:name) < 0 &&
  567. \ has_key(a:config, a:name)
  568. endfunction "}}}}
  569. let &cpo = s:saved_cpo
  570. unlet! s:saved_cpo
  571. " vim: fdm=marker fdc=3