diff options
| author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-11-19 23:59:52 +0100 |
|---|---|---|
| committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-11-20 01:52:39 +0100 |
| commit | 84ab1698e63170a94cfa1c5d99b7316cf3c2b584 (patch) | |
| tree | cb87e28be35e710b960d6e643f4ea7cf5596ec96 /src/qregisters.h | |
| parent | f9e6f8630cdb0c6d056154b82e8f94289509f48a (diff) | |
auto-completion of Q-Register names, goto labels and help topics
* Using a common implementation in RBTreeString::auto_complete().
This is very efficient even for very huge tables since only
an O(log(n)) lookup is required and then all entries with a matching
prefix are iterated. Worst-case complexity is still O(n), since all
entries may be legitimate completions.
If necessary, the number of matching entries could be restricted, though.
* Auto completes short and long Q-Reg names.
Short names are "case-insensitive" (since they are upper-cased).
Long specs are terminated with a closing bracket.
* Long spec completions may have problems with names containing
funny characters since they may be misinterpreted as string building
characters or contain braces. All the auto-completions suffered from
this problem already (see TODO).
* This greatly simplifies investigating the Q-Register name spaces
interactively and e.g. calling macros with long names, inserting
environment registers etc.
* Goto labels are terminated with commas since they may be part
of a computed goto.
* Help topics are matched case insensitive (just like the topic
lookup itself) and are terminated with the escape character.
This greatly simplifies navigating womanpages and looking up
topics with long names.
Diffstat (limited to 'src/qregisters.h')
| -rw-r--r-- | src/qregisters.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/qregisters.h b/src/qregisters.h index 1ea47ee..1d0962c 100644 --- a/src/qregisters.h +++ b/src/qregisters.h @@ -374,6 +374,12 @@ public: void update_environ(void); void clear(void); + + inline gchar * + auto_complete(const gchar *name, gchar completed = '\0', gsize max_len = 0) + { + return RBTreeString::auto_complete(name, completed, max_len); + } }; class QRegisterStack { @@ -471,6 +477,8 @@ public: { throw InvalidQRegError(name, is_local); } + + gchar *auto_complete(void); }; /* @@ -482,14 +490,19 @@ public: */ class StateExpectQReg : public State { public: + /* + * FIXME: Only public, so we can access it from + * cmdline.cpp. Will not be necessary if process_edit_cmd() + * is a State method. + */ + QRegSpecMachine machine; + StateExpectQReg(QRegSpecType type = QREG_REQUIRED); private: State *custom(gchar chr); protected: - QRegSpecMachine machine; - virtual State *got_register(QRegister *reg) = 0; }; @@ -624,6 +637,12 @@ namespace States { extern StateMacro macro; extern StateMacroFile macro_file; extern StateCopyToQReg copytoqreg; + + static inline bool + is_qreg() + { + return dynamic_cast<StateExpectQReg *>(current); + } } namespace QRegisters { |
