editorconfig-vim-0.3.3/000077500000000000000000000000001263534704700147755ustar00rootroot00000000000000editorconfig-vim-0.3.3/.editorconfig000066400000000000000000000005631263534704700174560ustar00rootroot00000000000000root = true [*] end_of_line = LF charset = utf-8 max_line_length = 80 [*.vim] indent_style = space indent_size = 4 insert_final_newline = true trim_trailing_whitespace = true max_line_length = 80 [*.rb] indent_style = space indent_size = 2 insert_final_newline = true trim_trailing_whitespace = true max_line_length = 120 [*.yml] indent_style = space indent_size = 2 editorconfig-vim-0.3.3/.gitignore000066400000000000000000000000051263534704700167600ustar00rootroot00000000000000tags editorconfig-vim-0.3.3/.gitmodules000066400000000000000000000002131263534704700171460ustar00rootroot00000000000000[submodule "tests/spec/plugin_tests"] path = tests/spec/plugin_tests url = https://github.com/editorconfig/editorconfig-plugin-tests.git editorconfig-vim-0.3.3/.travis.yml000066400000000000000000000004671263534704700171150ustar00rootroot00000000000000language: ruby rvm: - 1.9.3 gemfile: tests/Gemfile before_install: sudo apt-get install vim-gtk before_script: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" script: bundle exec rspec tests/spec/editorconfig_spec.rb notifications: email: on_success: change on_failure: always editorconfig-vim-0.3.3/CONTRIBUTORS000066400000000000000000000001171263534704700166540ustar00rootroot00000000000000Contributors to the EditorConfig Vim Plugin: Hong Xu Trey Hunner Kent Frazier editorconfig-vim-0.3.3/LICENSE000066400000000000000000000026011263534704700160010ustar00rootroot00000000000000Unless otherwise stated, all files are distributed under the Simplified BSD license included below. Copyright (c) 2011-2012 EditorConfig Team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. editorconfig-vim-0.3.3/README.md000066400000000000000000000066141263534704700162630ustar00rootroot00000000000000# EditorConfig Vim Plugin [![Build Status](https://travis-ci.org/editorconfig/editorconfig-vim.svg?branch=master)](https://travis-ci.org/editorconfig/editorconfig-vim) This is an [EditorConfig][] plugin for Vim. This plugin could be found on both [GitHub][] and [Vim online][]. ## Installation If your Vim is not compiled with `+python` feature (You can verify if the `+python` feature is included by running `:ver`. Most Linux distributions and with the official Windows binary have the `+python` feature enabled), please first download the [EditorConfig core][] and follow the instructions in the README and INSTALL files to install it. This plugin would NOT work if neither `+python` nor EditorConfig core is available. To install this plugin, you can use either of the following ways: - Download the archive and extract it into your Vim runtime directory (`~/.vim` on UNIX/Linux and `$VIM_INSTALLATION_FOLDER\vimfiles` on windows). - Use [pathogen][] (the git repository of this plugin is https://github.com/editorconfig/editorconfig-vim.git) - Use [Vundle][] by adding to your `.vimrc` Vundle plugins section: Plugin 'editorconfig/editorconfig-vim' Then remember to call `:PluginInstall`. ## Supported properties The EditorConfig Vim plugin supports the following EditorConfig [properties][]: * `indent_style` * `indent_size` * `tab_width` * `end_of_line` * `charset` * `insert_final_newline` (Feature +fixendofline (available on Vim 7.4.785+) or [PreserveNoEOL][] is required for this property) * `trim_trailing_whitespace` * `max_line_length` * `root` (only used by EditorConfig core) ## Recommended Options All of the options which are supported are documented in [editorconfig.txt][] and can be viewed by executing the following: `:help editorconfig`. #### Excluded patterns. To ensure that this plugin works well with [Tim Pope's fugitive][], use the following patterns array: > let g:EditorConfig_exclude_patterns = ['fugitive://.\*'] If you wanted to avoid loading EditorConfig for any remote files over ssh: > let g:EditorConfig_exclude_patterns = ['scp://.\*'] Of course these two items could be combined into the following: > let g:EditorConfig_exclude_patterns = ['fugitive://.\*', 'scp://.\*'] #### Exec Path The file path to the EditorConfig core executable. You could set this value in your |vimrc| like this: > let g:EditorConfig_exec_path = 'Path to your EditorConfig Core executable' ## Bugs and Feature Requests Feel free to submit bugs, feature requests, and other issues to the [issue tracker][]. Be sure you have read the [contribution guideline][]! [EditorConfig core]: https://github.com/editorconfig/editorconfig-core [EditorConfig]: http://editorconfig.org [GitHub]: https://github.com/editorconfig/editorconfig-vim [PreserveNoEOL]: http://www.vim.org/scripts/script.php?script_id=4550 [Tim Pope's fugitive]: https://github.com/tpope/vim-fugitive [Vim online]: http://www.vim.org/scripts/script.php?script_id=3934 [Vundle]: https://github.com/gmarik/Vundle.vim [contribution guideline]: https://github.com/editorconfig/editorconfig/blob/master/CONTRIBUTING.md#submitting-an-issue [issue tracker]: https://github.com/editorconfig/editorconfig-vim/issues [pathogen]: https://github.com/tpope/vim-pathogen [properties]: http://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties [editorconfig.txt]: https://github.com/editorconfig/editorconfig-vim/blob/master/doc/editorconfig.txt editorconfig-vim-0.3.3/autoload/000077500000000000000000000000001263534704700166055ustar00rootroot00000000000000editorconfig-vim-0.3.3/autoload/editorconfig.vim000066400000000000000000000036201263534704700217770ustar00rootroot00000000000000" Copyright (c) 2011-2012 EditorConfig Team " All rights reserved. " " Redistribution and use in source and binary forms, with or without " modification, are permitted provided that the following conditions are met: " " 1. Redistributions of source code must retain the above copyright notice, " this list of conditions and the following disclaimer. " 2. Redistributions in binary form must reproduce the above copyright notice, " this list of conditions and the following disclaimer in the documentation " and/or other materials provided with the distribution. " " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE " IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE " ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE " LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR " CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF " SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS " INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN " CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) " ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE " POSSIBILITY OF SUCH DAMAGE. " if v:version < 700 finish endif let s:saved_cpo = &cpo set cpo&vim " {{{1 variables let s:hook_list = [] function editorconfig#AddNewHook(func) " {{{1 " Add a new hook call add(s:hook_list, a:func) endfunction function editorconfig#ApplyHooks(config) " {{{1 " apply hooks for Hook in s:hook_list let l:hook_ret = Hook(a:config) if type(l:hook_ret) != type(0) && l:hook_ret != 0 " TODO print some debug info here endif endfor endfunction " }}} let &cpo = s:saved_cpo unlet! s:saved_cpo " vim: fdm=marker fdc=3 editorconfig-vim-0.3.3/doc/000077500000000000000000000000001263534704700155425ustar00rootroot00000000000000editorconfig-vim-0.3.3/doc/editorconfig.txt000066400000000000000000000216251263534704700207650ustar00rootroot00000000000000*editorconfig.txt* File: editorconfig.txt Version: 0.3.3 Maintainer: EditorConfig Team Description: EditorConfig vim plugin License: Copyright (c) 2011-2015 EditorConfig Team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. CONTENTS~ *editorconfig-contents* ---------------------------------------------------------------------------- 1. Overview |editorconfig-overview| 2. Installation |editorconfig-installation| 3. Commands |editorconfig-commands| 4. Settings |editorconfig-settings| 5. Advanced |editorconfig-advanced| OVERVIEW~ *editorconfig-overview* ---------------------------------------------------------------------------- This is the EditorConfig plugin for vim. INSTALLATION~ *editorconfig-installation* ---------------------------------------------------------------------------- Download the [EditorConfig core][] and follow the instructions in the README and INSTALL files to install it. Once EditorConfig core is installed, copy the `plugin/editorconfig.vim` file to your `~/.vim/plugin` directory, `autoload/editorconfig.vim` to `~/.vim/autoload` and `doc/editorconfig.txt` to your `~/.vim/doc` directory to install the EditorConfig plugin. COMMANDS~ *editorconfig-commands* ---------------------------------------------------------------------------- *:EditorConfigReload* Command: :EditorConfigReload Reload the EditorConfig conf files. When `.editorconfig` files are modified, this command could prevent you to reload the current edited file to load the new configuration. SETTINGS~ *editorconfig-settings* ---------------------------------------------------------------------------- *g:EditorConfig_core_mode* Specify the mode of EditorConfig core. Generally it is OK to leave this option empty. There are 3 modes currently: "external_command", "python_builtin", "python_external". python_builtin: Use the vim built-in python to run the python version EditorConfig Core. python_external: Use an external python interpreter to run the python version EditorConfig Core. external_command: Run external EditorConfig Core. If "g:EditorConfig_core_mode" is not specified, this plugin will automatically choose a mode that could work for you. The checking sequence is: python_builtin, external_command, python_external. *g:EditorConfig_exclude_patterns* This is a list contains file path patterns which will be ignored by EditorConfig plugin. When the path of the opened buffer (i.e. "expand('%:p')") matches any of the patterns in the list, EditorConfig will not load for this file. The default is an empty list. Example: Avoid loading EditorConfig for any remote files over ssh > let g:EditorConfig_exclude_patterns = ['scp://.*'] < *g:EditorConfig_exec_path* The file path to the EditorConfig core executable. You could set this value in your |vimrc| like this: > let g:EditorConfig_exec_path = 'Path to your EditorConfig Core executable' < The default value is empty. This plugin will search through the following executables in order: On UNIX: the value of g:EditorConfig_exec_path editorconfig /usr/local/bin/editorconfig /usr/bin/editorconfig /opt/bin/editorconfig /opt/editorconfig/bin/editorconfig editorconfig.py /usr/local/bin/editorconfig.py /usr/bin/editorconfig.py /opt/bin/editorconfig.py /opt/editorconfig/bin/editorconfig.py On Windows: the value of g:EditorConfig_exec_path editorconfig C:\editorconfig\bin\editorconfig D:\editorconfig\bin\editorconfig E:\editorconfig\bin\editorconfig F:\editorconfig\bin\editorconfig C:\Program Files\editorconfig\bin\editorconfig D:\Program Files\editorconfig\bin\editorconfig E:\Program Files\editorconfig\bin\editorconfig F:\Program Files\editorconfig\bin\editorconfig editorconfig.py *g:EditorConfig_max_line_indicator* The way to show the line where the maximal length is reached. Accepted values are "line", "fill", otherwise there will be no max line indicator. "line": the right column of the max line length column will be highlighted, made possible by setting 'colorcolumn' to "max_line_length + 1". "fill": all the columns to the right of the max line length column will be highlighted, made possible by setting 'colorcolumn' to a list of numbers starting from "max_line_length + 1" to the number of columns on the screen. "none": no max line length indicator will be shown. This is the recommended value when you do not want any indicator to be shown, but values other than "line" or "fill" would also work as "none". To set this option, add any of the following 3 lines to your |vimrc| file: > let g:EditorConfig_max_line_indicator = "line" let g:EditorConfig_max_line_indicator = "fill" let g:EditorConfig_max_line_indicator = "none" < Default to "line". *g:EditorConfig_python_files_dir* If the EditorConfig core mode is python_builtin or python_external (see |g:EditorConfig_core_mode|), this variable is the directory where the plugin looks for the python scripts. This could either be an abosolute path, or a path relative to any of the directories in 'runtimepath'. The default value is "plugin/editorconfig-core-py", which means all "plugin/editorconfig-core-py" directory in 'runtimepath' will be searched. *g:EditorConfig_preserve_formatoptions* Set this to 1 if you don't want your formatoptions modified when max_line_length is set: > let g:EditorConfig_preserve_formatoptions = 1 < This option defaults to 0. *g:EditorConfig_verbose* Set this to 1 if you want debug info printed: > let g:EditorConfig_verbose = 1 < ADVANCED~ *editorconfig-advanced* ---------------------------------------------------------------------------- *editorconfig-hook* *EditorConfig#AddNewHook()* While this plugin offers several builtin supported properties (as mentioned here: https://github.com/editorconfig/editorconfig-vim#supported-properties), we are also able to add our own hooks to support additional EditorConfig properties, including those not in the EditorConfig standard. For example, we are working on an Objective-C project, and all our "*.m" files should be Objective-C source files. However, vim sometimes detect "*.m" files as MATLAB source files, which causes incorrect syntax highlighting, code indentation, etc. To solve the case, we could write the following code into the |vimrc| file: > function! FiletypeHook(config) if has_key(a:config, 'vim_filetype') let &filetype = a:config['vim_filetype'] endif return 0 " Return 0 to show no error happened endfunction call editorconfig#AddNewHook(function('FiletypeHook')) < And add the following code to your .editorconfig file: > [*.m] vim_filetype = objc < Then try to open an Objective-C file, you will find the |filetype| is set to "objc". vim:ft=help:tw=78 editorconfig-vim-0.3.3/mkzip.sh000077500000000000000000000002041263534704700164620ustar00rootroot00000000000000#!/bin/sh zip -r editorconfig-vim-$*.zip plugin/editorconfig.vim plugin/editorconfig-core-py/* doc/editorconfig.txt autoload/*.vim editorconfig-vim-0.3.3/plugin/000077500000000000000000000000001263534704700162735ustar00rootroot00000000000000editorconfig-vim-0.3.3/plugin/editorconfig.vim000066400000000000000000000461071263534704700214740ustar00rootroot00000000000000" Copyright (c) 2011-2015 EditorConfig Team " All rights reserved. " " Redistribution and use in source and binary forms, with or without " modification, are permitted provided that the following conditions are met: " " 1. Redistributions of source code must retain the above copyright notice, " this list of conditions and the following disclaimer. " 2. Redistributions in binary form must reproduce the above copyright notice, " this list of conditions and the following disclaimer in the documentation " and/or other materials provided with the distribution. " " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE " IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE " ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE " LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR " CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF " SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS " INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN " CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) " ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE " POSSIBILITY OF SUCH DAMAGE. " if v:version < 700 finish endif " check whether this script is already loaded if exists("g:loaded_EditorConfig") finish endif let g:loaded_EditorConfig = 1 let s:saved_cpo = &cpo set cpo&vim " variables {{{1 if !exists('g:EditorConfig_exec_path') let g:EditorConfig_exec_path = '' endif if !exists('g:EditorConfig_python_files_dir') let g:EditorConfig_python_files_dir = 'plugin/editorconfig-core-py' endif if !exists('g:EditorConfig_verbose') let g:EditorConfig_verbose = 0 endif if !exists('g:EditorConfig_preserve_formatoptions') let g:EditorConfig_preserve_formatoptions = 0 endif if !exists('g:EditorConfig_max_line_indicator') let g:EditorConfig_max_line_indicator = 'line' endif if !exists('g:EditorConfig_exclude_patterns') let g:EditorConfig_exclude_patterns = [] endif if exists('g:EditorConfig_core_mode') && !empty(g:EditorConfig_core_mode) let s:editorconfig_core_mode = g:EditorConfig_core_mode else let s:editorconfig_core_mode = '' endif function! s:FindPythonInterp() " {{{1 " Find python interp. If found, return python command; if not found, return '' if has('unix') let l:searching_list = [ \ 'python', \ 'python27', \ 'python26', \ 'python25', \ 'python24', \ '/usr/local/bin/python', \ '/usr/local/bin/python27', \ '/usr/local/bin/python26', \ '/usr/local/bin/python25', \ '/usr/local/bin/python24', \ '/usr/bin/python', \ '/usr/bin/python27', \ '/usr/bin/python26', \ '/usr/bin/python25', \ '/usr/bin/python24'] elseif has('win32') let l:searching_list = [ \ 'python', \ 'python27', \ 'python26', \ 'python25', \ 'python24', \ 'C:\Python27\python.exe', \ 'C:\Python26\python.exe', \ 'C:\Python25\python.exe', \ 'C:\Python24\python.exe'] endif for possible_python_interp in l:searching_list if executable(possible_python_interp) return possible_python_interp endif endfor return '' endfunction function! s:FindPythonFiles() " {{{1 " Find EditorConfig Core python files " On Windows, we still use slash rather than backslash let l:old_shellslash = &shellslash set shellslash let l:python_core_files_dir = fnamemodify( \ findfile(g:EditorConfig_python_files_dir . '/main.py', \ ','.&runtimepath), ':p:h') if empty(l:python_core_files_dir) let l:python_core_files_dir = '' else " expand python core file path to full path, and remove the appending '/' let l:python_core_files_dir = substitute( \ fnamemodify(l:python_core_files_dir, ':p'), '/$', '', '') endif let &shellslash = l:old_shellslash return l:python_core_files_dir endfunction " Mode initialization functions {{{1 function! s:InitializeExternalCommand() " {{{2 " Initialize external_command mode let s:EditorConfig_exec_path = '' " User has specified an EditorConfig command. Use that one. if exists('g:EditorConfig_exec_path') && \ !empty(g:EditorConfig_exec_path) if executable(g:EditorConfig_exec_path) let s:EditorConfig_exec_path = g:EditorConfig_exec_path return 0 else return 1 endif endif " User does not specify an EditorConfig command. Let's search for it. if has('unix') let l:searching_list = [ \ 'editorconfig', \ '/usr/local/bin/editorconfig', \ '/usr/bin/editorconfig', \ '/opt/bin/editorconfig', \ '/opt/editorconfig/bin/editorconfig', \ 'editorconfig.py', \ '/usr/local/bin/editorconfig.py', \ '/usr/bin/editorconfig.py', \ '/opt/bin/editorconfig.py', \ '/opt/editorconfig/bin/editorconfig.py'] elseif has('win32') let l:searching_list = [ \ 'editorconfig', \ 'C:\editorconfig\bin\editorconfig', \ 'D:\editorconfig\bin\editorconfig', \ 'E:\editorconfig\bin\editorconfig', \ 'F:\editorconfig\bin\editorconfig', \ 'C:\Program Files\editorconfig\bin\editorconfig', \ 'D:\Program Files\editorconfig\bin\editorconfig', \ 'E:\Program Files\editorconfig\bin\editorconfig', \ 'F:\Program Files\editorconfig\bin\editorconfig', \ 'C:\Program Files (x86)\editorconfig\bin\editorconfig', \ 'D:\Program Files (x86)\editorconfig\bin\editorconfig', \ 'E:\Program Files (x86)\editorconfig\bin\editorconfig', \ 'F:\Program Files (x86)\editorconfig\bin\editorconfig', \ 'editorconfig.py'] endif " search for editorconfig core executable for possible_cmd in l:searching_list if executable(possible_cmd) let s:EditorConfig_exec_path = possible_cmd break endif endfor if empty(s:EditorConfig_exec_path) return 2 endif return 0 endfunction function! s:InitializePythonExternal() " {{{2 " Initialize external python. Before calling this function, please make sure " s:FindPythonFiles is called and the return value is set to " s:editorconfig_core_py_dir if !exists('s:editorconfig_core_py_dir') || \ empty(s:editorconfig_core_py_dir) return 2 endif " Find python interp if !exists('g:editorconfig_python_interp') || \ empty('g:editorconfig_python_interp') let s:editorconfig_python_interp = s:FindPythonInterp() endif if empty(s:editorconfig_python_interp) || \ !executable(s:editorconfig_python_interp) return 1 endif return 0 endfunction function! s:InitializePythonBuiltin(editorconfig_core_py_dir) " {{{2 " Initialize builtin python. The parameter is the Python Core directory if exists('s:builtin_python_initialized') && s:builtin_python_initialized return 0 endif let s:builtin_python_initialized = 1 let l:ret = 0 if !has('python') return 1 endif python << EEOOFF try: import vim import sys except: vim.command('let l:ret = 2') EEOOFF if l:ret != 0 return l:ret endif python << EEOOFF try: sys.path.insert(0, vim.eval('a:editorconfig_core_py_dir')) import editorconfig import editorconfig.exceptions as editorconfig_except except: vim.command('let l:ret = 3') del sys.path[0] ec_data = {} # used in order to keep clean Python namespace EEOOFF if l:ret != 0 return l:ret endif return 0 endfunction " Do some initalization for the case that the user has specified core mode {{{1 if !empty(s:editorconfig_core_mode) if s:editorconfig_core_mode == 'external_command' if s:InitializeExternalCommand() echo 'EditorConfig: Failed to initialize external_command mode' finish endif else let s:editorconfig_core_py_dir = s:FindPythonFiles() if empty(s:editorconfig_core_py_dir) echo 'EditorConfig: '. \ 'EditorConfig Python Core files could not be found.' finish endif if s:editorconfig_core_mode == 'python_builtin' && \ s:InitializePythonBuiltin(s:editorconfig_core_py_dir) echo 'EditorConfig: Failed to initialize vim built-in python.' finish elseif s:editorconfig_core_mode == 'python_external' && \ s:InitializePythonExternal() echo 'EditorConfig: Failed to find external Python interpreter.' finish endif endif endif " Determine the editorconfig_core_mode we should use {{{1 while 1 " If user has specified a mode, just break if exists('s:editorconfig_core_mode') && !empty(s:editorconfig_core_mode) break endif " Find Python core files. If not found, we try external_command mode let s:editorconfig_core_py_dir = s:FindPythonFiles() if empty(s:editorconfig_core_py_dir) " python files are not found if !s:InitializeExternalCommand() let s:editorconfig_core_mode = 'external_command' endif break endif " Builtin python mode first if !s:InitializePythonBuiltin(s:editorconfig_core_py_dir) let s:editorconfig_core_mode = 'python_builtin' break endif " Then external_command mode if !s:InitializeExternalCommand() let s:editorconfig_core_mode = 'external_command' break endif " Finally external python mode if !s:InitializePythonExternal() let s:editorconfig_core_mode = 'python_external' break endif break endwhile " No EditorConfig Core is available if empty(s:editorconfig_core_mode) echo "EditorConfig: ". \ "No EditorConfig Core is available. The plugin won't work." finish endif function! s:UseConfigFiles() " ignore buffers without a name if empty(expand('%:p')) return endif " Ignore specific patterns for pattern in g:EditorConfig_exclude_patterns if expand('%:p') =~ pattern return endif endfor if s:editorconfig_core_mode == 'external_command' call s:UseConfigFiles_ExternalCommand() elseif s:editorconfig_core_mode == 'python_builtin' call s:UseConfigFiles_Python_Builtin() elseif s:editorconfig_core_mode == 'python_external' call s:UseConfigFiles_Python_External() else echohl Error | \ echo "Unknown EditorConfig Core: " . \ s:editorconfig_core_mode | \ echohl None endif endfunction " command, autoload {{{1 command! EditorConfigReload call s:UseConfigFiles() " Reload EditorConfig files augroup editorconfig autocmd! autocmd BufNewFile,BufReadPost,BufFilePost * call s:UseConfigFiles() autocmd BufNewFile,BufRead .editorconfig set filetype=dosini augroup END " UseConfigFiles function for different mode {{{1 function! s:UseConfigFiles_Python_Builtin() " {{{2 " Use built-in python to run the python EditorConfig core let l:config = {} let l:ret = 0 " ignore buffers that do not have a file path associated if empty(expand('%:p')) return 0 endif python << EEOOFF ec_data['filename'] = vim.eval("expand('%:p')") ec_data['conf_file'] = ".editorconfig" try: ec_data['options'] = editorconfig.get_properties(ec_data['filename']) except editorconfig_except.EditorConfigError as e: if int(vim.eval('g:EditorConfig_verbose')) != 0: print >> sys.stderr, str(e) vim.command('let l:ret = 1') EEOOFF if l:ret != 0 return l:ret endif python << EEOOFF for key, value in ec_data['options'].items(): vim.command("let l:config['" + key.replace("'", "''") + "'] = " + "'" + value.replace("'", "''") + "'") EEOOFF call s:ApplyConfig(l:config) return 0 endfunction function! s:UseConfigFiles_Python_External() " {{{2 " Use external python interp to run the python EditorConfig Core let l:cmd = s:editorconfig_python_interp . ' ' . \ s:editorconfig_core_py_dir . '/main.py' call s:SpawnExternalParser(l:cmd) return 0 endfunction function! s:UseConfigFiles_ExternalCommand() " {{{2 " Use external EditorConfig core (The C core, or editorconfig.py) call s:SpawnExternalParser(s:EditorConfig_exec_path) endfunction function! s:SpawnExternalParser(cmd) " {{{2 " Spawn external EditorConfig. Used by s:UseConfigFiles_Python_External() and " s:UseConfigFiles_ExternalCommand() let l:cmd = a:cmd " ignore buffers that do not have a file path associated if empty(expand("%:p")) return endif " if editorconfig is present, we use this as our parser if !empty(l:cmd) let l:config = {} " In Windows, 'shellslash' also changes the behavior of 'shellescape'. " It makes 'shellescape' behave like in UNIX environment. So ':setl " noshellslash' before evaluating 'shellescape' and restore the " settings afterwards when 'shell' does not contain 'sh' somewhere. if has('win32') && empty(matchstr(&shell, 'sh')) let l:old_shellslash = &l:shellslash setlocal noshellslash endif let l:cmd = l:cmd . ' ' . shellescape(expand('%:p')) " restore 'shellslash' if exists('l:old_shellslash') let &l:shellslash = l:old_shellslash endif let l:parsing_result = split(system(l:cmd), '\n') " if editorconfig core's exit code is not zero, give out an error " message if v:shell_error != 0 echohl ErrorMsg echo 'Failed to execute "' . l:cmd . '". Exit code: ' . \ v:shell_error echo '' echo 'Message:' echo l:parsing_result echohl None return endif for one_line in l:parsing_result let l:eq_pos = stridx(one_line, '=') if l:eq_pos == -1 " = is not found. Skip this line continue endif let l:eq_left = strpart(one_line, 0, l:eq_pos) if l:eq_pos + 1 < strlen(one_line) let l:eq_right = strpart(one_line, l:eq_pos + 1) else let l:eq_right = '' endif let l:config[l:eq_left] = l:eq_right endfor call s:ApplyConfig(l:config) endif endfunction function! s:ApplyConfig(config) " {{{1 " Only process normal buffers (do not treat help files as '.txt' files) if !empty(&buftype) return endif " Set the indentation style according to the config values if has_key(a:config, "indent_style") if a:config["indent_style"] == "tab" setl noexpandtab elseif a:config["indent_style"] == "space" setl expandtab endif endif if has_key(a:config, "tab_width") let &l:tabstop = str2nr(a:config["tab_width"]) endif if has_key(a:config, "indent_size") " if indent_size is 'tab', set shiftwidth to tabstop; " if indent_size is a positive integer, set shiftwidth to the integer " value if a:config["indent_size"] == "tab" let &l:shiftwidth = &l:tabstop let &l:softtabstop = &l:shiftwidth else let l:indent_size = str2nr(a:config["indent_size"]) if l:indent_size > 0 let &l:shiftwidth = l:indent_size let &l:softtabstop = &l:shiftwidth endif endif endif if has_key(a:config, "end_of_line") && &l:modifiable if a:config["end_of_line"] == "lf" setl fileformat=unix elseif a:config["end_of_line"] == "crlf" setl fileformat=dos elseif a:config["end_of_line"] == "cr" setl fileformat=mac endif endif if has_key(a:config, "charset") && &l:modifiable if a:config["charset"] == "utf-8" setl fileencoding=utf-8 setl nobomb elseif a:config["charset"] == "utf-8-bom" setl fileencoding=utf-8 setl bomb elseif a:config["charset"] == "latin1" setl fileencoding=latin1 setl nobomb elseif a:config["charset"] == "utf-16be" setl fileencoding=utf-16be setl bomb elseif a:config["charset"] == "utf-16le" setl fileencoding=utf-16le setl bomb endif endif augroup editorconfig_trim_trailing_whitespace autocmd! BufWritePre if get(a:config, 'trim_trailing_whitespace', 'false') ==# 'true' autocmd BufWritePre call s:TrimTrailingWhitespace() endif augroup END if has_key(a:config, "insert_final_newline") if exists('+fixendofline') if a:config["insert_final_newline"] == "false" setl nofixendofline else setl fixendofline endif elseif exists(':SetNoEOL') == 2 if a:config["insert_final_newline"] == "false" silent! SetNoEOL " Use the PreserveNoEOL plugin to accomplish it endif endif endif " highlight the columns following max_line_length if has_key(a:config, 'max_line_length') let l:max_line_length = str2nr(a:config['max_line_length']) if l:max_line_length >= 0 let &l:textwidth = l:max_line_length if g:EditorConfig_preserve_formatoptions == 0 setlocal formatoptions+=tc endif endif if exists('+colorcolumn') if l:max_line_length > 0 if g:EditorConfig_max_line_indicator == 'line' let &l:colorcolumn = l:max_line_length + 1 elseif g:EditorConfig_max_line_indicator == 'fill' let &l:colorcolumn = join( \ range(l:max_line_length+1,&l:columns),',') endif endif endif endif call editorconfig#ApplyHooks(a:config) endfunction " }}} function! s:TrimTrailingWhitespace() " {{{{ " don't lose user position when trimming trailing whitespace let s:view = winsaveview() try %s/\s\+$//e finally call winrestview(s:view) endtry endfunction " }}} let &cpo = s:saved_cpo unlet! s:saved_cpo " vim: fdm=marker fdc=3 editorconfig-vim-0.3.3/tests/000077500000000000000000000000001263534704700161375ustar00rootroot00000000000000editorconfig-vim-0.3.3/tests/Gemfile000066400000000000000000000001541263534704700174320ustar00rootroot00000000000000source 'https://rubygems.org' gem 'rake', '~> 10.1.0' gem 'rspec', '~> 2.14.1' gem 'vimrunner', '~> 0.3.0' editorconfig-vim-0.3.3/tests/Gemfile.lock000066400000000000000000000006551263534704700203670ustar00rootroot00000000000000GEM remote: https://rubygems.org/ specs: diff-lcs (1.2.4) rake (10.1.0) rspec (2.14.1) rspec-core (~> 2.14.0) rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) rspec-core (2.14.5) rspec-expectations (2.14.2) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.14.3) vimrunner (0.3.0) PLATFORMS ruby DEPENDENCIES rake (~> 10.1.0) rspec (~> 2.14.1) vimrunner (~> 0.3.0) editorconfig-vim-0.3.3/tests/Rakefile000066400000000000000000000001661263534704700176070ustar00rootroot00000000000000# # run `rake` to run tests require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task :default => :spec editorconfig-vim-0.3.3/tests/spec/000077500000000000000000000000001263534704700170715ustar00rootroot00000000000000editorconfig-vim-0.3.3/tests/spec/.editorconfig000066400000000000000000000000751263534704700215500ustar00rootroot00000000000000[*.rb] indent_style = space indent_size = 2 end_of_line = LF editorconfig-vim-0.3.3/tests/spec/editorconfig_spec.rb000066400000000000000000000047661263534704700231210ustar00rootroot00000000000000require 'vimrunner' $vim = Vimrunner.start $vim.add_plugin(File.expand_path('../../..', __FILE__), 'plugin/editorconfig.vim') # The base path of the testing files BASE_PATH = File.expand_path('../plugin_tests/test_files/', __FILE__) # file_name is the file name that should be open by Vim # expected_values is a Hash that contains all the Vim options we need to test def test_editorconfig(file_name, expected_values) $vim.edit(File.join(BASE_PATH, file_name)) expected_values.each do |key, val| $vim.echo("&l:#{key}").should == val end $vim.command 'bd!' end describe 'plugin/editorconfig.vim' do after(:all) do $vim.kill end describe '#all' do it '3_space.py' do test_editorconfig '3_space.txt', expandtab: '1', shiftwidth: '3', tabstop: '3' end end it '4_space.py' do test_editorconfig '4_space.py', expandtab: '1', shiftwidth: '4', tabstop: '8' end it 'space.txt' do test_editorconfig 'space.txt', expandtab: '1', shiftwidth: $vim.echo('&l:tabstop') end it 'tab.txt' do test_editorconfig 'tab.txt', expandtab: '0' end it '4_tab.txt' do test_editorconfig '4_tab.txt', expandtab: '0', shiftwidth: '4', tabstop: '4' end it '4_tab_width_of_8' do test_editorconfig '4_tab_width_of_8.txt', expandtab: '0', shiftwidth: '4', tabstop: '8' end it 'lf.txt' do test_editorconfig 'lf.txt', fileformat: 'unix' end it 'crlf.txt' do test_editorconfig 'crlf.txt', fileformat: 'dos' end it 'cr.txt' do test_editorconfig 'cr.txt', fileformat: 'mac' end it 'utf-8.txt' do test_editorconfig 'utf-8.txt', fileencoding: 'utf-8', bomb: '0' end it 'utf-8-bom.txt' do test_editorconfig 'utf-8-bom.txt', fileencoding: 'utf-8', bomb: '1' end it 'utf-16be.txt' do test_editorconfig 'utf-16be.txt', fileencoding: 'utf-16' end it 'utf-16le.txt' do test_editorconfig 'utf-16le.txt', fileencoding: 'utf-16le' end it 'latin1.txt' do test_editorconfig 'latin1.txt', fileencoding: 'latin1' end # insert_final_newline by PreserveNoEOL tests are omitted, since they are not supported if $vim.echo("exists('+fixendofline')") == '1' it 'with_newline.txt' do test_editorconfig 'with_newline.txt', fixendofline: '1' end it 'without_newline.txt' do test_editorconfig 'without_newline.txt', fixendofline: '0' end end end editorconfig-vim-0.3.3/tests/spec/plugin_tests/000077500000000000000000000000001263534704700216115ustar00rootroot00000000000000