Skip to content

Commit 2b2165a

Browse files
committed
Man: extact heading in the next line if there is no argument to 'SH'
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 373135a commit 2b2165a

File tree

4 files changed

+94
-7
lines changed

4 files changed

+94
-7
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
CTAGS input.1 /^.TH CTAGS 1 "Version 0.0.0" "Darren Hiebert" "Universal Ctags"$/;" t end:30
2-
NAME input.1 /^.SH "NAME"$/;" s title:CTAGS end:7
3-
SYNOPSIS input.1 /^.SH SYNOPSIS$/;" s title:CTAGS end:14
4-
DESCRIPTION input.1 /^.SH "DESCRIPTION"$/;" s title:CTAGS end:23
5-
AUTHOR input.1 /^.SH AUTHOR$/;" s title:CTAGS end:27
6-
SEE ALSO input.1 /^.SH SEE ALSO$/;" s title:CTAGS end:30
1+
CTAGS input.1 /^.TH CTAGS 1 "Version 0.0.0" "Darren Hiebert" "Universal Ctags"$/;" t end:37
2+
NAME input.1 /^.SH "NAME"$/;" s title:CTAGS end:6
3+
ABSTRACT input.1 /^ABSTRACT$/;" s title:CTAGS end:9
4+
SYNOPSIS input.1 /^.SH SYNOPSIS$/;" s title:CTAGS end:16
5+
DESCRIPTION input.1 /^.SH "DESCRIPTION"$/;" s title:CTAGS end:25
6+
AUTHOR input.1 /^AUTHOR$/;" s title:CTAGS end:30
7+
ACKNOWLEDGMENT input.1 /^ACKNOWLEDGMENT$/;" s title:CTAGS end:34
8+
SEE ALSO input.1 /^.SH SEE ALSO$/;" s title:CTAGS end:37

Units/parser-man.r/simple.d/input.1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
.SH "NAME"
55
ctags \- Generate tag files for source code
66

7+
.SH
8+
ABSTRACT
79

810
.SH SYNOPSIS
911
.TP 6
@@ -21,10 +23,15 @@ editor or other utility. A "tag" signifies a language object for which an
2123
index entry is available (or, alternatively, the index entry created for that
2224
object).
2325

24-
.SH AUTHOR
26+
.SH
27+
AUTHOR
2528
.sp
2629
The Developers.
2730

31+
.SH
32+
ACKNOWLEDGMENT
33+
.sp
34+
2835
.SH SEE ALSO
2936
.sp
3037
See tags(5) for the details of tags file format.

optlib/man.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,30 @@
1010

