@@ -100,20 +100,20 @@ module.load = function()
100
100
101
101
if module .config .public .open_last_workspace and vim .fn .argc (- 1 ) == 0 then
102
102
if module .config .public .open_last_workspace == " default" then
103
- if not module .config . public .default_workspace then
103
+ if not module .public .get_default_workspace () then
104
104
log .warn (
105
105
' Configuration error in `core.dirman`: the `open_last_workspace` option is set to "default", but no default workspace is provided in the `default_workspace` configuration variable. Defaulting to opening the last known workspace.'
106
106
)
107
107
module .public .set_last_workspace ()
108
108
return
109
109
end
110
110
111
- module .public .open_workspace (module .config . public .default_workspace )
111
+ module .public .open_workspace (module .public .get_default_workspace () )
112
112
else
113
113
module .public .set_last_workspace ()
114
114
end
115
- elseif module .config . public .default_workspace then
116
- module .public .set_workspace (module .config . public .default_workspace )
115
+ elseif module .public .get_default_workspace () then
116
+ module .public .set_workspace (module .public .get_default_workspace () )
117
117
end
118
118
end
119
119
@@ -131,6 +131,7 @@ module.config.public = {
131
131
-- The index file is the "entry point" for all of your notes.
132
132
index = " index.norg" ,
133
133
-- The default workspace to set whenever Neovim starts.
134
+ -- If a function, will be called with the current workspace and should resolve to a valid workspace name
134
135
default_workspace = nil ,
135
136
-- Whether to open the last workspace's index file when `nvim` is executed
136
137
-- without arguments.
@@ -166,6 +167,15 @@ module.public = {
166
167
get_current_workspace = function ()
167
168
return module .private .current_workspace
168
169
end ,
170
+ --- The default workspace, may be set dynamically based on cwd
171
+ --- @return string ? # Should evaluate to a valid workspace name
172
+ get_default_workspace = function ()
173
+ if type (module .config .public .default_workspace ) == " function" then
174
+ return module .config .public .default_workspace ()
175
+ end
176
+
177
+ return module .config .public .default_workspace
178
+ end ,
169
179
--- Sets the workspace to the one specified (if it exists) and broadcasts the workspace_changed event
170
180
--- @param ws_name string #The name of a valid namespace we want to switch to
171
181
--- @return boolean #True if the workspace is set correctly, false otherwise
@@ -361,7 +371,7 @@ module.public = {
361
371
362
372
local last_workspace = storage .retrieve (" last_workspace" )
363
373
last_workspace = type (last_workspace ) == " string" and last_workspace
364
- or module .config . public .default_workspace
374
+ or module .public .get_default_workspace ()
365
375
or " "
366
376
367
377
local workspace_path = module .public .get_workspace (last_workspace )
0 commit comments