[gnome-builder] buffer: add helper to get word at iter location
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] buffer: add helper to get word at iter location
- Date: Thu, 16 Jul 2015 21:10:58 +0000 (UTC)
commit 4b35f0e8374d75f84495a798b5d0b36584112be2
Author: Christian Hergert <christian hergert me>
Date: Thu Jul 16 13:31:59 2015 -0700
buffer: add helper to get word at iter location
This uses pango natural words, extended to support _ as well. Convenient
to get current function or variable name.
libide/ide-buffer.c | 29 +++++++++++++++++++++++++++++
libide/ide-buffer.h | 2 ++
2 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-buffer.c b/libide/ide-buffer.c
index 1cc4599..f88d534 100644
--- a/libide/ide-buffer.c
+++ b/libide/ide-buffer.c
@@ -37,6 +37,7 @@
#include "ide-highlighter.h"
#include "ide-highlight-engine.h"
#include "ide-internal.h"
+#include "ide-source-iter.h"
#include "ide-source-location.h"
#include "ide-source-range.h"
#include "ide-symbol.h"
@@ -2139,3 +2140,31 @@ ide_buffer_get_symbol_resolver (IdeBuffer *self)
return NULL;
}
+
+/**
+ * ide_buffer_get_word_at_iter:
+ *
+ * Gets the word found under the position denoted by @iter.
+ *
+ * Returns: (transfer full): A newly allocated string.
+ */
+gchar *
+ide_buffer_get_word_at_iter (IdeBuffer *self,
+ const GtkTextIter *iter)
+{
+ GtkTextIter begin;
+ GtkTextIter end;
+
+ g_return_val_if_fail (IDE_IS_BUFFER (self), NULL);
+ g_return_val_if_fail (iter != NULL, NULL);
+
+ end = begin = *iter;
+
+ if (!_ide_source_iter_starts_word (&begin))
+ _ide_source_iter_backward_extra_natural_word_start (&begin);
+
+ if (!_ide_source_iter_ends_word (&end))
+ _ide_source_iter_forward_extra_natural_word_end (&end);
+
+ return gtk_text_iter_get_slice (&begin, &end);
+}
diff --git a/libide/ide-buffer.h b/libide/ide-buffer.h
index 3ffb410..bce4e29 100644
--- a/libide/ide-buffer.h
+++ b/libide/ide-buffer.h
@@ -88,6 +88,8 @@ IdeSymbol *ide_buffer_get_symbol_at_location_finish (IdeBuffer
GError **error);
void ide_buffer_hold (IdeBuffer *self);
void ide_buffer_release (IdeBuffer *self);
+gchar *ide_buffer_get_word_at_iter (IdeBuffer *self,
+ const GtkTextIter *iter);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]