aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/vis.111
-rw-r--r--sam.c6
-rw-r--r--vis-cmds.c13
-rw-r--r--vis-core.h1
-rw-r--r--vis.c2
5 files changed, 32 insertions, 1 deletions
diff --git a/man/vis.1 b/man/vis.1
index 556f445..40f2432 100644
--- a/man/vis.1
+++ b/man/vis.1
@@ -1398,6 +1398,17 @@ which tries the former before falling back to the latter.
The rename method fails for symlinks, hardlinks, in case of insufficient
directory permissions or when either the file owner, group, POSIX ACL or
SELinux labels can not be restored.
+.It Cm loadmethod Op Ar auto
+How existing files should be loaded,
+.Ar read
+which copies the file content to an independent in-memory buffer,
+.Ar mmap
+which memory maps the file from disk and uses OS capabilities as
+caching layer or
+.Ar auto
+which tries the former for files smaller than 8Mb and the latter for
+lager ones. WARNING: modifying a memory mapped file in-place will
+cause data loss.
.El
.
.Sh COMMAND and SEARCH PROMPT
diff --git a/sam.c b/sam.c
index 6665043..3b7aaf3 100644
--- a/sam.c
+++ b/sam.c
@@ -295,6 +295,7 @@ enum {
OPTION_CURSOR_LINE,
OPTION_COLOR_COLUMN,
OPTION_SAVE_METHOD,
+ OPTION_LOAD_METHOD,
OPTION_CHANGE_256COLORS,
};
@@ -369,6 +370,11 @@ static const OptionDef options[] = {
VIS_OPTION_TYPE_STRING|VIS_OPTION_NEED_WINDOW,
VIS_HELP("Save method to use for current file 'auto', 'atomic' or 'inplace'")
},
+ [OPTION_LOAD_METHOD] = {
+ { "loadmethod" },
+ VIS_OPTION_TYPE_STRING,
+ VIS_HELP("How to load existing files 'auto', 'read' or 'mmap'")
+ },
[OPTION_CHANGE_256COLORS] = {
{ "change-256colors" },
VIS_OPTION_TYPE_BOOL,
diff --git a/vis-cmds.c b/vis-cmds.c
index f181544..15bd89c 100644
--- a/vis-cmds.c
+++ b/vis-cmds.c
@@ -332,6 +332,19 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Select
return false;
}
break;
+ case OPTION_LOAD_METHOD:
+ if (strcmp("auto", arg.s) == 0) {
+ vis->load_method = TEXT_LOAD_AUTO;
+ } else if (strcmp("read", arg.s) == 0) {
+ vis->load_method = TEXT_LOAD_READ;
+ } else if (strcmp("mmap", arg.s) == 0) {
+ vis->load_method = TEXT_LOAD_MMAP;
+ } else {
+ vis_info_show(vis, "Invalid load method `%s', expected "
+ "'auto', 'read' or 'mmap'", arg.s);
+ return false;
+ }
+ break;
case OPTION_CHANGE_256COLORS:
vis->change_colors = toggle ? !vis->change_colors : arg.b;
break;
diff --git a/vis-core.h b/vis-core.h
index 900f498..d8f5e1d 100644
--- a/vis-core.h
+++ b/vis-core.h
@@ -215,6 +215,7 @@ struct Vis {
Map *actions; /* registered editor actions / special keys commands */
Array actions_user; /* dynamically allocated editor actions */
lua_State *lua; /* lua context used for syntax highligthing */
+ enum TextLoadMethod load_method; /* how existing files should be loaded */
VisEvent *event;
Array operators;
Array motions;
diff --git a/vis.c b/vis.c
index 64ad3ba..03b01ab 100644
--- a/vis.c
+++ b/vis.c
@@ -192,7 +192,7 @@ static File *file_new(Vis *vis, const char *name) {
}
File *file = NULL;
- Text *text = text_load(name);
+ Text *text = text_load_method(name, vis->load_method);
if (!text && name && errno == ENOENT)
text = text_load(NULL);
if (!text)