From d6366964458f81f17d4a3bad85aaad4648dae7dd Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Fri, 5 Jul 2019 10:44:42 -0400 Subject: [PATCH] history_save_max --- README.md | 4 ++-- editor.lua | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 91ff822..e660579 100644 --- a/README.md +++ b/README.md @@ -106,11 +106,11 @@ history You need to specify the path of the history file in the editor data, then restore the persistent history by `layout_machi.editor.restore_data`. For example, ``` -machi_layout_data = layout_machi.editor.restore_data({ history_file = ".machi-layout" }) +machi_layout_data = layout_machi.editor.restore_data({ history_file = ".machi-layout", history_save_max = 10 }) ``` Then start the editor with the restored data. -For now the last 10 commands are persisted. +The last `history_save_max` commands are persisted. ## Other functions diff --git a/editor.lua b/editor.lua index 709fe1f..45d468a 100644 --- a/editor.lua +++ b/editor.lua @@ -515,12 +515,11 @@ function start_editor(data) data.cmds[#data.cmds + 1] = current_cmd if data.history_file then - -- only save the last 10 layouts local file, err = io.open(data.history_file, "w") if err then print("cannot save history to " .. data.history_file) else - for i = max(1, #data.cmds - 10), #data.cmds do + for i = max(1, #data.cmds - data.history_save_max + 1), #data.cmds do print("save cmd " .. data.cmds[i]) file:write(data.cmds[i] .. "\n") end