From a6c13d77f2f5f504c7b99e66db5f7d52c1368b8a Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 22 Nov 2014 19:30:58 +0100 Subject: 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... ! ]* --- src/qregisters.cpp | 22 +++++++++++++++------- src/qregisters.h | 9 +++------ src/ring.h | 5 +++++ 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'src') 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); -- cgit v1.2.3