Skip to content

Commit

Permalink
vis: add loadmethod option
Browse files Browse the repository at this point in the history
Valid values are `read`, `mmap` or `auto`.
  • Loading branch information
martanne committed May 30, 2018
1 parent d9b8f7b commit c0eb121
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
11 changes: 11 additions & 0 deletions man/vis.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ enum {
OPTION_CURSOR_LINE,
OPTION_COLOR_COLUMN,
OPTION_SAVE_METHOD,
OPTION_LOAD_METHOD,
OPTION_CHANGE_256COLORS,
};

Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions vis-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions vis-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c0eb121

Please sign in to comment.