Skip to content

Commit 66e29d7

Browse files
committed
patch 7.4.2230
Problem: There is no equivalent of 'smartcase' for a tag search. Solution: Add value "followscs" and "smart" to 'tagcase'. (Christian Brabandt, closes #712) Turn tagcase test into new style.
1 parent f04507d commit 66e29d7

13 files changed

Lines changed: 131 additions & 156 deletions

File tree

runtime/doc/options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7417,6 +7417,9 @@ A jump table for the options with a short description can be found at |Q_op|.
74177417
By default, tag searches are case-sensitive. Case is ignored when
74187418
'ignorecase' is set and 'tagcase' is "followic", or when 'tagcase' is
74197419
"ignore".
7420+
Also when 'tagcase' is "followscs" and 'smartcase' is set, or
7421+
'tagcase' is "smart", and the pattern contains only lowercase
7422+
characters.
74207423

74217424
When 'tagbsearch' is off, tags searching is slower when a full match
74227425
exists, but faster when no full match exists. Tags in unsorted tags
@@ -7435,8 +7438,10 @@ A jump table for the options with a short description can be found at |Q_op|.
74357438
This option specifies how case is handled when searching the tags
74367439
file:
74377440
followic Follow the 'ignorecase' option
7441+
followscs Follow the 'smartcase' and 'ignorecase' options
74387442
ignore Ignore case
74397443
match Match case
7444+
smart Ignore case unless an upper case letter is used
74407445

74417446
*'taglength'* *'tl'*
74427447
'taglength' 'tl' number (default 0)

runtime/doc/tagsrch.txt

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,23 @@ Note that when the current file changes, the priority list is mostly not
8484
changed, to avoid confusion when using ":tnext". It is changed when using
8585
":tag {ident}".
8686

87-
The ignore-case matches are not found for a ":tag" command when the
88-
'ignorecase' option is off and 'tagcase' is "followic" or when 'tagcase' is
89-
"match". They are found when a pattern is used (starting with a "/") and for
90-
":tselect", also when 'ignorecase' is off and 'tagcase' is "followic" or when
91-
'tagcase' is "match". Note that using ignore-case tag searching disables
92-
binary searching in the tags file, which causes a slowdown. This can be
93-
avoided by fold-case sorting the tag file. See the 'tagbsearch' option for an
94-
explanation.
87+
The ignore-case matches are not found for a ":tag" command when:
88+
- the 'ignorecase' option is off and 'tagcase' is "followic"
89+
- 'tagcase' is "match"
90+
- 'tagcase' is "smart" and the pattern contains an upper case character.
91+
- 'tagcase' is "followscs" and 'smartcase' option is on and the pattern
92+
contains an upper case character.
93+
94+
The gnore-case matches are found when:
95+
- a pattern is used (starting with a "/")
96+
- for ":tselect"
97+
- when 'tagcase' is "followic" and 'ignorecase' is off
98+
- when 'tagcase' is "match"
99+
- when 'tagcase' is "followscs" and the 'smartcase' option is off
100+
101+
Note that using ignore-case tag searching disables binary searching in the
102+
tags file, which causes a slowdown. This can be avoided by fold-case sorting
103+
the tag file. See the 'tagbsearch' option for an explanation.
95104

96105
==============================================================================
97106
2. Tag stack *tag-stack* *tagstack* *E425*
@@ -442,13 +451,18 @@ file "tags". It can also be used to access a common tags file.
442451
The next file in the list is not used when:
443452
- A matching static tag for the current buffer has been found.
444453
- A matching global tag has been found.
445-
This also depends on whether case is ignored. Case is ignored when
446-
'ignorecase' is set and 'tagcase' is "followic", or when 'tagcase' is
447-
"ignore". If case is not ignored, and the tags file only has a match without
448-
matching case, the next tags file is searched for a match with matching case.
449-
If no tag with matching case is found, the first match without matching case
450-
is used. If case is ignored, and a matching global tag with or without
451-
matching case is found, this one is used, no further tags files are searched.
454+
This also depends on whether case is ignored. Case is ignored when:
455+
- 'tagcase' is "followic" and 'ignorecase' is set
456+
- 'tagcase' is "ignore"
457+
- 'tagcase' is "smart" and and the pattern only contains lower case
458+
characters.
459+
- 'tagcase' is "followscs" and 'smartcase' is set and and the pattern only
460+
contains lower case characters.
461+
If case is not ignored, and the tags file only has a match without matching
462+
case, the next tags file is searched for a match with matching case. If no
463+
tag with matching case is found, the first match without matching case is
464+
used. If case is ignored, and a matching global tag with or without matching
465+
case is found, this one is used, no further tags files are searched.
452466

453467
When a tag file name starts with "./", the '.' is replaced with the path of
454468
the current file. This makes it possible to use a tags file in the directory

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,6 @@ test1 \
20312031
test_marks \
20322032
test_nested_function \
20332033
test_search_mbyte \
2034-
test_tagcase \
20352034
test_utf8 \
20362035
test_wordcount \
20372036
test_writefile \
@@ -2123,6 +2122,7 @@ test_arglist \
21232122
test_syntax \
21242123
test_tabline \
21252124
test_tabpage \
2125+
test_tagcase \
21262126
test_tagjump \
21272127
test_textobjects \
21282128
test_timers \

src/option.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,13 @@ EXTERN int p_tbs; /* 'tagbsearch' */
822822
EXTERN char_u *p_tc; /* 'tagcase' */
823823
EXTERN unsigned tc_flags; /* flags from 'tagcase' */
824824
#ifdef IN_OPTION_C
825-
static char *(p_tc_values[]) = {"followic", "ignore", "match", NULL};
825+
static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL};
826826
#endif
827827
#define TC_FOLLOWIC 0x01
828828
#define TC_IGNORE 0x02
829829
#define TC_MATCH 0x04
830+
#define TC_FOLLOWSCS 0x08
831+
#define TC_SMART 0x10
830832
EXTERN long p_tl; /* 'taglength' */
831833
EXTERN int p_tr; /* 'tagrelative' */
832834
EXTERN char_u *p_tags; /* 'tags' */

