history_save_max

This commit is contained in:
Xinhao Yuan 2019-07-05 10:44:42 -04:00
parent 512811d3a7
commit d636696445
2 changed files with 3 additions and 4 deletions

View File

@ -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, 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. 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 ## Other functions

View File

@ -515,12 +515,11 @@ function start_editor(data)
data.cmds[#data.cmds + 1] = current_cmd data.cmds[#data.cmds + 1] = current_cmd
if data.history_file then if data.history_file then
-- only save the last 10 layouts
local file, err = io.open(data.history_file, "w") local file, err = io.open(data.history_file, "w")
if err then if err then
print("cannot save history to " .. data.history_file) print("cannot save history to " .. data.history_file)
else 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]) print("save cmd " .. data.cmds[i])
file:write(data.cmds[i] .. "\n") file:write(data.cmds[i] .. "\n")
end end