revise the naming function
This commit is contained in:
parent
b39d60741e
commit
dfb0f19512
|
@ -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.
|
||||
|
|
|
@ -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")
|
||||
|
|
4
init.lua
4
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")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue