Hi Geany developers.

First off, I've been using Geany for years now. I just love it. Thanks
for making it <3.

I'm a newcomer (you probably noticed). I have a patch for Geany to
submit to you.
As I regularly use the search window and the results to locate matches,
I wished
the results highlighted matches. I couldn't find how to change the font
(bold or italic)
so I went for something simpler.

This patch surrounds matches in each result line with right/left
pointing thumbs. I have
to admit this is really good enough to me as, with time, I started to
squint to find where
in the results the search pattern lies. I hope you find it useful. I've
already applied and
tested it with the version of Geany installed on my machine (Gentoo) —
FYI Gentoo
provides out-of-the-tree patching features without resorting to overlays.

Note however I didn't go as far as detecting regular expression
sub-matches. Only the
text delimited by the "start" and "end" fields of the "GeanyMatchInfo"
structure are
taken into account — which was sufficient to cover all the cases I need.
IMHO adding
more symbols is likely to clutter the result lines more than necessary.

Here's what a search line looks like ("gint" is the search pattern):

    sciwrappers.c:207: return (☛gint☚) SSM(sci, SCI_GETEOLMODE, 0, 0);

FTR I have selected filled thumbs instead of the empty ones (U+261E,
U+261C) for
maximum contrast.

Greetings,
Vince C.
>From c17ea16c3556ba116764df48bc3b57a46d8ce272 Mon Sep 17 00:00:00 2001
From: Vince C <vi...@users.sf.net>
Date: Mon, 10 Sep 2018 10:02:23 +0200
Subject: [PATCH] search.c: Highlight searches

Ideally matched terms in the message window would be coloured
or emphasized using current font attributes (e.g. bold, italic...) This
patch surrounds matched terms with unicode symbols (right and left
pointing thumbs, respectively U+216B and U+261A).
---
 src/search.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/search.c b/src/search.c
index e56be7016..72cafec7f 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2146,7 +2146,7 @@ gint search_find_text(ScintillaObject *sci, GeanyFindFlags flags, struct Sci_Tex
 
 static gint find_document_usage(GeanyDocument *doc, const gchar *search_text, GeanyFindFlags flags)
 {
-	gchar *buffer, *short_file_name;
+	gchar *line_text, *buffer, *short_file_name;
 	struct Sci_TextToFind ttf;
 	gint count = 0;
 	gint prev_line = -1;
@@ -2166,9 +2166,21 @@ static gint find_document_usage(GeanyDocument *doc, const gchar *search_text, Ge
 		GeanyMatchInfo *info = match->data;
 		gint line = sci_get_line_from_position(doc->editor->sci, info->start);
 
+		/* Surround matches with some distinctive symbols.
+		 * Note: assume match is a non-empty string. */
+		gint line_position = sci_get_position_from_line(doc->editor->sci, line);
+		gint start = info->start - line_position;
+		gint end = info->end - line_position;
+
 		if (line != prev_line)
 		{
-			buffer = sci_get_line(doc->editor->sci, line);
+			line_text = sci_get_line(doc->editor->sci, line);
+			buffer = g_strdup_printf("%.*s\u261b%.*s\u261a%s",
+				start, line_text,
+				end - start, &line_text[start],
+				&line_text[end]);
+			g_free(line_text);
+
 			msgwin_msg_add(COLOR_BLACK, line + 1, doc,
 				"%s:%d: %s", short_file_name, line + 1, g_strstrip(buffer));
 			g_free(buffer);
-- 
2.16.4

_______________________________________________
Devel mailing list
Devel@lists.geany.org
https://lists.geany.org/cgi-bin/mailman/listinfo/devel

Reply via email to