aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-22 19:30:58 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-22 19:52:47 +0100
commita6c13d77f2f5f504c7b99e66db5f7d52c1368b8a (patch)
treecb952691971c790a2b951dc5cac6068097355bb2
parent3af77d3e21cc154a24ecf37b83b217066d296ec9 (diff)
downloadsciteco-a6c13d77f2f5f504c7b99e66db5f7d52c1368b8a.tar.gz
allow setting the "*" register as an alternative to nEB
this is more consistent with SciTECO's idea of abstract registers and allows the currend buffer to be saved on the Q-Register stack. This allows the idiom: [* ! ...change current buffer... ! ]*
-rw-r--r--doc/sciteco.7.template19
-rw-r--r--lib/session.tes7
-rw-r--r--src/qregisters.cpp22
-rw-r--r--src/qregisters.h9
-rw-r--r--src/ring.h5
-rw-r--r--teco.ini2
6 files changed, 45 insertions, 19 deletions
diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template
index 4dd08b2..7a2e924 100644
--- a/doc/sciteco.7.template
+++ b/doc/sciteco.7.template
@@ -742,7 +742,24 @@ Replacement string register.
Its integer part is unused.
.TP
.BR * " (asterisk)"
-Name and id of current buffer in ring.
+File name (string part) and id (numeric part) of current
+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.
+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,
+as in \(lq1U*\(rq, is equivalent to editing a buffer by id
+(e.g. \(lq1EB\fB$\fP\(rq) but is shorter since there is no
+string parameter.
+This allows the useful idioms of changing to the previous
+buffer with \(lq-%*\fB$\fP\(rq, changing to the next
+buffer with \(lq%*\fB$\fP\(rq and changing the current buffer
+temporarily:
+.EX
+[* ! ...change current buffer... ! ]*
+.EE
.TP
.BR $ " (Escape)"
Command-line replacement register.
diff --git a/lib/session.tes b/lib/session.tes
index d038db5..0c3ef0a 100644
--- a/lib/session.tes
+++ b/lib/session.tes
@@ -2,7 +2,7 @@
! Path of the session profile.
Change this to save/load a custom profile !
-EQ[session.path] IQ[$HOME]/.teco_session 1EB
+[* EQ[session.path] IQ[$HOME]/.teco_session ]*
@[session.save]{
Q*U.[curbuf]
@@ -18,6 +18,7 @@ EQ[session.path] IQ[$HOME]/.teco_session 1EB
EBQ[session.path]
HK G.[session] EW EF
+ Q.[curbuf]EB
}
@[session.load]{
@@ -35,8 +36,6 @@ EQ[session.path] IQ[$HOME]/.teco_session 1EB
@[session.git]{
! if there is no Git repository, session.path is left as it is !
:EG[session.path]git rev-parse --show-toplevel"S
- Q*U.#cb
- EQ[session.path] ZJ -D I/.teco_session
- Q.#cbEB
+ [* EQ[session.path] ZJ -D I/.teco_session ]*
'
}
diff --git a/src/qregisters.cpp b/src/qregisters.cpp
index 24ca904..846a5a4 100644
--- a/src/qregisters.cpp
+++ b/src/qregisters.cpp
@@ -229,16 +229,24 @@ QRegister::load(const gchar *filename)
}
tecoInt
-QRegisterBufferInfo::get_integer(void)
+QRegisterBufferInfo::set_integer(tecoInt v)
{
- tecoInt id = 1;
+ if (!ring.edit(v))
+ throw Error("Invalid buffer id %" TECO_INTEGER_FORMAT, v);
- for (Buffer *buffer = ring.first();
- buffer != ring.current;
- buffer = buffer->next())
- id++;
+ return v;
+}
- return id;
+void
+QRegisterBufferInfo::undo_set_integer(void)
+{
+ current_doc_undo_edit();
+}
+
+tecoInt
+QRegisterBufferInfo::get_integer(void)
+{
+ return ring.get_id();
}
gchar *
diff --git a/src/qregisters.h b/src/qregisters.h
index cf2c644..9a7618b 100644
--- a/src/qregisters.h
+++ b/src/qregisters.h
@@ -146,12 +146,9 @@ class QRegisterBufferInfo : public QRegister {
public:
QRegisterBufferInfo() : QRegister("*") {}
- tecoInt
- set_integer(tecoInt v)
- {
- return v;
- }
- void undo_set_integer(void) {}
+ /* setting "*" is equivalent to nEB */
+ tecoInt set_integer(tecoInt v);
+ void undo_set_integer(void);
tecoInt get_integer(void);
diff --git a/src/ring.h b/src/ring.h
index 5dc3a37..7aa4f27 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -187,6 +187,11 @@ public:
}
tecoInt get_id(Buffer *buffer);
+ inline tecoInt
+ get_id(void)
+ {
+ return get_id(current);
+ }
Buffer *find(const gchar *filename);
Buffer *find(tecoInt id);
diff --git a/teco.ini b/teco.ini
index 759124e..67ead44 100644
--- a/teco.ini
+++ b/teco.ini
@@ -49,7 +49,7 @@ Z"=
M[session.load]
|
[.f
- <:L;R 0X.f EBQ.f EB L>
+ <:L;R 0X.f [* EBQ.f ]* L>
].f
-EF
'