From 99379d23f43c55bd0a49f77d79985d98aa64bd27 Mon Sep 17 00:00:00 2001 From: Tamas TEVESZ Date: Sun, 12 Feb 2017 19:03:30 +0100 Subject: Add :file command :file - display the current file name on the status line :file /some/file - set the current file name to whatever specified Modeled after vim's file command; in response to #141. --- src/cmds_command.c | 27 +++++++++++++++++++++++++++ src/doc | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/src/cmds_command.c b/src/cmds_command.c index efbd537..88401e9 100644 --- a/src/cmds_command.c +++ b/src/cmds_command.c @@ -55,6 +55,7 @@ L"e! txt", L"datefmt", L"delfilter", L"delfilters", +L"file", L"fill", L"filteron", L"filteroff", @@ -613,6 +614,32 @@ void do_commandmode(struct block * sb) { } else if ( inputline[0] == L'w' ) { savefile(); + } else if ( ! wcsncmp(inputline, L"file ", 5) ) { + + char cline [BUFFERSIZE]; + wordexp_t p; + + wcstombs(cline, inputline, BUFFERSIZE); + del_range_chars(cline, 0, 4); + wordexp(cline, &p, 0); + + if ( p.we_wordc < 1 ) { + sc_error("Failed to expand filename"); + } else { + strncpy(curfile, p.we_wordv[0], PATHLEN - 1); + sc_info("File name set to \"%s\"", curfile); + } + + wordfree(&p); + + } else if ( ! wcscmp(inputline, L"file") ) { + + if( ! *curfile ) { + sc_info("Current file has no name"); + } else { + sc_info("Current file: \"%s\"", curfile); + } + } else if ( inputline[0] == L'x' ) { if ( savefile() == 0 ) shall_quit = 1; diff --git a/src/doc b/src/doc index c369692..36d7784 100644 --- a/src/doc +++ b/src/doc @@ -422,6 +422,13 @@ Commands for handling cell content: Remove the map sequence {lhs} that takes effect in INSERT_MODE. + :file [{file}] + If {file} is given, expand {file}, and set the current file + name to the result of the expansion. + + If {file} is not given, display the current file name on + the status line. + :fill {range} {initial_number} {increment_number} Fill range {range} with values. The first cell of the range will have {initial_number} and each successive cell -- cgit v1.2.3