[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs TODO.org qeconfig.h search.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs TODO.org qeconfig.h search.c |
Date: |
Mon, 2 Jan 2017 06:30:09 -0500 (EST) |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 17/01/02 06:30:09
Modified files:
. : TODO.org qeconfig.h search.c
Log message:
search: extensions
- add `delete-matching-lines`
- move search command definitions to search.c
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/TODO.org?cvsroot=qemacs&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/qemacs/qeconfig.h?cvsroot=qemacs&r1=1.62&r2=1.63
http://cvs.savannah.gnu.org/viewcvs/qemacs/search.c?cvsroot=qemacs&r1=1.10&r2=1.11
Patches:
Index: TODO.org
===================================================================
RCS file: /sources/qemacs/qemacs/TODO.org,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- TODO.org 31 Dec 2016 11:25:25 -0000 1.20
+++ TODO.org 2 Jan 2017 11:30:09 -0000 1.21
@@ -81,7 +81,6 @@
** screen: check coordinate system to 1000 based with optional sidebars
** search: add regex support
** search: hex-mode search strings should mix hex ut8 strings and ASCII
control char names
-** search: delete-matching-lines
** search: make isearch bindings for minibuffer
** search: query replace word/case/hex toggles
** session: register session store functions
Index: qeconfig.h
===================================================================
RCS file: /sources/qemacs/qemacs/qeconfig.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -b -r1.62 -r1.63
--- qeconfig.h 31 Dec 2016 18:45:08 -0000 1.62
+++ qeconfig.h 2 Jan 2017 11:30:09 -0000 1.63
@@ -169,41 +169,6 @@
"s{Set visited file name: }[file]|file|"
"s{Rename file? }|newname|")
- /*---------------- Search and replace ----------------*/
-
- /* M-C-s should be bound to isearch-forward-regex */
- /* mg binds search-forward to M-s */
- CMD3( KEY_META('S'), KEY_NONE,
- "search-forward", do_search_string, ESsi, 1,
- "s{Search forward: }|search|"
- "v")
- /* M-C-r should be bound to isearch-backward-regex */
- /* mg binds search-forward to M-r */
- CMD3( KEY_META('R'), KEY_NONE,
- "search-backward", do_search_string, ESsi, -1,
- "s{Search backward: }|search|"
- "v")
- CMD3( KEY_META('C'), KEY_NONE,
- "count-matches", do_search_string, ESsi, 0,
- "s{Count Matches: }|search|"
- "v")
- /* passing argument should switch to regex incremental search */
- CMD3( KEY_CTRL('r'), KEY_NONE,
- "isearch-backward", do_isearch, ESii, -1, "vui" )
- CMD3( KEY_CTRL('s'), KEY_NONE,
- "isearch-forward", do_isearch, ESii, 1, "vui" )
- CMD2( KEY_META('%'), KEY_NONE,
- "query-replace", do_query_replace, ESss,
- "*" "s{Query replace: }|search|"
- "s{With: }|replace|")
- /* passing argument restricts replace to word matches */
- /* XXX: non standard binding */
- CMD2( KEY_META('r'), KEY_NONE,
- "replace-string", do_replace_string, ESssi,
- "*" "s{Replace String: }|search|"
- "s{With: }|replace|"
- "ui")
-
/*---------------- Paragraph / case handling ----------------*/
CMD0( KEY_META('h'), KEY_NONE,
Index: search.c
===================================================================
RCS file: /sources/qemacs/qemacs/search.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- search.c 31 Dec 2016 11:25:25 -0000 1.10
+++ search.c 2 Jan 2017 11:30:09 -0000 1.11
@@ -301,7 +301,7 @@
search_abort_func, NULL,
&is->found_offset, &is->found_end) > 0) {
s->region_style = QE_STYLE_SEARCH_MATCH;
- if (is->dir > 0) {
+ if (is->dir >= 0) {
s->b->mark = is->found_offset;
s->offset = is->found_end;
} else {
@@ -413,7 +413,7 @@
} else
if (is->pos < SEARCH_LENGTH) {
/* add the match position, if any */
- unsigned long v = is->dir > 0 ? FOUND_TAG : FOUND_TAG | FOUND_REV;
+ unsigned long v = (is->dir >= 0) ? FOUND_TAG : FOUND_TAG |
FOUND_REV;
if (is->found_offset < 0 && is->search_u32_len > 0) {
is->search_flags |= SEARCH_FLAG_WRAPPED;
if (is->dir < 0)
@@ -842,7 +842,7 @@
query_replace(s, search_str, replace_str, 1, flags);
}
-/* dir = 0, 1, -2 -> count matches, reverse, forward */
+/* dir = 0, -1, 1, 2 -> count matches, reverse, forward, delete-matching-lines
*/
void do_search_string(EditState *s, const char *search_str, int dir)
{
unsigned int search_u32[SEARCH_LENGTH];
@@ -868,10 +868,16 @@
offset, s->b->total_size,
search_u32, search_u32_len,
NULL, NULL, &found_offset, &found_end) > 0) {
- if (dir == 0) {
count++;
+ if (dir == 0) {
offset = found_end;
continue;
+ } else
+ if (dir == 2) {
+ offset = eb_goto_bol(s->b, found_offset);
+ eb_delete(s->b, offset,
+ eb_next_line(s->b, found_offset) - offset);
+ continue;
} else {
s->offset = (dir < 0) ? found_offset : found_end;
do_center_cursor(s, 0);
@@ -879,7 +885,10 @@
}
} else {
if (dir == 0) {
- put_status(s, "\"%s\": %d matches", search_str, count);
+ put_status(s, "%d matches", count);
+ } else
+ if (dir == 2) {
+ put_status(s, "deleted %d lines", count);
} else {
put_status(s, "Search failed: \"%s\"", search_str);
}
@@ -887,3 +896,54 @@
}
}
}
+
+static CmdDef search_commands[] = {
+
+ /*---------------- Search and replace ----------------*/
+
+ /* M-C-s should be bound to isearch-forward-regex */
+ /* mg binds search-forward to M-s */
+ CMD3( KEY_META('S'), KEY_NONE,
+ "search-forward", do_search_string, ESsi, 1,
+ "s{Search forward: }|search|"
+ "v")
+ /* M-C-r should be bound to isearch-backward-regex */
+ /* mg binds search-forward to M-r */
+ CMD3( KEY_META('R'), KEY_NONE,
+ "search-backward", do_search_string, ESsi, -1,
+ "s{Search backward: }|search|"
+ "v")
+ CMD3( KEY_META('C'), KEY_NONE,
+ "count-matches", do_search_string, ESsi, 0,
+ "s{Count Matches: }|search|"
+ "v")
+ CMD3( KEY_NONE, KEY_NONE,
+ "delete-matching-lines", do_search_string, ESsi, 2,
+ "s{Delete lines containing: }|search|"
+ "v")
+ /* passing argument should switch to regex incremental search */
+ CMD3( KEY_CTRL('r'), KEY_NONE,
+ "isearch-backward", do_isearch, ESii, -1, "vui" )
+ CMD3( KEY_CTRL('s'), KEY_NONE,
+ "isearch-forward", do_isearch, ESii, 1, "vui" )
+ CMD2( KEY_META('%'), KEY_NONE,
+ "query-replace", do_query_replace, ESss,
+ "*" "s{Query replace: }|search|"
+ "s{With: }|replace|")
+ /* passing argument restricts replace to word matches */
+ /* XXX: non standard binding */
+ CMD2( KEY_META('r'), KEY_NONE,
+ "replace-string", do_replace_string, ESssi,
+ "*" "s{Replace String: }|search|"
+ "s{With: }|replace|"
+ "ui")
+
+ CMD_DEF_END,
+};
+
+static int search_init(void) {
+ qe_register_cmd_table(search_commands, NULL);
+ return 0;
+}
+
+qe_module_init(search_init);
- [Qemacs-commit] qemacs TODO.org qeconfig.h search.c,
Charlie Gordon <=