Skip to content

Commit f1db2a7

Browse files
authored
Merge pull request #3568 from masatake/revise-optlib-path
main: make ~/.ctags.d as the default element for the optlib path list
2 parents 32745a0 + 98407fa commit f1db2a7

File tree

3 files changed

+114
-11
lines changed

3 files changed

+114
-11
lines changed

docs/man/ctags.1.rst

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ Option File Options
830830

831831
``--optlib-dir=[+]<directory>``
832832
Add an optlib *<directory>* to or reset the optlib path list.
833-
By default, the optlib path list is empty.
833+
See "`Default optlib path list`_" about the default elements for optlib path list.
834834

835835
optlib Options
836836
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2153,12 +2153,18 @@ ENVIRONMENT VARIABLES
21532153
FILES
21542154
-----
21552155

2156+
Output files
2157+
~~~~~~~~~~~~
2158+
21562159
``tags``
21572160
The default tag file created by ctags.
21582161

21592162
``TAGS``
21602163
The default tag file created by etags.
21612164

2165+
Preloading option files
2166+
~~~~~~~~~~~~~~~~~~~~~~~
2167+
21622168
``$XDG_CONFIG_HOME/ctags/*.ctags``, or ``$HOME/.config/ctags/*.ctags`` if
21632169
``$XDG_CONFIG_HOME`` is not defined
21642170
(on other than MS Windows)
@@ -2197,6 +2203,35 @@ FILES
21972203

21982204
``*.ctags`` files in a directory are loaded in alphabetical order.
21992205

2206+
Default optlib path list
2207+
~~~~~~~~~~~~~~~~~~~~~~~~
2208+
2209+
``$XDG_CONFIG_HOME/ctags``, or ``$HOME/.config/ctags`` if
2210+
``$XDG_CONFIG_HOME`` is not defined
2211+
(on other than MS Windows)
2212+
2213+
``$HOME/.ctags.d``
2214+
2215+
``$HOMEDRIVE$HOMEPATH/ctags.d`` (on MS Windows only)
2216+
2217+
These directories are parts of the optlib path list by default.
2218+
See "`Option File Options`_" about the optlib path list.
2219+
2220+
If you have a set of options that you want to enable
2221+
conditionally, make a directory in the path in the optlib path
2222+
list, and put the options to the files having .ctags as extensions
2223+
under the directory. ``--options=<the-directory-name>`` is for
2224+
enabling the options.
2225+
2226+
For example, consider you have some options you want to enable
2227+
only when tagging the Linux kernel source tree. In that case,
2228+
make ``$HOME/.ctags.d/linux`` directory, put the options to
2229+
``$HOME/.ctags.d/linux/my.ctags``. If you have many options, you
2230+
can split them into multiple files like
2231+
``$HOME/.ctags.d/linux/device-driver.ctags`` and
2232+
``$HOME/.ctags.d/linux/network-stack.ctags``. Either way, you can
2233+
enable the options in the .ctags file(s) under the directory by
2234+
adding ``--options=linux`` to your ctags command line.
22002235

22012236
SEE ALSO
22022237
--------

main/options.c

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ typedef enum eOptionLoadingStage {
194194
OptionLoadingStageNone,
195195
OptionLoadingStageCustom,
196196
OptionLoadingStageXdg,
197-
OptionLoadingStageHomeRecursive,
198-
OptionLoadingStageCurrentRecursive,
197+
OptionLoadingStageHomeDir,
198+
OptionLoadingStageCurrentDir,
199199
OptionLoadingStageEnvVar,
200200
OptionLoadingStageCmdline,
201201
} OptionLoadingStage;
@@ -613,8 +613,8 @@ static const char *const StageDescription [] = {
613613
[OptionLoadingStageNone] = "not initialized",
614614
[OptionLoadingStageCustom] = "custom file",
615615
[OptionLoadingStageXdg] = "file(s) under $XDG_CONFIG_HOME and $HOME/.config",
616-
[OptionLoadingStageHomeRecursive] = "file(s) under $HOME",
617-
[OptionLoadingStageCurrentRecursive] = "file(s) under the current directory",
616+
[OptionLoadingStageHomeDir] = "file(s) under $HOME",
617+
[OptionLoadingStageCurrentDir] = "file(s) under the current directory",
618618
[OptionLoadingStageCmdline] = "command line",
619619
};
620620

@@ -3768,28 +3768,28 @@ static struct preloadPathElt preload_path_list [] = {
37683768
.isDirectory = true,
37693769
.makePath = prependEnvvar,
37703770
.extra = "HOME",
3771-
.stage = OptionLoadingStageHomeRecursive,
3771+
.stage = OptionLoadingStageHomeDir,
37723772
},
37733773
#ifdef WIN32
37743774
{
37753775
.path = "ctags.d",
37763776
.isDirectory = true,
37773777
.makePath = getConfigAtHomeOnWindows,
37783778
.extra = NULL,
3779-
.stage = OptionLoadingStageHomeRecursive,
3779+
.stage = OptionLoadingStageHomeDir,
37803780
},
37813781
#endif
37823782
{
37833783
.path = ".ctags.d",
37843784
.isDirectory = true,
37853785
.makePath = NULL,
3786-
.stage = OptionLoadingStageCurrentRecursive,
3786+
.stage = OptionLoadingStageCurrentDir,
37873787
},
37883788
{
37893789
.path = "ctags.d",
37903790
.isDirectory = true,
37913791
.makePath = NULL,
3792-
.stage = OptionLoadingStageCurrentRecursive,
3792+
.stage = OptionLoadingStageCurrentDir,
37933793
},
37943794
{
37953795
.path = NULL,
@@ -3808,14 +3808,47 @@ extern void readOptionConfiguration (void)
38083808
parseConfigurationFileOptions ();
38093809
}
38103810

3811+
static stringList* optlibPathListNew(struct preloadPathElt *pathList)
3812+
{
3813+
stringList * appended = stringListNew ();
3814+
3815+
for (size_t i = 0; pathList[i].path != NULL || pathList[i].makePath != NULL; ++i)
3816+
{
3817+
struct preloadPathElt *elt = pathList + i;
3818+
preloadMakePathFunc maker = elt->makePath;
3819+
const char *path = elt->path;
3820+
3821+
if (!elt->isDirectory)
3822+
continue;
3823+
3824+
if (elt->stage == OptionLoadingStageCurrentDir)
3825+
continue;
3826+
3827+
if (maker)
3828+
path = maker(elt->path, elt->extra);
3829+
3830+
if (path == NULL)
3831+
continue;
3832+
3833+
vString *vpath;
3834+
if (path == elt->path)
3835+
vpath = vStringNewInit (path);
3836+
else
3837+
vpath = vStringNewOwn ((char *)path);
3838+
stringListAdd(appended, vpath);
3839+
}
3840+
3841+
return appended;
3842+
}
3843+
38113844
/*
38123845
* Option initialization
38133846
*/
38143847

