feat!: remove recursive dir support for setlocal (#2415)

* feat!: remove recursive dir support for `setlocal`

* Update version in man page

* Update `CHANGELOG.md`
This commit is contained in:
Joe Lim authored and GitHub committed 2026-03-05 18:52:13 +11:00
1 parent 941866b62f
commit 374ae19cb2
7 files changed
+17 -88

No files matched your search

+1
View File
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- The key `<backspace2>` has been renamed to `<backspace>` for `map` keybindings (#2286).
- `.Stat.DirSize` and `.Stat.DirCount` in the ruler file no longer have a pointer type, and will be set to `-1` instead of `nil` if the corresponding value cannot be determined (#2397).
- `setlocal` commands no longer support the ability to specify recursive directories (#2415). For use cases where `setlocal` should apply to a directory based on some condition, it is recommended to script this inside the `on-load` hook command.
### Added
+1 -29
View File
@@ -312,34 +312,6 @@ func matchShellFile(s string) (matches []compMatch, longest string) {
return
}
func matchSetlocalDir(s string) (matches []compMatch, longest string) {
matches, longest = matchFile(s, true, cmdEscape, cmdUnescape)
if len(matches) == 0 {
return
}
trimSep := func(path string) string {
return strings.TrimSuffix(path, string(filepath.Separator))
}
trimSepEsc := func(path string) string {
return cmdEscape(trimSep(cmdUnescape(path)))
}
// add separate matches for path and recursive path
tmp := make([]compMatch, 0, len(matches)*2)
for _, match := range matches {
trimmedMatch := compMatch{trimSep(match.name), trimSepEsc(match.result)}
tmp = append(tmp, trimmedMatch, match)
}
matches = tmp
if longest != s {
longest = trimSepEsc(longest)
}
return
}
func matchExec(s string) (matches []compMatch, longest string) {
var words []string
for p := range strings.SplitSeq(envPath, string(filepath.ListSeparator)) {
@@ -442,7 +414,7 @@ func completeCmd(s string) (matches []compMatch, longest string) {
}
case "setlocal":
if len(f) == 2 {
matches, longest = matchSetlocalDir(f[1])
matches, longest = matchCmdFile(f[1], true)
break
}
if len(f) == 3 {
-3
View File
@@ -1481,7 +1481,6 @@ Command `set` is used to set an option which can be a boolean, integer, or strin
Command `setlocal` is used to set a local option for a directory which can be a boolean or string.
Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse` and `sortby`.
Adding a trailing path separator (i.e. `/` for Unix and `\` for Windows) sets the option for the given directory along with its subdirectories:
setlocal /foo/bar hidden # boolean enable
setlocal /foo/bar hidden true # boolean enable
@@ -1491,8 +1490,6 @@ Adding a trailing path separator (i.e. `/` for Unix and `\` for Windows) sets th
setlocal /foo/bar sortby time # string value without quotes
setlocal /foo/bar sortby 'time' # string value with single quotes (whitespace)
setlocal /foo/bar sortby "time" # string value with double quotes (backslash escapes)
setlocal /foo/bar hidden # for only '/foo/bar' directory
setlocal /foo/bar/ hidden # for '/foo/bar' and its subdirectories (e.g. '/foo/bar/baz')
Command `map` is used to bind a key in Normal and Visual mode to a command which can be a built-in command, custom command, or shell command:
+1 -5
View File
@@ -1629,9 +1629,7 @@ string:
Command setlocal is used to set a local option for a directory which can
be a boolean or string. Currently supported local options are dircounts,
dirfirst, dironly, hidden, info, reverse and sortby. Adding a trailing
path separator (i.e. / for Unix and \ for Windows) sets the option for
the given directory along with its subdirectories:
dirfirst, dironly, hidden, info, reverse and sortby.
setlocal /foo/bar hidden # boolean enable
setlocal /foo/bar hidden true # boolean enable
@@ -1641,8 +1639,6 @@ the given directory along with its subdirectories:
setlocal /foo/bar sortby time # string value without quotes
setlocal /foo/bar sortby 'time' # string value with single quotes (whitespace)
setlocal /foo/bar sortby "time" # string value with double quotes (backslash escapes)
setlocal /foo/bar hidden # for only '/foo/bar' directory
setlocal /foo/bar/ hidden # for '/foo/bar' and its subdirectories (e.g. '/foo/bar/baz')
Command map is used to bind a key in Normal and Visual mode to a command
which can be a built-in command, custom command, or shell command:
-9
View File
@@ -456,11 +456,6 @@ func (e *setExpr) eval(app *app, _ []string) {
}
func (e *setLocalExpr) eval(app *app, _ []string) {
recursive := strings.HasSuffix(e.path, string(os.PathSeparator)) && e.path != string(os.PathSeparator)
if recursive {
e.path = strings.TrimSuffix(e.path, string(os.PathSeparator))
}
var err error
e.path, err = filepath.Abs(replaceTilde(e.path))
if err != nil {
@@ -468,10 +463,6 @@ func (e *setLocalExpr) eval(app *app, _ []string) {
return
}
if recursive && e.path != string(os.PathSeparator) {
e.path += string(os.PathSeparator)
}
switch e.opt {
case "dircounts", "nodircounts", "dircounts!":
err = applyLocalBoolOpt(gLocalOpts.dircounts, gOpts.dircounts, e)
-5
View File
@@ -1425,9 +1425,6 @@ directory which can be a boolean or string.
Currently supported local options are \f[CR]dircounts\f[R],
\f[CR]dirfirst\f[R], \f[CR]dironly\f[R], \f[CR]hidden\f[R],
\f[CR]info\f[R], \f[CR]reverse\f[R] and \f[CR]sortby\f[R].
Adding a trailing path separator (i.e.
\f[CR]/\f[R] for Unix and \f[CR]\(rs\f[R] for Windows) sets the option
for the given directory along with its subdirectories:
.IP
.EX
setlocal /foo/bar hidden # boolean enable
@@ -1438,8 +1435,6 @@ setlocal /foo/bar hidden! # boolean toggle
setlocal /foo/bar sortby time # string value without quotes
setlocal /foo/bar sortby \(aqtime\(aq # string value with single quotes (whitespace)
setlocal /foo/bar sortby \(dqtime\(dq # string value with double quotes (backslash escapes)
setlocal /foo/bar hidden # for only \(aq/foo/bar\(aq directory
setlocal /foo/bar/ hidden # for \(aq/foo/bar\(aq and its subdirectories (e.g. \(aq/foo/bar/baz\(aq)
.EE
.PP
Command \f[CR]map\f[R] is used to bind a key in Normal and Visual mode
+14 -37
View File
@@ -2,7 +2,6 @@ package main
import (
"maps"
"path/filepath"
"time"
)
@@ -132,73 +131,51 @@ var gLocalOpts struct {
sortby map[string]sortMethod
}
func localOptPaths(path string) []string {
list := []string{path}
for curr := path; !isRoot(curr); curr = filepath.Dir(curr) {
list = append(list, curr+string(filepath.Separator))
}
return list
}
func getDirCounts(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.dircounts[key]; ok {
return val
}
if val, ok := gLocalOpts.dircounts[path]; ok {
return val
}
return gOpts.dircounts
}
func getDirFirst(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.dirfirst[key]; ok {
return val
}
if val, ok := gLocalOpts.dirfirst[path]; ok {
return val
}
return gOpts.dirfirst
}
func getDirOnly(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.dironly[key]; ok {
return val
}
if val, ok := gLocalOpts.dironly[path]; ok {
return val
}
return gOpts.dironly
}
func getHidden(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.hidden[key]; ok {
return val
}
if val, ok := gLocalOpts.hidden[path]; ok {
return val
}
return gOpts.hidden
}
func getInfo(path string) []string {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.info[key]; ok {
return val
}
if val, ok := gLocalOpts.info[path]; ok {
return val
}
return gOpts.info
}
func getReverse(path string) bool {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.reverse[key]; ok {
return val
}
if val, ok := gLocalOpts.reverse[path]; ok {
return val
}
return gOpts.reverse
}
func getSortBy(path string) sortMethod {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.sortby[key]; ok {
return val
}
if val, ok := gLocalOpts.sortby[path]; ok {
return val
}
return gOpts.sortby
}