Kaydet (Commit) 593b9dd2 authored tarafından Colomban Wendling's avatar Colomban Wendling

Merge branch 'single-line-regex'

...@@ -1231,6 +1231,10 @@ The syntax for the *Use regular expressions* option is shown in ...@@ -1231,6 +1231,10 @@ The syntax for the *Use regular expressions* option is shown in
.. note:: .. note::
*Use escape sequences* is implied for regular expressions. *Use escape sequences* is implied for regular expressions.
The *Use multi-line matching* option enables multi-line regular
expressions instead of single-line ones. See `Regular expressions`_ for
more details on the differences between the two modes.
The *Use escape sequences* option will transform any escaped characters The *Use escape sequences* option will transform any escaped characters
into their UTF-8 equivalent. For example, \\t will be transformed into into their UTF-8 equivalent. For example, \\t will be transformed into
a tab character. Other recognized symbols are: \\\\, \\n, \\r, \\uXXXX a tab character. Other recognized symbols are: \\\\, \\n, \\r, \\uXXXX
...@@ -1451,10 +1455,17 @@ options`_). The syntax is Perl compatible. Basic syntax is described ...@@ -1451,10 +1455,17 @@ options`_). The syntax is Perl compatible. Basic syntax is described
in the table below. For full details, see in the table below. For full details, see
http://www.geany.org/manual/gtk/glib/glib-regex-syntax.html. http://www.geany.org/manual/gtk/glib/glib-regex-syntax.html.
By default regular expressions are matched on a line-by-line basis.
If you are interested in multi-line regular expressions, matched against
the whole buffer at once, see the section `Multi-line regular expressions`_
below.
.. note:: .. note::
1. The *Use escape sequences* dialog option always applies for regular 1. The *Use escape sequences* dialog option always applies for regular
expressions. expressions.
2. Searching backwards with regular expressions is not supported. 2. Searching backwards with regular expressions is not supported.
3. The *Use multi-line matching* dialog option to select single or
multi-line matching.
**In a regular expression, the following characters are interpreted:** **In a regular expression, the following characters are interpreted:**
...@@ -1531,6 +1542,30 @@ $ This matches the end of a line. ...@@ -1531,6 +1542,30 @@ $ This matches the end of a line.
distributed under the `License for Scintilla and SciTE`_. distributed under the `License for Scintilla and SciTE`_.
Multi-line regular expressions
``````````````````````````````
.. note::
The *Use multi-line matching* dialog option enables multi-line
regular expressions.
Multi-line regular expressions work just like single-line ones but a
match can span several lines.
While the syntax is the same, a few practical differences applies:
======= ============================================================
. Matches any character but newlines. This behavior can be changed
to also match newlines using the (?s) option, see
http://www.geany.org/manual/gtk/glib/glib-regex-syntax.html#idp5671632
[^...] A negative range (see above) *will* match newlines if they are
not explicitly listed in that negative range. For example, range
[^a-z] will match newlines, while range [^a-z\\r\\n] won't.
While this is the expected behavior, it can lead to tricky
problems if one doesn't think about it when writing an expression.
======= ============================================================
View menu View menu
--------- ---------
......
...@@ -837,14 +837,14 @@ static void find_usage(gboolean in_session) ...@@ -837,14 +837,14 @@ static void find_usage(gboolean in_session)
if (sci_has_selection(doc->editor->sci)) if (sci_has_selection(doc->editor->sci))
{ /* take selected text if there is a selection */ { /* take selected text if there is a selection */
search_text = sci_get_selection_contents(doc->editor->sci); search_text = sci_get_selection_contents(doc->editor->sci);
flags = SCFIND_MATCHCASE; flags = GEANY_FIND_MATCHCASE;
} }
else else
{ {
editor_find_current_word_sciwc(doc->editor, -1, editor_find_current_word_sciwc(doc->editor, -1,
editor_info.current_word, GEANY_MAX_WORD_LENGTH); editor_info.current_word, GEANY_MAX_WORD_LENGTH);
search_text = g_strdup(editor_info.current_word); search_text = g_strdup(editor_info.current_word);
flags = SCFIND_MATCHCASE | SCFIND_WHOLEWORD; flags = GEANY_FIND_MATCHCASE | GEANY_FIND_WHOLEWORD;
} }
search_find_usage(search_text, search_text, flags, in_session); search_find_usage(search_text, search_text, flags, in_session);
...@@ -934,7 +934,7 @@ G_MODULE_EXPORT void on_find_next1_activate(GtkMenuItem *menuitem, gpointer user ...@@ -934,7 +934,7 @@ G_MODULE_EXPORT void on_find_next1_activate(GtkMenuItem *menuitem, gpointer user
G_MODULE_EXPORT void on_find_previous1_activate(GtkMenuItem *menuitem, gpointer user_data) G_MODULE_EXPORT void on_find_previous1_activate(GtkMenuItem *menuitem, gpointer user_data)
{ {
if (search_data.flags & SCFIND_REGEXP) if (search_data.flags & GEANY_FIND_REGEXP)
/* Can't reverse search order for a regex (find next ignores search backwards) */ /* Can't reverse search order for a regex (find next ignores search backwards) */
utils_beep(); utils_beep();
else else
......
...@@ -1491,7 +1491,7 @@ static void replace_header_filename(GeanyDocument *doc) ...@@ -1491,7 +1491,7 @@ static void replace_header_filename(GeanyDocument *doc)
ttf.chrg.cpMax = sci_get_position_from_line(doc->editor->sci, 4); ttf.chrg.cpMax = sci_get_position_from_line(doc->editor->sci, 4);
ttf.lpstrText = filebase; ttf.lpstrText = filebase;
if (search_find_text(doc->editor->sci, SCFIND_MATCHCASE | SCFIND_REGEXP, &ttf, NULL) != -1) if (search_find_text(doc->editor->sci, GEANY_FIND_MATCHCASE | GEANY_FIND_REGEXP, &ttf, NULL) != -1)
{ {
sci_set_target_start(doc->editor->sci, ttf.chrgText.cpMin); sci_set_target_start(doc->editor->sci, ttf.chrgText.cpMin);
sci_set_target_end(doc->editor->sci, ttf.chrgText.cpMax); sci_set_target_end(doc->editor->sci, ttf.chrgText.cpMax);
...@@ -2043,7 +2043,7 @@ gint document_find_text(GeanyDocument *doc, const gchar *text, const gchar *orig ...@@ -2043,7 +2043,7 @@ gint document_find_text(GeanyDocument *doc, const gchar *text, const gchar *orig
return -1; return -1;
/* Sci doesn't support searching backwards with a regex */ /* Sci doesn't support searching backwards with a regex */
if (flags & SCFIND_REGEXP) if (flags & GEANY_FIND_REGEXP)
search_backwards = FALSE; search_backwards = FALSE;
if (!original_text) if (!original_text)
...@@ -2124,7 +2124,7 @@ gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gch ...@@ -2124,7 +2124,7 @@ gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gch
return -1; return -1;
/* Sci doesn't support searching backwards with a regex */ /* Sci doesn't support searching backwards with a regex */
if (flags & SCFIND_REGEXP) if (flags & GEANY_FIND_REGEXP)
search_backwards = FALSE; search_backwards = FALSE;
if (!original_find_text) if (!original_find_text)
......
...@@ -1466,9 +1466,9 @@ static gboolean cb_func_search_action(guint key_id) ...@@ -1466,9 +1466,9 @@ static gboolean cb_func_search_action(guint key_id)
text = get_current_word_or_sel(doc, TRUE); text = get_current_word_or_sel(doc, TRUE);
if (sci_has_selection(sci)) if (sci_has_selection(sci))
search_mark_all(doc, text, SCFIND_MATCHCASE); search_mark_all(doc, text, GEANY_FIND_MATCHCASE);
else else
search_mark_all(doc, text, SCFIND_MATCHCASE | SCFIND_WHOLEWORD); search_mark_all(doc, text, GEANY_FIND_MATCHCASE | GEANY_FIND_WHOLEWORD);
g_free(text); g_free(text);
break; break;
......
This diff is collapsed.
...@@ -61,6 +61,15 @@ enum GeanyFindSelOptions ...@@ -61,6 +61,15 @@ enum GeanyFindSelOptions
GEANY_FIND_SEL_AGAIN GEANY_FIND_SEL_AGAIN
}; };
enum GeanyFindFlags
{
GEANY_FIND_MATCHCASE = 1 << 0,
GEANY_FIND_WHOLEWORD = 1 << 1,
GEANY_FIND_WORDSTART = 1 << 2,
GEANY_FIND_REGEXP = 1 << 3,
GEANY_FIND_MULTILINE = 1 << 4
};
/** Search preferences */ /** Search preferences */
typedef struct GeanySearchPrefs typedef struct GeanySearchPrefs
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment