Re: Case-insensitive search
Darcy Shen <[email protected]>
| Newsgroups | gmane.editors.texmacs.devel |
|---|---|
| Message-ID | <[email protected]> |
https://github.com/texmacs/texmacs/pull/4 Thanks for your Pull Request. I hope the github GNU TeXmacs group will make it easy for contributors to submit patches. ---- On Fri, 16 Feb 2018 06:14:06 +0800 Marduk Bolaños <[email protected]> wrote ---- Dear all, I have long wanted to implement a feature that is incredibly missing in TeXmacs: case-insensitive search. Below you will find the patches that implement it. Please test it extensively and if it is good to go, it must be included in TeXmacs. Best regards, Marduk PS There is a new preference in the Other tab that toggles case sensitivity. git-diff-c.patch ----------------- diff --git a/TeXmacs-git/texmacs/src/src/Data/Tree/tree_search.cpp b/texmacs/src/src/Data/Tree/tree_search.cpp index 26df0cb..b2bef95 100644 --- a/TeXmacs-git/texmacs/src/src/Data/Tree/tree_search.cpp +++ b/texmacs/src/src/Data/Tree/tree_search.cpp @@ -13,6 +13,7 @@ #include "analyze.hpp" #include "boot.hpp" #include "drd_mode.hpp" +#include <locale> int search_max_hits= 1000000; bool blank_match_flag= false; @@ -20,6 +21,7 @@ bool initial_match_flag= false; bool partial_match_flag= false; bool injective_match_flag= false; bool cascaded_match_flag= false; +bool case_insensitive_match_flag= false; void search (range_set& sel, tree t, tree what, path p); bool match (tree t, tree what); @@ -46,6 +48,8 @@ initialize_search () { (get_user_preference ("allow-injective-match", "on") == "on"); cascaded_match_flag= (get_user_preference ("allow-cascaded-match", "on") == "on"); + case_insensitive_match_flag= + (get_user_preference ("case-insensitive-match", "off") == "on"); } static void @@ -234,11 +238,21 @@ search_concat (tree t, tree what, int pos, int i, void search_string (range_set& sel, string s, tree what, path p) { + + string source = string(N(s)); + + if (case_insensitive_match_flag){ + for (int i = 0; i < N(s); i++) + source[i] = std::tolower(s[i]); + } else { + source = s; + } + if (is_atomic (what)) { string w= what->label; int pos= 0; while (pos < N(s)) { - int next= tm_search_forwards (w, pos, s); + int next= tm_search_forwards (w, pos, source); if (next < 0 || next >= N(s)) break; merge (sel, simple_range (p * next, p * (next + N(w)))); pos= next + N(w); git-diff-scheme.patch ---------------------- diff --git a/TeXmacs-git/texmacs/src/TeXmacs/progs/generic/generic-widgets.scm b/texmacs/src/TeXmacs/progs/generic/generic-widgets.scm index 7214e5c..adf34d9 100644 --- a/TeXmacs-git/texmacs/src/TeXmacs/progs/generic/generic-widgets.scm +++ b/texmacs/src/TeXmacs/progs/generic/generic-widgets.scm @@ -482,10 +482,12 @@ (define (search-toolbar-search what) (let* ((u (current-buffer)) - (aux (search-buffer))) + (aux (search-buffer)) + (what-case (if (get-boolean-preference "case-insensitive-match") + (string-downcase what) what))) (set-search-reference (cursor-path)) (set-search-filter) - (buffer-set-body aux `(document ,what)) + (buffer-set-body aux `(document ,what-case)) (buffer-set-master aux u) (set! search-window (current-window)) (perform-search))) diff --git a/../TeXmacs-git/texmacs/src/TeXmacs/progs/texmacs/menus/preferences-widgets.scm b/texmacs/src/TeXmacs/progs/texmacs/menus/preferences-widgets.scm index 360f4bb..bc86cb6 100644 --- a/TeXmacs-git/texmacs/src/TeXmacs/progs/texmacs/menus/preferences-widgets.scm +++ b/texmacs/src/TeXmacs/progs/texmacs/menus/preferences-widgets.scm @@ -656,6 +656,9 @@ (meti (hlist // (text "Program bracket selections")) (toggle (set-boolean-preference "prog:select brackets" answer) (get-boolean-preference "prog:select brackets"))) + (meti (hlist // (text "Case-insensitive search")) + (toggle (set-boolean-preference "case-insensitive-match" answer) + (get-boolean-preference "case-insensitive-match"))) (assuming (qt-gui?) ; TODO: recode the dialogue in scheme (meti (hlist // (text "Use print dialogue")) (toggle (set-boolean-preference "gui:print dialogue" answer) _______________________________________________ Texmacs-dev mailing list mailto:[email protected] https://lists.gnu.org/mailman/listinfo/texmacs-dev _______________________________________________ Texmacs-dev mailing list [email protected] https://lists.gnu.org/mailman/listinfo/texmacs-dev