Skip to content

Commit

Permalink
Make list of ignored syntax groups configurable
Browse files Browse the repository at this point in the history
While trying to fix issue #20 I decided to refactor the code that
handles ignored syntax groups: Previously the list of excluded groups
was hard coded in two places, now it's a configuration option. Then
it turned out that including shFunction* in the list of excluded
syntax groups didn't fix the reported issue...
  • Loading branch information
xolox committed Oct 29, 2011
1 parent 3d7e091 commit e3290ab
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -159,6 +159,10 @@ If this is set and not false, it will suppress the warning on startup if ctags i

:let g:easytags_suppress_ctags_warning = 1

### The `g:easytags_ignored_syntax_groups` option

This variable is a string of comma separated names of syntax groups in which dynamic highlighting is not applied. It defaults to `.*String.*,.*Comment.*,cIncluded`.

## Faster syntax highlighting using Python

The Vim script implementation of dynamic syntax highlighting is quite slow on large tags files. When the Python Interface to Vim is enabled the easytags plug-in will therefor automatically use a Python script that performs dynamic syntax highlighting about twice as fast as the Vim script implementation. The following options are available to change the default configuration.
Expand Down
10 changes: 6 additions & 4 deletions autoload/xolox/easytags.vim
@@ -1,9 +1,9 @@
" Vim script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: October 1, 2011
" Last Change: October 29, 2011
" URL: http://peterodding.com/code/vim/easytags/

let g:xolox#easytags#version = '2.7'
let g:xolox#easytags#version = '2.7.1'

" Public interface through (automatic) commands. {{{1

Expand Down Expand Up @@ -315,8 +315,9 @@ function! xolox#easytags#highlight() " {{{2
" Convert matched tags to :syntax command and execute it.
call map(matches, 'xolox#misc#escape#pattern(get(v:val, "name"))')
let pattern = tagkind.pattern_prefix . '\%(' . join(xolox#misc#list#unique(matches), '\|') . '\)' . tagkind.pattern_suffix
let template = 'syntax match %s /%s/ containedin=ALLBUT,.*String.*,.*Comment.*,cIncluded'
let command = printf(template, hlgroup_tagged, escape(pattern, '/'))
let template = 'syntax match %s /%s/ containedin=ALLBUT,%s'
let command = printf(template, hlgroup_tagged, escape(pattern, '/'), xolox#misc#option#get('easytags_ignored_syntax_groups'))
call xolox#misc#msg#debug("easytags.vim %s: Executing command '%s'.", g:xolox#easytags#version, command)
try
execute command
catch /^Vim\%((\a\+)\)\=:E339/
Expand Down Expand Up @@ -677,6 +678,7 @@ function! s:highlight_with_python(syntax_group, tagkind) " {{{2
let context['prefix'] = get(a:tagkind, 'pattern_prefix', '')
let context['suffix'] = get(a:tagkind, 'pattern_suffix', '')
let context['filters'] = get(a:tagkind, 'python_filter', {})
let context['ignoresyntax'] = xolox#misc#option#get('easytags_ignored_syntax_groups')
" Call the Python function and intercept the output.
try
redir => commands
Expand Down
6 changes: 6 additions & 0 deletions doc/easytags.txt
Expand Up @@ -321,6 +321,12 @@ is not found or not recent enough.
>
:let g:easytags_suppress_ctags_warning = 1
-------------------------------------------------------------------------------
The *g:easytags_ignored_syntax_groups* option

This variable is a string of comma separated names of syntax groups in which
dynamic highlighting is not applied. It defaults to '.*String.*,.*Comment.*,cIncluded'.

===============================================================================
*easytags-faster-syntax-highlighting-using-python*
Faster syntax highlighting using Python ~
Expand Down
14 changes: 7 additions & 7 deletions misc/easytags/highlight.py
Expand Up @@ -5,7 +5,7 @@
generation in Python with a focus on doing the least amount of work.
Author: Peter Odding <peter@peterodding.com>
Last Change: June 14, 2011
Last Change: October 29, 2011
URL: http://peterodding.com/code/vim/easytags
'''

Expand All @@ -18,7 +18,7 @@
def easytags_ping():
print 'it works!'

def easytags_gensyncmd(tagsfiles, filetype, tagkinds, syntaxgroup, prefix, suffix, filters):
def easytags_gensyncmd(tagsfiles, filetype, tagkinds, syntaxgroup, prefix, suffix, filters, ignoresyntax):
# Get arguments from Vim.
if filters:
tagkinds = filters['kind']
Expand All @@ -43,13 +43,13 @@ def easytags_gensyncmd(tagsfiles, filetype, tagkinds, syntaxgroup, prefix, suffi
patterns.append(escaped)
counter += len(escaped)
if counter > limit:
commands.append(_easytags_makecmd(syntaxgroup, prefix, suffix, patterns))
commands.append(_easytags_makecmd(syntaxgroup, prefix, suffix, patterns, ignoresyntax))
patterns = []
counter = 0
if patterns:
commands.append(_easytags_makecmd(syntaxgroup, prefix, suffix, patterns))
commands.append(_easytags_makecmd(syntaxgroup, prefix, suffix, patterns, ignoresyntax))
return ' | '.join(commands)

def _easytags_makecmd(syntaxgroup, prefix, suffix, patterns):
template = r'syntax match %s /%s\%%(%s\)%s/ containedin=ALLBUT,.*String.*,.*Comment.*,cIncluded'
return template % (syntaxgroup, prefix, r'\|'.join(patterns), suffix)
def _easytags_makecmd(syntaxgroup, prefix, suffix, patterns, ignoresyntax):
template = r'syntax match %s /%s\%%(%s\)%s/ containedin=ALLBUT,%s'
return template % (syntaxgroup, prefix, r'\|'.join(patterns), suffix, ignoresyntax)
6 changes: 5 additions & 1 deletion plugin/easytags.vim
@@ -1,6 +1,6 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
" Last Change: September 26, 2011
" Last Change: October 29, 2011
" URL: http://peterodding.com/code/vim/easytags/
" Requires: Exuberant Ctags (http://ctags.sf.net)

Expand Down Expand Up @@ -40,6 +40,10 @@ if !exists('g:easytags_ignored_filetypes')
let g:easytags_ignored_filetypes = '^tex$'
endif

if !exists('g:easytags_ignored_syntax_groups')
let g:easytags_ignored_syntax_groups = '.*String.*,.*Comment.*,cIncluded'
endif

if !exists('g:easytags_python_script')
let g:easytags_python_script = expand('<sfile>:p:h') . '/../misc/easytags/highlight.py'
endif
Expand Down

0 comments on commit e3290ab

Please sign in to comment.