aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-03-10 18:35:00 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-03-10 18:35:00 +0100
commita0d1231340617ab28a941f723793ad7be242ca0c (patch)
tree68d3e0aea009e034a6abafc4dd3a89629641db37
parent67b846c099968439c415ae18fcc6736bdd26e233 (diff)
downloadsciteco-a0d1231340617ab28a941f723793ad7be242ca0c.tar.gz
always normalize directory separators to "/" in the "*" Q-Register
* on Windows, this register contained backward slashes. This means that macros working with that register had to cope with both forward and backward slashes. * The file names are still displayed in the native style by the UI * This approach also has disadvantages: What if the user wants to insert the current file name somewhere where "\" is expected? However, this seems to be an unlikely case and the use can still replace the "/" with "\" again. * Avoid some virtual method calls in QRegisterBufferInfo
-rw-r--r--doc/sciteco.7.template10
-rw-r--r--src/qregisters.cpp27
2 files changed, 32 insertions, 5 deletions
diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template
index 6c48f20..00c8366 100644
--- a/doc/sciteco.7.template
+++ b/doc/sciteco.7.template
@@ -636,7 +636,10 @@ There is at most one unnamed buffer in the ring, identified
by the empty name.
Named buffers are buffers with an associated file name.
The file might or might not already exist in the file system.
-The file name uses the host system's path seperator.
+The file name uses the host system's directory separator, but for
+the sake of macro portability the directory separators are
+normalized to \(lq/\(rq when accessing the current buffer's
+file name with the \(lq*\(rq Q-Register.
File names are always tried to be normalized to absolute
paths to make them independant of \*(ST's current working
directory.
@@ -897,6 +900,11 @@ buffer in ring.
The unnamed buffer has an empty name.
If the current document is a register, this returns the
name or id of the buffer last edited.
+Buffer file names are \fItried\fP to be made absolute paths
+by \*(ST, but this might not always be possible.
+Also, file names accessed with the \(lq*\(rq register will
+always have forward-slash directory separators even if they
+are displayed differently in the user interface.
The \(lq*\(rq register may also be edited but changing its
string contents has no effect on the file name of the buffer.
Setting the numeric part of the \(lq*\(rq register,
diff --git a/src/qregisters.cpp b/src/qregisters.cpp
index 20f6e99..acb12cf 100644
--- a/src/qregisters.cpp
+++ b/src/qregisters.cpp
@@ -318,7 +318,22 @@ QRegisterBufferInfo::get_integer(void)
gchar *
QRegisterBufferInfo::get_string(void)
{
- return g_strdup(ring.current->filename ? : "");
+ gchar *str = g_strdup(ring.current->filename ? : "");
+
+ /*
+ * On platforms with a default non-forward-slash directory
+ * separator (i.e. Windows), Buffer::filename will have
+ * the wrong separator.
+ * To make the life of macros that evaluate "*" easier,
+ * the directory separators are normalized to "/" here.
+ * This does not change the size of the string, so
+ * get_string_size() still works.
+ */
+#if G_DIR_SEPARATOR != '/'
+ g_strdelimit(str, G_DIR_SEPARATOR_S, '/');
+#endif
+
+ return str;
}
gsize
@@ -330,7 +345,8 @@ QRegisterBufferInfo::get_string_size(void)
gint
QRegisterBufferInfo::get_character(gint position)
{
- if (position < 0 || position >= (gint)get_string_size())
+ if (position < 0 ||
+ position >= (gint)QRegisterBufferInfo::get_string_size())
return -1;
return ring.current->filename[position];
@@ -339,11 +355,14 @@ QRegisterBufferInfo::get_character(gint position)
void
QRegisterBufferInfo::edit(void)
{
+ gchar *str;
+
QRegister::edit();
QRegisters::view.ssm(SCI_BEGINUNDOACTION);
- QRegisters::view.ssm(SCI_SETTEXT, 0,
- (sptr_t)(ring.current->filename ? : ""));
+ str = QRegisterBufferInfo::get_string();
+ QRegisters::view.ssm(SCI_SETTEXT, 0, (sptr_t)str);
+ g_free(str);
QRegisters::view.ssm(SCI_ENDUNDOACTION);
QRegisters::view.undo_ssm(SCI_UNDO);