38153848
extern void initOptions (void)
38163849
{
38173850
OptionFiles = stringListNew ();
3818-
OptlibPathList = stringListNew ();
3851+
OptlibPathList = optlibPathListNew (preload_path_list);
38193852

38203853
verbose ("Setting option defaults\n");
38213854
installHeaderListDefaults ();

man/ctags.1.rst.in

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ Option File Options
830830

831831
``--optlib-dir=[+]<directory>``
832832
Add an optlib *<directory>* to or reset the optlib path list.
833-
By default, the optlib path list is empty.
833+
See "`Default optlib path list`_" about the default elements for optlib path list.
834834

835835
optlib Options
836836
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2153,12 +2153,18 @@ ENVIRONMENT VARIABLES
21532153
FILES
21542154
-----
21552155

2156+
Output files
2157+
~~~~~~~~~~~~
2158+
21562159
``tags``
21572160
The default tag file created by @CTAGS_NAME_EXECUTABLE@.
21582161

21592162
``TAGS``
21602163
The default tag file created by @ETAGS_NAME_EXECUTABLE@.
21612164

2165+
Preloading option files
2166+
~~~~~~~~~~~~~~~~~~~~~~~
2167+
21622168
``$XDG_CONFIG_HOME/ctags/*.ctags``, or ``$HOME/.config/ctags/*.ctags`` if
21632169
``$XDG_CONFIG_HOME`` is not defined
21642170
(on other than MS Windows)
@@ -2197,6 +2203,35 @@ FILES
21972203

21982204
``*.ctags`` files in a directory are loaded in alphabetical order.
21992205

2206+
Default optlib path list
2207+
~~~~~~~~~~~~~~~~~~~~~~~~
2208+
2209+
``$XDG_CONFIG_HOME/ctags``, or ``$HOME/.config/ctags`` if
2210+
``$XDG_CONFIG_HOME`` is not defined
2211+
(on other than MS Windows)
2212+
2213+
``$HOME/.ctags.d``
2214+
2215+
``$HOMEDRIVE$HOMEPATH/ctags.d`` (on MS Windows only)
2216+
2217+
These directories are parts of the optlib path list by default.
2218+
See "`Option File Options`_" about the optlib path list.
2219+
2220+
If you have a set of options that you want to enable
2221+
conditionally, make a directory in the path in the optlib path
2222+
list, and put the options to the files having .ctags as extensions
2223+
under the directory. ``--options=<the-directory-name>`` is for
2224+
enabling the options.
2225+
2226+
For example, consider you have some options you want to enable
2227+
only when tagging the Linux kernel source tree. In that case,
2228+
make ``$HOME/.ctags.d/linux`` directory, put the options to
2229+
``$HOME/.ctags.d/linux/my.ctags``. If you have many options, you
2230+
can split them into multiple files like
2231+
``$HOME/.ctags.d/linux/device-driver.ctags`` and
2232+
``$HOME/.ctags.d/linux/network-stack.ctags``. Either way, you can
2233+
enable the options in the .ctags file(s) under the directory by
2234+
adding ``--options=linux`` to your ctags command line.
22002235

22012236
SEE ALSO
22022237
--------

0 commit comments

Comments
 (0)