Skip to content

Commit 51dd9f2

Browse files
committed
main,Zsh: detect zsh in the parser guessing based on emacs modelines (thelist at EOF)
For an example: ... # Local Variables: # mode: sh # eval: (sh-set-shell "zsh") # End: The original code tells that ctags should use "sh" parser for processing the input. With this change, ctags can detect "zsh" passed as an argument to sh-set-shell function. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 2fbc66e commit 51dd9f2

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Local Variables:
2+
# mode: sh
3+
# eval: (sh-set-shell "zsh")
4+
# End:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Local Variables:
2+
# mode: sh
3+
# eval: (sh-set-shell "bash")
4+
# End:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Local Variables:
2+
# mode: sh
3+
# End:

Tmain/emacs-modline-shell-script-zsh.d/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ for f in input-firstline0.unknown \
99
input-firstline3.unknown \
1010
input-firstline4.unknown \
1111
input-firstline5.unknown \
12+
input-lastlist0.unknown \
13+
input-lastlist1.unknown \
14+
input-lastlist2.unknown \
1215
; do
1316
$CTAGS --quiet --options=NONE -G --print-language $f
1417
done

Tmain/emacs-modline-shell-script-zsh.d/stdout-expected.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ input-firstline2.unknown: Sh
44
input-firstline3.unknown: Sh
55
input-firstline4.unknown: Sh
66
input-firstline5.unknown: Sh
7+
input-lastlist0.unknown: Zsh
8+
input-lastlist1.unknown: Sh
9+
input-lastlist2.unknown: Sh

main/parse.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ static vString* determineEmacsModeAtEOF (MIO* const fp)
875875
bool headerFound = false;
876876
const char* p;
877877
vString* mode = vStringNew ();
878+
bool is_shell_mode = false;
878879

879880
while ((line = readLineRaw (vLine, fp)) != NULL)
880881
{
@@ -888,11 +889,22 @@ static vString* determineEmacsModeAtEOF (MIO* const fp)
888889
; /* no-op */
889890
for ( ; *p != '\0' && isLanguageNameChar ((int) *p) ; ++p)
890891
vStringPut (mode, (int) *p);
892+
893+
is_shell_mode = ((strcasecmp (vStringValue (mode), "sh") == 0
894+
|| strcasecmp (vStringValue (mode), "shell-script") == 0));
891895
}
892896
else if (headerFound && (p = strstr(line, "End:")))
893897
headerFound = false;
894898
else if (strstr (line, "Local Variables:"))
895899
headerFound = true;
900+
else if (is_shell_mode && (p = strstr (line, "sh-set-shell")))
901+
{
902+
p += strlen("sh-set-shell");
903+
while (isspace ((int) *p))
904+
p++;
905+
if (strncmp (p, "\"zsh\"", 5) == 0)
906+
vStringCopyS (mode, "Zsh");
907+
}
896908
}
897909
vStringDelete (vLine);
898910
return mode;

0 commit comments

Comments
 (0)