Skip to content

Instantly share code, notes, and snippets.

@chrisbra
Created March 30, 2016 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisbra/45a9cb6b7168458e5cb307457a17ffa1 to your computer and use it in GitHub Desktop.
Save chrisbra/45a9cb6b7168458e5cb307457a17ffa1 to your computer and use it in GitHub Desktop.
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index f71c4ad..6b1b067 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -7374,7 +7374,8 @@ A jump table for the options with a short description can be found at |Q_op|.
By default, tag searches are case-sensitive. Case is ignored when
'ignorecase' is set and 'tagcase' is "followic", or when 'tagcase' is
- "ignore".
+ "ignore" or when 'tagcase' is "followscs" and 'smartcase' is set and
+ the pattern contains only lowercase characters.
When 'tagbsearch' is off, tags searching is slower when a full match
exists, but faster when no full match exists. Tags in unsorted tags
@@ -7395,6 +7396,7 @@ A jump table for the options with a short description can be found at |Q_op|.
followic Follow the 'ignorecase' option
ignore Ignore case
match Match case
+ followscs Follow the 'smartcase' (and 'ignorecase') option.
*'taglength'* *'tl'*
'taglength' 'tl' number (default 0)
diff --git a/runtime/doc/tagsrch.txt b/runtime/doc/tagsrch.txt
index 86a00f4..5e48895 100644
--- a/runtime/doc/tagsrch.txt
+++ b/runtime/doc/tagsrch.txt
@@ -86,12 +86,15 @@ changed, to avoid confusion when using ":tnext". It is changed when using
The ignore-case matches are not found for a ":tag" command when the
'ignorecase' option is off and 'tagcase' is "followic" or when 'tagcase' is
-"match". They are found when a pattern is used (starting with a "/") and for
-":tselect", also when 'ignorecase' is off and 'tagcase' is "followic" or when
-'tagcase' is "match". Note that using ignore-case tag searching disables
-binary searching in the tags file, which causes a slowdown. This can be
-avoided by fold-case sorting the tag file. See the 'tagbsearch' option for an
-explanation.
+"match" or 'tagcase' is "followscs" and 'smartcase' option is on and the
+pattern does contain an upper case character. They are found when a pattern is
+used (starting with a "/") and for ":tselect", also when 'ignorecase' is off
+and 'tagcase' is "followic" or when 'tagcase' is "match" or when 'tagcase' is
+"followscs" and the 'smartcase' option is off.
+
+Note that using ignore-case tag searching disables binary searching in the
+tags file, which causes a slowdown. This can be avoided by fold-case sorting
+the tag file. See the 'tagbsearch' option for an explanation.
==============================================================================
2. Tag stack *tag-stack* *tagstack* *E425*
@@ -444,7 +447,9 @@ The next file in the list is not used when:
- A matching global tag has been found.
This also depends on whether case is ignored. Case is ignored when
'ignorecase' is set and 'tagcase' is "followic", or when 'tagcase' is
-"ignore". If case is not ignored, and the tags file only has a match without
+"ignore", or when 'smartcase' is set and 'tagcase' is "followscs" and the
+pattern only contains lower case characters.
+If case is not ignored, and the tags file only has a match without
matching case, the next tags file is searched for a match with matching case.
If no tag with matching case is found, the first match without matching case
is used. If case is ignored, and a matching global tag with or without
diff --git a/src/option.h b/src/option.h
index cf7ba04..62e658a 100644
--- a/src/option.h
+++ b/src/option.h
@@ -822,11 +822,12 @@ EXTERN int p_tbs; /* 'tagbsearch' */
EXTERN char_u *p_tc; /* 'tagcase' */
EXTERN unsigned tc_flags; /* flags from 'tagcase' */
#ifdef IN_OPTION_C
-static char *(p_tc_values[]) = {"followic", "ignore", "match", NULL};
+static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", NULL};
#endif
#define TC_FOLLOWIC 0x01
#define TC_IGNORE 0x02
#define TC_MATCH 0x04
+#define TC_FOLLOWSCS 0x08
EXTERN long p_tl; /* 'taglength' */
EXTERN int p_tr; /* 'tagrelative' */
EXTERN char_u *p_tags; /* 'tags' */
diff --git a/src/tag.c b/src/tag.c
index 1541259..d92d335 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -1389,6 +1389,7 @@ find_tags(
case TC_FOLLOWIC: break;
case TC_IGNORE: p_ic = TRUE; break;
case TC_MATCH: p_ic = FALSE; break;
+ case TC_FOLLOWSCS: p_ic = ignorecase(pat); break;
}
help_save = curbuf->b_help;
diff --git a/src/testdir/test_tagcase.in b/src/testdir/test_tagcase.in
index d76dbab..acb6d20 100644
--- a/src/testdir/test_tagcase.in
+++ b/src/testdir/test_tagcase.in
@@ -10,7 +10,7 @@ STARTTEST
:"
:" Verify default values.
:set ic& | setg tc& | setl tc&
-:call append('$', "ic=".&ic." g:tc=".&g:tc." l:tc=".&l:tc." tc=".&tc)
+:call append('$', "ic=".&ic." g:tc=".&g:tc." l:tc=".&l:tc." tc=".&tc. " scs=".&scs)
:"
:" Verify that the local setting accepts <empty> but that the global setting
:" does not. The first of these (setting the local value to <empty>) should
@@ -27,12 +27,14 @@ STARTTEST
:"
:" Verify that the correct number of matching tags is found for all values of
:" 'ignorecase' and global and local values 'tagcase', in all combinations.
-:for &ic in [0, 1]
-: for &g:tc in ["followic", "ignore", "match"]
-: for &l:tc in ["", "followic", "ignore", "match"]
-: call append('$', "ic=".&ic." g:tc=".&g:tc." l:tc=".&l:tc." tc=".&tc)
-: call append('$', len(taglist("^foo$")))
-: call append('$', len(taglist("^Foo$")))
+:for &scs in [0, 1]
+: for &ic in [0, 1]
+: for &g:tc in ["followic", "ignore", "match", "followscs"]
+: for &l:tc in ["", "followic", "ignore", "match", "followscs"]
+: call append('$', "ic=".&ic." g:tc=".&g:tc." l:tc=".&l:tc." tc=".&tc. " scs=".&scs)
+: call append('$', 'foo: '. len(taglist("^foo$")))
+: call append('$', 'Foo: '. len(taglist("^Foo$")))
+: endfor
: endfor
: endfor
:endfor
diff --git a/src/testdir/test_tagcase.ok b/src/testdir/test_tagcase.ok
index fe161cf..96e1d37 100644
--- a/src/testdir/test_tagcase.ok
+++ b/src/testdir/test_tagcase.ok
@@ -1,76 +1,244 @@
-ic=0 g:tc=followic l:tc=followic tc=followic
+ic=0 g:tc=followic l:tc=followic tc=followic scs=0
E474: Invalid argument: tc=
E474: Invalid argument: tc=
-ic=0 g:tc=followic l:tc= tc=followic
-1
-1
-ic=0 g:tc=followic l:tc=followic tc=followic
-1
-1
-ic=0 g:tc=followic l:tc=ignore tc=ignore
-2
-2
-ic=0 g:tc=followic l:tc=match tc=match
-1
-1
-ic=0 g:tc=ignore l:tc= tc=ignore
-2
-2
-ic=0 g:tc=ignore l:tc=followic tc=followic
-1
-1
-ic=0 g:tc=ignore l:tc=ignore tc=ignore
-2
-2
-ic=0 g:tc=ignore l:tc=match tc=match
-1
-1
-ic=0 g:tc=match l:tc= tc=match
-1
-1
-ic=0 g:tc=match l:tc=followic tc=followic
-1
-1
-ic=0 g:tc=match l:tc=ignore tc=ignore
-2
-2
-ic=0 g:tc=match l:tc=match tc=match
-1
-1
-ic=1 g:tc=followic l:tc= tc=followic
-2
-2
-ic=1 g:tc=followic l:tc=followic tc=followic
-2
-2
-ic=1 g:tc=followic l:tc=ignore tc=ignore
-2
-2
-ic=1 g:tc=followic l:tc=match tc=match
-1
-1
-ic=1 g:tc=ignore l:tc= tc=ignore
-2
-2
-ic=1 g:tc=ignore l:tc=followic tc=followic
-2
-2
-ic=1 g:tc=ignore l:tc=ignore tc=ignore
-2
-2
-ic=1 g:tc=ignore l:tc=match tc=match
-1
-1
-ic=1 g:tc=match l:tc= tc=match
-1
-1
-ic=1 g:tc=match l:tc=followic tc=followic
-2
-2
-ic=1 g:tc=match l:tc=ignore tc=ignore
-2
-2
-ic=1 g:tc=match l:tc=match tc=match
-1
-1
+ic=0 g:tc=followic l:tc= tc=followic scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=followic l:tc=followic tc=followic scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=followic l:tc=ignore tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=0 g:tc=followic l:tc=match tc=match scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=followic l:tc=followscs tc=followscs scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=ignore l:tc= tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=0 g:tc=ignore l:tc=followic tc=followic scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=ignore l:tc=ignore tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=0 g:tc=ignore l:tc=match tc=match scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=ignore l:tc=followscs tc=followscs scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=match l:tc= tc=match scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=match l:tc=followic tc=followic scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=match l:tc=ignore tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=0 g:tc=match l:tc=match tc=match scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=match l:tc=followscs tc=followscs scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=followscs l:tc= tc=followscs scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=followscs l:tc=followic tc=followic scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=followscs l:tc=ignore tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=0 g:tc=followscs l:tc=match tc=match scs=0
+foo: 1
+Foo: 1
+ic=0 g:tc=followscs l:tc=followscs tc=followscs scs=0
+foo: 1
+Foo: 1
+ic=1 g:tc=followic l:tc= tc=followic scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=followic l:tc=followic tc=followic scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=followic l:tc=ignore tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=followic l:tc=match tc=match scs=0
+foo: 1
+Foo: 1
+ic=1 g:tc=followic l:tc=followscs tc=followscs scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=ignore l:tc= tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=ignore l:tc=followic tc=followic scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=ignore l:tc=ignore tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=ignore l:tc=match tc=match scs=0
+foo: 1
+Foo: 1
+ic=1 g:tc=ignore l:tc=followscs tc=followscs scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=match l:tc= tc=match scs=0
+foo: 1
+Foo: 1
+ic=1 g:tc=match l:tc=followic tc=followic scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=match l:tc=ignore tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=match l:tc=match tc=match scs=0
+foo: 1
+Foo: 1
+ic=1 g:tc=match l:tc=followscs tc=followscs scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=followscs l:tc= tc=followscs scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=followscs l:tc=followic tc=followic scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=followscs l:tc=ignore tc=ignore scs=0
+foo: 2
+Foo: 2
+ic=1 g:tc=followscs l:tc=match tc=match scs=0
+foo: 1
+Foo: 1
+ic=1 g:tc=followscs l:tc=followscs tc=followscs scs=0
+foo: 2
+Foo: 2
+ic=0 g:tc=followic l:tc= tc=followic scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=followic l:tc=followic tc=followic scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=followic l:tc=ignore tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=0 g:tc=followic l:tc=match tc=match scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=followic l:tc=followscs tc=followscs scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=ignore l:tc= tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=0 g:tc=ignore l:tc=followic tc=followic scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=ignore l:tc=ignore tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=0 g:tc=ignore l:tc=match tc=match scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=ignore l:tc=followscs tc=followscs scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=match l:tc= tc=match scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=match l:tc=followic tc=followic scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=match l:tc=ignore tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=0 g:tc=match l:tc=match tc=match scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=match l:tc=followscs tc=followscs scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=followscs l:tc= tc=followscs scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=followscs l:tc=followic tc=followic scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=followscs l:tc=ignore tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=0 g:tc=followscs l:tc=match tc=match scs=1
+foo: 1
+Foo: 1
+ic=0 g:tc=followscs l:tc=followscs tc=followscs scs=1
+foo: 1
+Foo: 1
+ic=1 g:tc=followic l:tc= tc=followic scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=followic l:tc=followic tc=followic scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=followic l:tc=ignore tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=followic l:tc=match tc=match scs=1
+foo: 1
+Foo: 1
+ic=1 g:tc=followic l:tc=followscs tc=followscs scs=1
+foo: 2
+Foo: 1
+ic=1 g:tc=ignore l:tc= tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=ignore l:tc=followic tc=followic scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=ignore l:tc=ignore tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=ignore l:tc=match tc=match scs=1
+foo: 1
+Foo: 1
+ic=1 g:tc=ignore l:tc=followscs tc=followscs scs=1
+foo: 2
+Foo: 1
+ic=1 g:tc=match l:tc= tc=match scs=1
+foo: 1
+Foo: 1
+ic=1 g:tc=match l:tc=followic tc=followic scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=match l:tc=ignore tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=match l:tc=match tc=match scs=1
+foo: 1
+Foo: 1
+ic=1 g:tc=match l:tc=followscs tc=followscs scs=1
+foo: 2
+Foo: 1
+ic=1 g:tc=followscs l:tc= tc=followscs scs=1
+foo: 2
+Foo: 1
+ic=1 g:tc=followscs l:tc=followic tc=followic scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=followscs l:tc=ignore tc=ignore scs=1
+foo: 2
+Foo: 2
+ic=1 g:tc=followscs l:tc=match tc=match scs=1
+foo: 1
+Foo: 1
+ic=1 g:tc=followscs l:tc=followscs tc=followscs scs=1
+foo: 2
+Foo: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment