Skip to content

Commit 2fbc66e

Browse files
committed
main,Zsh: detect zsh in the parser guessing based on emacs modelines (the first line)
We introduced Zsh parser. To utilize the new paresr, it is not enough to detect a mode in an emacs modeline. For an example: -*- mode: sh; eval: (sh-set-shell "zsh") -*- ... 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 d30bac0 commit 2fbc66e

File tree

10 files changed

+55
-0
lines changed

10 files changed

+55
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- mode: sh; eval: (sh-set-shell "zsh") -*-
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- mode: shell-script; sh-set-shell: zsh -*-
2+
# Emacs doesn't understand this notation but I found one in
3+
# https://github.com/neumachen/dotfiles/blob/3e2b04249f852dbdf7dee1e33e518de61031eb04/private_dot_config/exact_zsh/dot_zprofile
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- mode: sh; eval: (sh-set-shell "bash") -*-
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- mode: shell-script; sh-set-shell: bash -*-
2+
# Emacs doesn't understand this notation but I found one in
3+
# https://github.com/neumachen/dotfiles/blob/3e2b04249f852dbdf7dee1e33e518de61031eb04/private_dot_config/exact_zsh/dot_zprofile
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- mode: sh -*-
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- mode: shell-script -*-
2+
# Emacs doesn't understand this notation but I found one in
3+
# https://github.com/neumachen/dotfiles/blob/3e2b04249f852dbdf7dee1e33e518de61031eb04/private_dot_config/exact_zsh/dot_zprofile
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright: 2022 Masatake YAMATO
2+
# License: GPL-2
3+
4+
CTAGS=$1
5+
6+
for f in input-firstline0.unknown \
7+
input-firstline1.unknown \
8+
input-firstline2.unknown \
9+
input-firstline3.unknown \
10+
input-firstline4.unknown \
11+
input-firstline5.unknown \
12+
; do
13+
$CTAGS --quiet --options=NONE -G --print-language $f
14+
done

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

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
input-firstline0.unknown: Zsh
2+
input-firstline1.unknown: Zsh
3+
input-firstline2.unknown: Sh
4+
input-firstline3.unknown: Sh
5+
input-firstline4.unknown: Sh
6+
input-firstline5.unknown: Sh

main/parse.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,24 @@ static vString* extractInterpreter (MIO* input)
783783
return interpreter;
784784
}
785785

786+
static bool isShellZsh (const char *p)
787+
{
788+
p = strstr (p, "sh-set-shell");
789+
if (!p)
790+
return false;
791+
p += strlen("sh-set-shell");
792+
793+
if (*p == ':')
794+
p++;
795+
while (isspace ((int) *p))
796+
p++;
797+
798+
if (strncmp (p, "\"zsh\"", 5) == 0
799+
|| strncmp (p, "zsh", 3) == 0)
800+
return true;
801+
return false;
802+
}
803+
786804
static vString* determineEmacsModeAtFirstLine (const char* const line)
787805
{
788806
vString* mode = vStringNew ();
@@ -803,6 +821,11 @@ static vString* determineEmacsModeAtFirstLine (const char* const line)
803821
; /* no-op */
804822
for ( ; *p != '\0' && isLanguageNameChar ((int) *p) ; ++p)
805823
vStringPut (mode, (int) *p);
824+
825+
if ((strcmp(vStringValue (mode), "sh") == 0
826+
|| strcmp(vStringValue (mode), "shell-script") == 0)
827+
&& isShellZsh (p))
828+
vStringCopyS (mode, "Zsh");
806829
}
807830
else
808831
{

0 commit comments

Comments
 (0)