mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
File path settings now rank higher than scope settings
A file setting like “src/*.cc” is arguably more specific (and thus more local) than targeting the scope “source.c++”, so it makes sense that the file settings rank higher than scope settings. Some users also find it natural to target file extensions over scopes, but as TM will store some learned settings with a scope selector, it would previously lead to confusion, when a user was unable to e.g. change tab size for “*.php” (because TM had a learned setting for “source.php”).
This commit is contained in:
@@ -186,7 +186,7 @@ namespace
|
||||
if(section->scope_selector.does_match(scope, &rank))
|
||||
orderScopeMatches.emplace(rank, section);
|
||||
}
|
||||
else if(!section->has_file_glob || section->file_glob.does_match(path == NULL_STR ? directory : path))
|
||||
else if(!section->has_file_glob)
|
||||
{
|
||||
iterate(pair, section->variables)
|
||||
expand_variable(pair->first, pair->second, variables);
|
||||
@@ -200,6 +200,18 @@ namespace
|
||||
expand_variable(pair->first, pair->second, variables);
|
||||
}
|
||||
|
||||
citerate(file, paths(directory))
|
||||
{
|
||||
citerate(section, sections(*file))
|
||||
{
|
||||
if(section->has_file_glob && section->file_glob.does_match(path == NULL_STR ? directory : path))
|
||||
{
|
||||
iterate(pair, section->variables)
|
||||
expand_variable(pair->first, pair->second, variables);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
variables.erase("CWD");
|
||||
|
||||
@@ -24,3 +24,20 @@ void test_scope_selector_ranking ()
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("foo/bar/file"), "text.markup").get("mySetting"), "6");
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("foo/bar/file"), "text.markup.html").get("mySetting"), "8");
|
||||
}
|
||||
|
||||
void test_glob_and_scope_selector_ranking ()
|
||||
{
|
||||
test::jail_t jail;
|
||||
|
||||
jail.set_content(".tm_properties", "mySetting = 1\n[ text ]\nmySetting = 2\n");
|
||||
jail.set_content("local/.tm_properties", "mySetting = 3\n[ text ]\nmySetting = 4\n[ *.txt ]\nmySetting = 5\n");
|
||||
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("file.foo") ).get("mySetting"), "1");
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("file.txt") ).get("mySetting"), "1");
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("file.foo"), "text").get("mySetting"), "2");
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("file.txt"), "text").get("mySetting"), "2");
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("local/file.foo") ).get("mySetting"), "3");
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("local/file.txt") ).get("mySetting"), "5");
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("local/file.foo"), "text").get("mySetting"), "4");
|
||||
OAK_ASSERT_EQ(settings_for_path(jail.path("local/file.txt"), "text").get("mySetting"), "5");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user