From 3ddd2046c42ae4df90daa425df3ed40ff61b4b32 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 2 Sep 2023 00:49:47 +0200 Subject: [PATCH] Ignoring __pycache__ directories in macro editor This feature can be configured by providing a colon-separated list of directory names to ignore in the $KLAYOUT_IGNORE_MACRO_DIRS env var. --- src/lym/lym/lymMacroCollection.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lym/lym/lymMacroCollection.cc b/src/lym/lym/lymMacroCollection.cc index c55f71ba6..6712d6549 100644 --- a/src/lym/lym/lymMacroCollection.cc +++ b/src/lym/lym/lymMacroCollection.cc @@ -38,6 +38,7 @@ #include "tlProgress.h" #include "tlFileUtils.h" #include "tlResources.h" +#include "tlEnv.h" #include "rba.h" #include "pya.h" @@ -363,6 +364,22 @@ namespace { } #endif +// Some directories are ignored in addition to dotfiles +static bool dir_is_ignored (const std::string &dn) +{ + static std::set ignored; + static bool initialized = false; + + if (! initialized) { + // a colon-separated list of directory names + std::string ign = tl::get_env ("KLAYOUT_IGNORE_MACRO_DIRS", "__pycache__"); + auto ignv = tl::split (ign, ":"); + ignored.insert (ignv.begin (), ignv.end ()); + } + + return ignored.find (dn) != ignored.end (); +} + void MacroCollection::scan () { std::string p = path (); @@ -431,6 +448,10 @@ void MacroCollection::scan () continue; } + if (dir_is_ignored (*f)) { + continue; + } + try { MacroCollection *&mc = m_folders.insert (std::make_pair (*f, (MacroCollection *) 0)).first->second;