aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-06-14 19:08:06 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-06-14 19:08:06 +0200
commit15409bae5ffdfce4ef17c4ccf14c8cd4c1b8f37e (patch)
tree852b915a69d57679a05ef5fec0ee6608cdcf2dee /src/parser.cpp
parent573951d4e2bb4fb1d14212583a59ce76344593cc (diff)
downloadsciteco-15409bae5ffdfce4ef17c4ccf14c8cd4c1b8f37e.tar.gz
handle environment variables more consistently
* the registers beginning with "$" are exported into sub-process environments. Therefore macros can now modify the environment (variables) of commands executed via EC/EG. A variable can be modified temporarily, e.g.: [[$FOO] ^U[$FOO]bar$ EC...$ ][$FOO] * SciTECO accesses the global environment registers instead of using g_getenv(). Therefore now, tilde-expansion will always use the current value of the "$HOME" register. Previously, both register and environment variable could diverge. * This effectively fully maps the process environment to a subset of Q-Registers beginning with "$". * This hasn't been implemented by mapping those registers to special implementations that updates the process environment directly, since g_setenv() is non-thread-safe on UNIX and we're expected to have threads soon - at least in the GTK+ UI.
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 3e3f387..f88ae90 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1595,16 +1595,18 @@ UndoTokenChangeDir::run(void)
*
* 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
+ * as set by the \fBHOME\fP environment variable
+ * (i.e. its corresponding \(lq$HOME\(rq environment
+ * register).
+ * This variable is always initialized by \*(ST
* (see \fBsciteco\fP(1)).
* Therefore the expression \(lqFG\fB$\fP\(rq is
- * roughly equivalent to both \(lqFG~\fB$\fP\(rq and
+ * exactly equivalent to both \(lqFG~\fB$\fP\(rq and
* \(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.
+ * the special global 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.
@@ -1612,19 +1614,25 @@ UndoTokenChangeDir::run(void)
State *
StateChangeDir::got_file(const gchar *filename)
{
+ gchar *dir;
+
BEGIN_EXEC(&States::start);
/* passes ownership of string to undo token object */
undo.push(new UndoTokenChangeDir(g_get_current_dir()));
- if (!*filename)
- filename = g_getenv("HOME");
+ dir = *filename ? g_strdup(filename)
+ : QRegisters::globals["$HOME"]->get_string();
- if (g_chdir(filename))
+ if (g_chdir(dir)) {
/* FIXME: Is errno usable on Windows here? */
- throw Error("Cannot change working directory "
- "to \"%s\"", filename);
+ Error err("Cannot change working directory "
+ "to \"%s\"", dir);
+ g_free(dir);
+ throw err;
+ }
+ g_free(dir);
return &States::start;
}