diff --git a/README.md b/README.md index 50cd108..bc48eea 100644 --- a/README.md +++ b/README.md @@ -131,8 +131,7 @@ If `cycle` is true, it then moves the window by cycling all regions. ### `name` as a function in `machi.layout.create` -When passed in as a function, `name` takes the tag `t` and a boolean flag `p` and returns a function for the tag-dependent name of the layout. -Flag `p` is set true when the name is used for persisting the layout. If the layout is not intented to persist, returning `nil` when `p` is true to skip persisting. +When passed in as a function, `name` takes the tag `t` and returns (1) a string for the tag-dependent name of the layout, and (2) a boolean indicating the persistence of the layout. The default layout, `machi.default_layout`, uses the screen geometry and the tag name for name, thus allows the actual layout to be tag- and screen-dependent. To differentiate tags with the same name, you may need a more advanced naming function. diff --git a/editor.lua b/editor.lua index cc13a9e..16e611f 100644 --- a/editor.lua +++ b/editor.lua @@ -653,8 +653,8 @@ local function create(data) -- bring the current cmd to the front data.cmds[#data.cmds + 1] = current_cmd - local instance_name = layout.machi_get_instance_name(tag, true) - if instance_name ~= nil then + local instance_name, persistent = layout.machi_get_instance_name(tag) + if persistent then data.last_cmd[instance_name] = current_cmd if data.history_file then local file, err = io.open(data.history_file, "w") diff --git a/init.lua b/init.lua index 9e7d699..cdc8047 100644 --- a/init.lua +++ b/init.lua @@ -3,13 +3,13 @@ local editor = require(... .. ".editor") local switcher = require(... .. ".switcher") local default_editor = editor.create() local default_layout = layout.create( - function (tag, _persist) + function (tag) if tag.machi_name_cache == nil then tag.machi_name_cache = tostring(tag.screen.geometry.width) .. "x" .. tostring(tag.screen.geometry.height) .. "+" .. tostring(tag.screen.geometry.x) .. "+" .. tostring(tag.screen.geometry.y) .. '+' .. tag.name end - return tag.machi_name_cache + return tag.machi_name_cache, true end, default_editor) local gcolor = require("gears.color") diff --git a/layout.lua b/layout.lua index 4e4ea79..8ee9ec4 100644 --- a/layout.lua +++ b/layout.lua @@ -51,14 +51,14 @@ local function create(name, editor) if type(name) == "function" then get_instance_name = name else - get_instance_name = function () return name end + get_instance_name = function () return name, true end end local function get_instance(tag) - local name = get_instance_name(tag, false) + local name, persistent = get_instance_name(tag) if instances[name] == nil then instances[name] = { - cmd = editor.get_last_cmd(name), + cmd = persistent and editor.get_last_cmd(name) or nil, regions_cache = {}, } end