src/proto/search.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ void save_search_patterns(void);
77
void restore_search_patterns(void);
88
void free_search_patterns(void);
99
int ignorecase(char_u *pat);
10+
int ignorecase_opt(char_u *pat, int ic_in, int scs);
1011
int pat_has_uppercase(char_u *pat);
1112
char_u *last_csearch(void);
1213
int last_csearch_forward(void);

src/search.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,18 @@ free_search_patterns(void)
367367
int
368368
ignorecase(char_u *pat)
369369
{
370-
int ic = p_ic;
370+
return ignorecase_opt(pat, p_ic, p_scs);
371+
}
372+
373+
/*
374+
* As ignorecase() put pass the "ic" and "scs" flags.
375+
*/
376+
int
377+
ignorecase_opt(char_u *pat, int ic_in, int scs)
378+
{
379+
int ic = ic_in;
371380

372-
if (ic && !no_smartcase && p_scs
381+
if (ic && !no_smartcase && scs
373382
#ifdef FEAT_INS_EXPAND
374383
&& !(ctrl_x_mode && curbuf->b_p_inf)
375384
#endif

src/tag.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,9 +1385,11 @@ find_tags(
13851385
*/
13861386
switch (curbuf->b_tc_flags ? curbuf->b_tc_flags : tc_flags)
13871387
{
1388-
case TC_FOLLOWIC: break;
1389-
case TC_IGNORE: p_ic = TRUE; break;
1390-
case TC_MATCH: p_ic = FALSE; break;
1388+
case TC_FOLLOWIC: break;
1389+
case TC_IGNORE: p_ic = TRUE; break;
1390+
case TC_MATCH: p_ic = FALSE; break;
1391+
case TC_FOLLOWSCS: p_ic = ignorecase(pat); break;
1392+
case TC_SMART: p_ic = ignorecase_opt(pat, TRUE, TRUE); break;
13911393
}
13921394

13931395
help_save = curbuf->b_help;

src/testdir/Make_all.mak

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ SCRIPTS_ALL = \
100100
test_marks.out \
101101
test_nested_function.out \
102102
test_search_mbyte.out \
103-
test_tagcase.out \
104103
test_utf8.out \
105104
test_wordcount.out \
106105
test_writefile.out

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ source test_statusline.vim
3535
source test_syn_attr.vim
3636
source test_tabline.vim
3737
source test_tabpage.vim
38+
source test_tagcase.vim
3839
source test_tagjump.vim
3940
source test_timers.vim
4041
source test_true_false.vim

src/testdir/test_tagcase.in

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)