aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cmdline.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-06-02 15:38:00 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-06-02 15:38:00 +0200
commit02d414b3ab447e637fef776e387aa5a07293738a (patch)
tree60d5db01e9e0cc15f1f8e84abb14138cb0ca54a3 /src/cmdline.cpp
parent6c62ccc436d972a872616c187d460ed61c8bc0d2 (diff)
downloadsciteco-02d414b3ab447e637fef776e387aa5a07293738a.tar.gz
added <FG> command and special Q-Register "$" to set and get the current working directory
* FG stands for "Folder Go" * FG behaves similar to a Unix shell `cd`. Without arguments, it changes to the $HOME directory. * The $HOME directory was previously only used by $SCITECOCONFIG on Unix. Now it is documented on its own, since the HOME directory should also be configurable on Windows - e.g. to adapt SciTECO to a MinGW or Cygwin installation. HOME is initialized just like the other environment variables. This also means that now, the $HOME Q-Register is always defined and can be used by platform-agnostic macros. * FG uses a new kind of tab-completion: for directories only. It would be annoying to complete the FG command after every directory, so this tab-completion does not close the command automatically. Theoretically, it would be possible to close the command after completing a directory with no subdirectories, but this is not supported currently. * Filename arguments are no longer completed with " " if {} escaping is in place as this brings no benefit. Instead no completion character is inserted for this escape mode. * "$" was mapped to the current directory to support an elegant way to insert/get the current directory. Also this allows the idiom "[$ FG...new_dir...$ ]$" for changing the current directory temporarily. * The Q-Register stack was extended to support restoring the string part of special Q-Registers (that overwrite the default functionality) when using the "[$" and "]$" commands. * fixed minor typos (american spelling)
Diffstat (limited to 'src/cmdline.cpp')
-rw-r--r--src/cmdline.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/cmdline.cpp b/src/cmdline.cpp
index b85850a..82c8434 100644
--- a/src/cmdline.cpp
+++ b/src/cmdline.cpp
@@ -48,7 +48,8 @@
namespace SciTECO {
-static gchar *filename_complete(const gchar *filename, gchar completed = ' ');
+static gchar *filename_complete(const gchar *filename, gchar completed = ' ',
+ GFileTest file_test = G_FILE_TEST_EXISTS);
static gchar *symbol_complete(SymbolList &list, const gchar *symbol,
gchar completed = ' ');
@@ -291,6 +292,7 @@ Cmdline::process_edit_cmd(gchar key)
interface.popup_clear();
if (States::is_file()) {
+ /* File names, including directories */
if (modifier_enabled) {
/* reinsert one level of file name */
while (States::is_file() && rubout_len &&
@@ -416,6 +418,19 @@ Cmdline::process_edit_cmd(gchar key)
while (spaces--)
insert(' ');
+ } else if (States::is_dir()) {
+ if (interface.popup_is_shown()) {
+ /* cycle through popup pages */
+ interface.popup_show();
+ break;
+ }
+
+ gchar *new_chars = filename_complete(strings[0], '\0',
+ G_FILE_TEST_IS_DIR);
+
+ if (new_chars)
+ insert(new_chars);
+ g_free(new_chars);
} else if (States::is_file()) {
if (interface.popup_is_shown()) {
/* cycle through popup pages */
@@ -423,7 +438,7 @@ Cmdline::process_edit_cmd(gchar key)
break;
}
- gchar complete = escape_char == '{' ? ' ' : escape_char;
+ gchar complete = escape_char == '{' ? '\0' : escape_char;
gchar *new_chars = filename_complete(strings[0], complete);
if (new_chars)
@@ -574,7 +589,8 @@ Cmdline::fnmacro(const gchar *name)
}
static gchar *
-filename_complete(const gchar *filename, gchar completed)
+filename_complete(const gchar *filename, gchar completed,
+ GFileTest file_test)
{
gsize dirname_len;
gchar *dirname, dir_sep;
@@ -635,12 +651,20 @@ filename_complete(const gchar *filename, gchar completed)
* so g_strconcat() works here.
*/
cur_filename = g_strconcat(dirname, cur_basename, NIL);
- if (!*basename && !file_is_visible(cur_filename)) {
+
+ /*
+ * NOTE: This avoids g_file_test() for G_FILE_TEST_EXISTS
+ * since the file we process here should always exist.
+ */
+ if ((!*basename && !file_is_visible(cur_filename)) ||
+ (file_test != G_FILE_TEST_EXISTS &&
+ !g_file_test(cur_filename, file_test))) {
g_free(cur_filename);
continue;
}
- if (g_file_test(cur_filename, G_FILE_TEST_IS_DIR))
+ if (file_test == G_FILE_TEST_IS_DIR ||
+ g_file_test(cur_filename, G_FILE_TEST_IS_DIR))
String::append(cur_filename, dir_sep);
files = g_slist_prepend(files, cur_filename);
@@ -683,7 +707,13 @@ filename_complete(const gchar *filename, gchar completed)
}
interface.popup_show();
- } else if (files_len == 1 && !filename_is_dir((gchar *)files->data)) {
+ } else if (completed && files_len == 1 &&
+ !filename_is_dir((gchar *)files->data)) {
+ /*
+ * FIXME: If we are completing only directories,
+ * we can theoretically insert the completed character
+ * after directories without subdirectories
+ */
String::append(insert, completed);
}