1111
static void initializeManParser (const langType language)
1212
{
13+
addLanguageOptscriptToHook (language, SCRIPT_HOOK_PRELUDE,
14+
"{{ % /replace SCOPE-ACTION -\n"
15+
" % /push SCOPE-ACTION -\n"
16+
" /scope-action {\n"
17+
" /replace eq {\n"
18+
" _scopetop pop 1 /start _matchloc _matchloc2line dup 2 gt {\n"
19+
" 2 sub end:\n"
20+
" } {\n"
21+
" pop\n"
22+
" pop\n"
23+
" } ifelse\n"
24+
" _scopepop\n"
25+
" } if\n"
26+
"\n"
27+
" _scopetop {\n"
28+
" . exch scope:\n"
29+
" } if\n"
30+
" . _scopepush\n"
31+
" } def\n"
32+
"}}");
1333

1434
addLanguageRegexTable (language, "main");
1535
addLanguageRegexTable (language, "section");
36+
addLanguageRegexTable (language, "sectionheading");
1637
addLanguageRegexTable (language, "EOF");
1738
addLanguageRegexTable (language, "SKIP");
1839
addLanguageRegexTable (language, "REST");
@@ -33,6 +54,12 @@ static void initializeManParser (const langType language)
3354
addLanguageTagMultiTableRegex (language, "main",
3455
"^\\.SH[\t ]+([^\n]+)\n",
3556
"\\1", "s", "{icase}{scope=push}{tenter=section}", NULL);
57+
addLanguageTagMultiTableRegex (language, "main",
58+
"^\\.SH[\t ]*\n",
59+
"", "", "{icase}{tenter=sectionheading}"
60+
"{{\n"
61+
" /push\n"
62+
"}}", NULL);
3663
addLanguageTagMultiTableRegex (language, "main",
3764
"^[^\n]*\n|[^\n]+",
3865
"", "", "", NULL);
@@ -48,12 +75,30 @@ static void initializeManParser (const langType language)
4875
addLanguageTagMultiTableRegex (language, "section",
4976
"^\\.SH[\t ]+([^\n]+)\n",
5077
"\\1", "s", "{icase}{scope=replace}", NULL);
78+
addLanguageTagMultiTableRegex (language, "section",
79+
"^\\.SH[\t ]*\n",
80+
"", "", "{icase}{tenter=sectionheading}"
81+
"{{\n"
82+
" /replace\n"
83+
"}}", NULL);
5184
addLanguageTagMultiTableRegex (language, "section",
5285
"^[^\n]*\n|[^\n]+",
5386
"", "", "", NULL);
5487
addLanguageTagMultiTableRegex (language, "section",
5588
"^",
5689
"", "", "{scope=clear}{tquit}", NULL);
90+
addLanguageTagMultiTableRegex (language, "sectionheading",
91+
"^[ \t]*([^\n]+)\n",
92+
"\\1", "s", "{tleave}"
93+
"{{\n"
94+
" scope-action\n"
95+
"}}", NULL);
96+
addLanguageTagMultiTableRegex (language, "sectionheading",
97+
"^[^\n]*\n|[^\n]+",
98+
"", "", "", NULL);
99+
addLanguageTagMultiTableRegex (language, "sectionheading",
100+
"^",
101+
"", "", "{scope=clear}{tquit}", NULL);
57102
addLanguageTagMultiTableRegex (language, "EOF",
58103
"^",
59104
"", "", "{scope=clear}{tquit}", NULL);

optlib/man.ctags

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@
4444

4545
--_tabledef-Man=main
4646
--_tabledef-Man=section
47+
--_tabledef-Man=sectionheading
48+
49+
--_prelude-Man={{
50+
% /replace SCOPE-ACTION -
51+
% /push SCOPE-ACTION -
52+
/scope-action {
53+
/replace eq {
54+
_scopetop pop 1 /start _matchloc _matchloc2line dup 2 gt {
55+
2 sub end:
56+
} {
57+
pop
58+
pop
59+
} ifelse
60+
_scopepop
61+
} if
62+
63+
_scopetop {
64+
. exch scope:
65+
} if
66+
. _scopepush
67+
} def
68+
}}
4769

4870
--_tabledef-Man=EOF
4971
--_tabledef-Man=SKIP
@@ -62,9 +84,20 @@
6284
--_mtable-regex-Man=main/\.TH[\t ]+([^\t \n]+)[^\n]*\n/\1/t/{icase}{scope=set}
6385
--_mtable-regex-Man=main/\.SH[\t ]+"([^"\n]+)"[^\n]*\n/\1/s/{icase}{scope=push}{tenter=section}
6486
--_mtable-regex-Man=main/\.SH[\t ]+([^\n]+)\n/\1/s/{icase}{scope=push}{tenter=section}
87+
--_mtable-regex-Man=main/\.SH[\t ]*\n//{icase}{tenter=sectionheading}{{
88+
/push
89+
}}
6590
--_mtable-extend-Man=main+REST
6691

6792
--_mtable-extend-Man=section+GUARD
6893
--_mtable-regex-Man=section/\.SH[\t ]+"([^"\n]+)"[^\n]*\n/\1/s/{icase}{scope=replace}
6994
--_mtable-regex-Man=section/\.SH[\t ]+([^\n]+)\n/\1/s/{icase}{scope=replace}
95+
--_mtable-regex-Man=section/\.SH[\t ]*\n//{icase}{tenter=sectionheading}{{
96+
/replace
97+
}}
7098
--_mtable-extend-Man=section+REST
99+
100+
--_mtable-regex-Man=sectionheading/[ \t]*([^\n]+)\n/\1/s/{tleave}{{
101+
scope-action
102+
}}
103+
--_mtable-extend-Man=sectionheading+REST

0 commit comments

Comments
 (0)