Mercurial > repos > public > matlab_path_manager
changeset 3:ce34182c274e
Add state
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 10 Sep 2018 15:19:55 +0200 |
parents | a9795512f33a |
children | 38c29c9ba07f |
files | +mpm/clear.m +mpm/clear_state.m +mpm/init_state.m +mpm/leave.m +mpm/set.m |
diffstat | 5 files changed, 32 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+mpm/clear.m Mon Sep 10 15:19:55 2018 +0200 @@ -0,0 +1,13 @@ +% Remove all loaded subpaths from the matlab path +function clear() + state = mpm.load_state(); + + subpaths = state.added_paths.keys(); + + for i = 1:length(subpaths) + rmpath(subpaths{i}); + state.added_paths.remove(subpaths{i}); + end + + mpm.save_state(state); +end
--- a/+mpm/clear_state.m Mon Sep 10 14:59:21 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function clear_state() - mpm.save_state(struct()); -end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+mpm/init_state.m Mon Sep 10 15:19:55 2018 +0200 @@ -0,0 +1,5 @@ +function init_state() + s = struct(); + s.added_paths = containers.Map(); + mpm.save_state(s); +end
--- a/+mpm/leave.m Mon Sep 10 14:59:21 2018 +0200 +++ b/+mpm/leave.m Mon Sep 10 15:19:55 2018 +0200 @@ -4,8 +4,14 @@ d = pwd; end + state = mpm.load_state(); + sp = mpm.subpaths(d); for i = 1:length(sp) - rmpath(fullfile(pwd, sp{i})); + subpath = fullfile(pwd, sp{i}); + rmpath(subpath); + state.added_paths.remove(subpath); end + + mpm.save_state(state) end
--- a/+mpm/set.m Mon Sep 10 14:59:21 2018 +0200 +++ b/+mpm/set.m Mon Sep 10 15:19:55 2018 +0200 @@ -4,8 +4,14 @@ d = pwd; end + state = mpm.load_state(); + sp = mpm.subpaths(d); for i = 1:length(sp) - addpath(fullfile(pwd, sp{i})); + subpath = fullfile(pwd, sp{i}); + addpath(subpath); + state.added_paths(subpath) = true; end + + mpm.save_state(state); end