summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-11 00:05:25 +0800
committerruki <[email protected]>2017-05-11 00:05:25 +0800
commit18cc92064b4331e3d4fb5ca63ef3723b955d4448 (patch)
treeaea22341d7a5056c8337e011acd8fb7ec1d55f8d
parent7d461c4de3e3476366b53aa67dd17f4f1e785ee2 (diff)
save global repl history
-rw-r--r--core/src/xmake/readline/history_list.c3
-rw-r--r--xmake/core/main.lua2
-rw-r--r--xmake/core/project/history.lua45
-rw-r--r--xmake/core/sandbox/modules/import/core/project/history.lua18
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua4
-rw-r--r--xmake/plugins/macro/main.lua6
6 files changed, 57 insertions, 21 deletions
diff --git a/core/src/xmake/readline/history_list.c b/core/src/xmake/readline/history_list.c
index d3145c4c7..8b48b6ded 100644
--- a/core/src/xmake/readline/history_list.c
+++ b/core/src/xmake/readline/history_list.c
@@ -34,11 +34,10 @@
*/
#include "prefix.h"
-#ifdef XM_CONFIG_API_HAVE_READLINE
-
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
+#ifdef XM_CONFIG_API_HAVE_READLINE
// history_list wrapper
tb_int_t xm_readline_history_list(lua_State* lua)
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index 97c77ae43..a809fc508 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -181,7 +181,7 @@ function main.done()
-- save command lines to history
if os.isfile(xmake._PROJECT_FILE) then
- history.save("cmdlines", option.cmdline())
+ history("local.history"):save("cmdlines", option.cmdline())
end
-- run task
diff --git a/xmake/core/project/history.lua b/xmake/core/project/history.lua
index a6ed24cb3..72d090784 100644
--- a/xmake/core/project/history.lua
+++ b/xmake/core/project/history.lua
@@ -33,29 +33,46 @@ local utils = require("base/utils")
local string = require("base/string")
local cache = require("project/cache")
--- get cache
-function history._cache()
+-- the cache instance
+--
+-- @param scopename local.xxxx
+-- global.xxxx
+--
+function history._instance(scopename)
+
+ -- check
+ assert(scopename)
- -- get it from cache first if exists
- if history._CACHE then
- return history._CACHE
+ -- init instances
+ history._INSTANCES = history._INSTANCES or {}
+ local instances = history._INSTANCES
+
+ -- this instance has been initialized?
+ if instances[scopename] then
+ return instances[scopename]
end
+ -- init instance
+ local instance = table.inherit(history)
+
-- init cache
- history._CACHE = cache("local.history")
+ instance._CACHE = cache(scopename)
+
+ -- save instance
+ instances[scopename] = instance
-- ok
- return history._CACHE
+ return instance
end
-- save history
-function history.save(key, value)
+function history:save(key, value)
-- check
assert(key and value ~= nil)
-- load history values first
- local values = history.load(key) or {}
+ local values = self:load(key) or {}
-- remove the oldest value if be full
if #values > 64 then
@@ -66,16 +83,16 @@ function history.save(key, value)
table.insert(values, value)
-- save history
- history._cache():set(key, values)
- history._cache():flush()
+ self._CACHE:set(key, values)
+ self._CACHE:flush()
end
-- load history
-function history.load(key)
+function history:load(key)
-- load it
- return history._cache():get(key)
+ return self._CACHE:get(key)
end
-- return module: history
-return history
+return history._instance
diff --git a/xmake/core/sandbox/modules/import/core/project/history.lua b/xmake/core/sandbox/modules/import/core/project/history.lua
index da95817a9..b205afdf9 100644
--- a/xmake/core/sandbox/modules/import/core/project/history.lua
+++ b/xmake/core/sandbox/modules/import/core/project/history.lua
@@ -33,19 +33,33 @@ local option = require("base/option")
local string = require("base/string")
local history = require("project/history")
local raise = require("sandbox/modules/raise")
+local instance = nil
+
+-- enter the history scope
+function sandbox_core_project_history.enter(scopename)
+
+ -- get the history instance
+ instance = history(scopename)
+end
-- load the history data
function sandbox_core_project_history.load(key)
+ -- check
+ assert(instance)
+
-- load it
- return history.load(key)
+ return instance:load(key)
end
-- save the history data
function sandbox_core_project_history.save(key, value)
+ -- check
+ assert(instance)
+
-- save it
- history.save(key, value)
+ instance:save(key, value)
end
-- return module
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
index 5576d48a2..262363e1a 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
@@ -54,7 +54,7 @@ function sandbox_core_sandbox.interactive()
readline.clear_history()
-- load history
- replhistory = history.load("replhistory") or {}
+ replhistory = history("global.history"):load("replhistory") or {}
for _, ln in ipairs(replhistory) do
readline.add_history(ln)
end
@@ -70,7 +70,7 @@ function sandbox_core_sandbox.interactive()
local entries = readline.history_list()
if #entries > #replhistory then
for i = #replhistory + 1, #entries do
- history.save("replhistory", entries[i].line)
+ history("global.history"):save("replhistory", entries[i].line)
end
end
diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua
index ca2ca02b2..1fbd26207 100644
--- a/xmake/plugins/macro/main.lua
+++ b/xmake/plugins/macro/main.lua
@@ -201,6 +201,9 @@ end
-- begin to record macro
function _begin()
+ -- enter local history
+ history.enter("local.history")
+
-- patch begin tag to the history: cmdlines
history.save("cmdlines", "__macro_begin__")
end
@@ -208,6 +211,9 @@ end
-- end to record macro
function _end(macroname)
+ -- enter local history
+ history.enter("local.history")
+
-- load the history: cmdlines
local cmdlines = history.load("cmdlines")