From 00e3e0aba5595e9f2b511d343161267cb704fa70 Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Sat, 21 Mar 2020 17:01:16 -0400 Subject: [PATCH] Provided default value of editor; Changed document. --- README.md | 9 ++++++--- editor.lua | 6 ++---- init.lua | 4 ++-- layout.lua | 6 +++++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 84b6ea0..0f214d6 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,13 @@ You can change it after loading the module. Use `local layout = machi.layout.create(args)` to instantiate the layout with an editor object. `args` is a table of arguments, where the followings can be used: - - `name`: the constant name of the layout - - `name_func`: a `function(t)` closure that returns a string for tag `t`. `name_func` overrides `name` - - `persistent`: whether to keep a history of the command for the layout. Default is `true` + - `name`: the constant name of the layout. + - `name_func`: a `function(t)` closure that returns a string for tag `t`. `name_func` overrides `name`. + - `persistent`: whether to keep a history of the command for the layout. The default is `true`. - `default_cmd`: the command to use if there is no persistent history for this layout. + - `editor`: the editor used for the layout. The default is `machi.default_editor` (or `machi.editor.default_editor`). + +Either `name` or `name_func` must be set - others are optional. The function is compatible with the previous `machi.layout.create(name, editor, default_cmd)` calls. diff --git a/editor.lua b/editor.lua index ecc2161..e01d567 100644 --- a/editor.lua +++ b/editor.lua @@ -1,7 +1,3 @@ -local machi = { - layout = require((...):match("(.-)[^%.]+$") .. "layout"), -} - local api = { beautiful = require("beautiful"), wibox = require("wibox"), @@ -965,4 +961,6 @@ function module.create(data) } end +module.default_editor = module.create() + return module diff --git a/init.lua b/init.lua index 6c0c9c4..eca07e6 100644 --- a/init.lua +++ b/init.lua @@ -9,8 +9,8 @@ local function default_name(tag) end return tag.machi_name_cache end -local default_editor = editor.create() -local default_layout = layout.create{ name_func = default_name, editor = default_editor } +local default_editor = editor.default_editor +local default_layout = layout.create{ name_func = default_name } local gcolor = require("gears.color") local beautiful = require("beautiful") diff --git a/layout.lua b/layout.lua index a88e38b..7c4713c 100644 --- a/layout.lua +++ b/layout.lua @@ -1,3 +1,7 @@ +local machi = { + editor = require((...):match("(.-)[^%.]+$") .. "editor"), +} + local api = { screen = screen, awful = require("awful"), @@ -128,7 +132,7 @@ function module.create(args_or_name, editor, default_cmd) else return nil end - args.editor = args.editor or editor + args.editor = args.editor or editor or machi.editor.default_editor args.default_cmd = args.default_cmd or default_cmd or global_default_cmd args.persistent = args.persistent == nil or args.persistent