From 8f4be27dca714b168414171bde3eeee9fefc44e9 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 27 Jan 2015 14:08:01 -0200 Subject: [PATCH] (isearch-search-fun-default): Implement group folding in isearch. (isearch-fold-groups group-fold-table): New variables. When `isearch-fold-groups' is non-nil `group-fold-table' is used as the case table. --- lisp/isearch.el | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lisp/isearch.el b/lisp/isearch.el index 99ca73f..7d568dd 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -272,6 +272,38 @@ Default value, nil, means edit the string instead." :version "23.1" :group 'isearch) +(defcustom isearch-fold-groups t + "Whether regular isearch should do group folding. +This means some characters will match entire groups of charactes, +such as \" matching ”, for instance." + :type 'boolean + :group 'isearch + :version "25.1") + +(defvar group-fold-table + (eval-when-compile + (let ((table (make-char-table 'case-table)) + (eq (make-char-table 'equiv))) + (require 'subr-x) + ;; Build the group table. + (dotimes (i (length eq)) + (when-let ((d (get-char-code-property i 'decomposition)) + (k (car-safe d))) + (unless (eq i k) + (aset eq i (if (characterp k) k (cadr d)))))) + ;; Put it in the right place. + (set-char-table-extra-slot table 1 eq) + table)) + "Used for folding characters of the same group during search.") + +(defmacro with-group-folding (&rest body) + "Execute BODY with character-group folding turned on. +This sets `group-fold-table' as the case-table during the +execution of BODY." + `(let ((case-fold-search t)) + (with-case-table group-fold-table + ,@body))) + (defcustom isearch-lazy-highlight t "Controls the lazy-highlighting during incremental search. When non-nil, all text in the buffer matching the current search @@ -2568,6 +2600,12 @@ Can be changed via `isearch-search-fun-function' for special needs." (defun isearch-search-fun-default () "Return default functions to use for the search." (cond + (isearch-fold-groups + (lambda (&rest args) + (let* ((isearch-fold-groups nil) + (function (isearch-search-fun-default))) + (with-group-folding + (apply function args))))) (isearch-word (lambda (string &optional bound noerror count) ;; Use lax versions to not fail at the end of the word while -- 2.2.2