diff options
| -rw-r--r-- | man/vis.1 | 11 | ||||
| -rw-r--r-- | sam.c | 6 | ||||
| -rw-r--r-- | vis-cmds.c | 13 | ||||
| -rw-r--r-- | vis-core.h | 1 | ||||
| -rw-r--r-- | vis.c | 2 |
5 files changed, 32 insertions, 1 deletions
@@ -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 @@ -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, @@ -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; @@ -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; @@ -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) |
