aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.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/parser.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/parser.cpp')
-rw-r--r--src/parser.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 5e8f6f6..6462933 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -53,6 +53,7 @@ namespace States {
StateControl control;
StateASCII ascii;
StateFCommand fcommand;
+ StateChangeDir changedir;
StateCondCommand condcommand;
StateECommand ecommand;
StateScintilla_symbols scintilla_symbols;
@@ -1448,6 +1449,7 @@ StateFCommand::StateFCommand() : State()
transitions['D'] = &States::searchdelete;
transitions['S'] = &States::replace;
transitions['R'] = &States::replacedefault;
+ transitions['G'] = &States::changedir;
}
State *
@@ -1552,6 +1554,60 @@ StateFCommand::custom(gchar chr)
return &States::start;
}
+void
+UndoTokenChangeDir::run(void)
+{
+ /*
+ * Changing the directory on rub-out may fail.
+ * This is handled silently.
+ */
+ g_chdir(dir);
+}
+
+/*$
+ * FG[directory]$ -- Change working directory
+ *
+ * Changes the process' current working directory
+ * to <directory> which affects all subsequent
+ * operations on relative file names like
+ * tab-completions.
+ * It is also inherited by external processes spawned
+ * via \fBEC\fP and \fBEG\fP.
+ *
+ * If <directory> is omitted, the working directory
+ * is changed to the current user's home directory
+ * as set by the \fBHOME\fP environment variable.
+ * This variable is alwas initialized by \*(ST
+ * (see \fBsciteco\fP(1)).
+ * Therefore \(lqFG\fB$\fP\(rq is roughly equivalent
+ * to \(lqFG^EQ[$HOME]\fB$\fP\(rq.
+ *
+ * The current working directory is also mapped to
+ * the Q-Register \(lq$\(rq (dollar sign) which
+ * may be used retrieve the current working directory.
+ *
+ * String-building characters are enabled on this
+ * command and directories can be tab-completed.
+ */
+State *
+StateChangeDir::done(const gchar *str)
+{
+ BEGIN_EXEC(&States::start);
+
+ /* passes ownership of string to undo token object */
+ undo.push(new UndoTokenChangeDir(g_get_current_dir()));
+
+ if (!*str)
+ str = g_getenv("HOME");
+
+ if (g_chdir(str))
+ /* FIXME: Is errno usable on Windows here? */
+ throw Error("Cannot change working directory "
+ "to \"%s\"", str);
+
+ return &States::start;
+}
+
StateCondCommand::StateCondCommand() : State()
{
transitions['\0'] = this;