aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmdline.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-24 19:57:07 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-24 19:57:07 +0100
commit71f84c2ca051fb3f4e0e98faaba05e9449598b81 (patch)
treecdcf22acae633132c2690c9c4035be915760a450 /cmdline.cpp
parent2add69b7f08f19ae2687276ebafcf6989915aa69 (diff)
downloadsciteco-71f84c2ca051fb3f4e0e98faaba05e9449598b81.tar.gz
support auto-completion of symbols in the scintilla command (ES)
* does not yet handle case-insensitive completions * does not handle omitting of the SCI_ prefix
Diffstat (limited to 'cmdline.cpp')
-rw-r--r--cmdline.cpp79
1 files changed, 69 insertions, 10 deletions
diff --git a/cmdline.cpp b/cmdline.cpp
index fd37650..674000b 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -12,10 +12,14 @@
#include "qbuffers.h"
#include "goto.h"
#include "undo.h"
+#include "symbols.h"
static inline const gchar *process_edit_cmd(gchar key);
static gchar *macro_echo(const gchar *macro);
+
static gchar *filename_complete(const gchar *filename, gchar completed = ' ');
+static gchar *symbol_complete(SymbolList &list, const gchar *symbol,
+ gchar completed = ' ');
static const gchar *last_occurrence(const gchar *str,
const gchar *chars = " \t\v\r\n\f<>,;@");
@@ -118,7 +122,25 @@ process_edit_cmd(gchar key)
if (States::current == &States::editfile ||
States::current == &States::savefile ||
States::current == &States::loadqreg) {
- gchar *new_chars = filename_complete(strings[0], escape_char);
+ gchar *new_chars = filename_complete(strings[0],
+ escape_char);
+ if (new_chars)
+ g_stpcpy(insert, new_chars);
+ g_free(new_chars);
+ } else if (States::current == &States::scintilla_symbols) {
+ const gchar *symbol = NULL;
+ SymbolList &list = Symbols::scintilla;
+ gchar *new_chars;
+
+ if (strings[0]) {
+ symbol = last_occurrence(strings[0], ",");
+ if (*symbol == ',') {
+ symbol++;
+ list = Symbols::scilexer;
+ }
+ }
+
+ new_chars = symbol_complete(list, symbol, ',');
if (new_chars)
g_stpcpy(insert, new_chars);
g_free(new_chars);
@@ -255,7 +277,7 @@ filename_complete(const gchar *filename, gchar completed)
for (GList *file = g_list_first(matching);
file != NULL;
file = g_list_next(file)) {
- Interface::PopupFileType type;
+ Interface::PopupEntryType type;
bool in_buffer = false;
if (filename_is_dir((gchar *)file->data)) {
@@ -266,19 +288,14 @@ filename_complete(const gchar *filename, gchar completed)
in_buffer = ring.find((gchar *)file->data);
}
- interface.popup_add_filename(type, (gchar *)file->data,
- in_buffer);
+ interface.popup_add(type, (gchar *)file->data,
+ in_buffer);
}
interface.popup_show();
} else if (g_list_length(matching) == 1 &&
!filename_is_dir((gchar *)g_list_first(matching)->data)) {
- gchar *new_insert;
-
- new_insert = g_strconcat(insert ? : "",
- (gchar []){completed, '\0'}, NULL);
- g_free(insert);
- insert = new_insert;
+ String::append(insert, completed);
}
g_completion_free(completion);
@@ -290,6 +307,48 @@ filename_complete(const gchar *filename, gchar completed)
return insert;
}
+static gchar *
+symbol_complete(SymbolList &list, const gchar *symbol, gchar completed)
+{
+ GList *glist;
+ GList *matching;
+ GCompletion *completion;
+ gchar *new_prefix;
+ gchar *insert = NULL;
+
+ if (!symbol)
+ symbol = "";
+
+ glist = list.get_glist();
+ if (!glist)
+ return NULL;
+
+ completion = g_completion_new(NULL);
+ g_completion_add_items(completion, glist);
+
+ matching = g_completion_complete(completion, symbol, &new_prefix);
+ if (new_prefix && strlen(new_prefix) > strlen(symbol))
+ insert = g_strdup(new_prefix + strlen(symbol));
+ g_free(new_prefix);
+
+ if (!insert && g_list_length(matching) > 1) {
+ for (GList *entry = g_list_first(matching);
+ entry != NULL;
+ entry = g_list_next(entry)) {
+ interface.popup_add(Interface::POPUP_PLAIN,
+ (gchar *)entry->data);
+ }
+
+ interface.popup_show();
+ } else if (g_list_length(matching) == 1) {
+ String::append(insert, completed);
+ }
+
+ g_completion_free(completion);
+
+ return insert;
+}
+
/*
* Auxiliary functions
*/