[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master c5f9ccf 4/6: * lisp/isearch.el: Generalize definiti
From: |
Artur Malabarba |
Subject: |
[Emacs-diffs] master c5f9ccf 4/6: * lisp/isearch.el: Generalize definition of regexp-function toggles |
Date: |
Sun, 25 Oct 2015 01:16:24 +0000 |
branch: master
commit c5f9ccfce272e06be568182c2c088f628add4eaf
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>
* lisp/isearch.el: Generalize definition of regexp-function toggles
(isearch-specify-regexp-function): New macro for specifying
possible values of `isearch-regexp-function'.
(isearch-toggle-character-fold, isearch-toggle-symbol)
(isearch-toggle-word): Define with `isearch-specify-regexp-function'.
---
lisp/isearch.el | 63 +++++++++++++++++++++++++-----------------------------
1 files changed, 29 insertions(+), 34 deletions(-)
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 1386473..2c031aa 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -521,10 +521,8 @@ This is like `describe-bindings', but displays only
Isearch keys."
(define-key map "\M-sc" 'isearch-toggle-case-fold)
(define-key map "\M-si" 'isearch-toggle-invisible)
(define-key map "\M-sr" 'isearch-toggle-regexp)
- (define-key map "\M-sw" 'isearch-toggle-word)
- (define-key map "\M-s_" 'isearch-toggle-symbol)
(define-key map "\M-s " 'isearch-toggle-lax-whitespace)
- (define-key map "\M-s'" #'isearch-toggle-character-fold)
+ ;; More toggles defined by `isearch-specify-regexp-function'.
(define-key map [?\M-%] 'isearch-query-replace)
(define-key map [?\C-\M-%] 'isearch-query-replace-regexp)
@@ -845,7 +843,6 @@ See the command `isearch-forward-symbol' for more
information."
;; "List of commands for which isearch-mode does not recursive-edit.")
(autoload 'character-fold-to-regexp "character-fold")
-(put 'character-fold-to-regexp 'isearch-message-prefix "char-fold ")
(defun isearch-mode (forward &optional regexp op-fun recursive-edit
regexp-function)
"Start Isearch minor mode.
@@ -1506,36 +1503,34 @@ Use `isearch-exit' to quit without signaling."
(setq isearch-success t isearch-adjusted t)
(isearch-update))
-(defun isearch-toggle-word ()
- "Toggle word searching on or off."
- ;; The status stack is left unchanged.
- (interactive)
- (setq isearch-regexp-function
- (if (memq isearch-regexp-function '(t word-search-regexp))
- nil #'word-search-regexp))
- (when isearch-regexp-function (setq isearch-regexp nil))
- (setq isearch-success t isearch-adjusted t)
- (isearch-update))
-
-(defun isearch-toggle-symbol ()
- "Toggle symbol searching on or off."
- (interactive)
- (setq isearch-regexp-function
- (unless (eq isearch-regexp-function #'isearch-symbol-regexp)
- 'isearch-symbol-regexp))
- (when isearch-regexp-function (setq isearch-regexp nil))
- (setq isearch-success t isearch-adjusted t)
- (isearch-update))
-
-(defun isearch-toggle-character-fold ()
- "Toggle character folding in searching on or off."
- (interactive)
- (setq isearch-regexp-function
- (unless (eq isearch-regexp-function #'character-fold-to-regexp)
- #'character-fold-to-regexp))
- (when isearch-regexp-function (setq isearch-regexp nil))
- (setq isearch-success t isearch-adjusted t)
- (isearch-update))
+;;; Toggles for `isearch-regexp-function' and `search-default-regexp-mode'.
+(defmacro isearch-specify-regexp-function (mode function key)
+ "Define a search MODE in which `isearch-regexp-function' is set to FUNCTION.
+Define a command called `isearch-toggle-MODE' and bind it to
+`isearch-mode-map' under `M-s KEY'.
+Also set the `isearch-message-prefix' property of FUNCTION."
+ (let ((command-name (intern (format "isearch-toggle-%s" mode))))
+ `(progn
+ (defun ,command-name ()
+ ,(format "Toggle %s searching on or off." mode)
+ (interactive)
+ (setq isearch-regexp-function
+ (unless (eq isearch-regexp-function #',function)
+ #',function))
+ (when isearch-regexp-function (setq isearch-regexp nil))
+ (setq isearch-success t isearch-adjusted t)
+ (isearch-update))
+ (define-key isearch-mode-map ,(concat "\M-s" key) #',command-name)
+ (put ',function 'isearch-message-prefix ,(format "%s " mode))
+ (cl-callf (lambda (types) (cons 'choice
+ (cons '(const :tag ,(capitalize (format "%s
search" mode)) ,function)
+ (cdr types))))
+ (get 'search-default-regexp-mode 'custom-type)))))
+
+(isearch-specify-regexp-function word word-search-regexp "w")
+(isearch-specify-regexp-function symbol isearch-symbol-regexp "_")
+(isearch-specify-regexp-function character-fold character-fold-to-regexp "'")
+(put 'character-fold-to-regexp 'isearch-message-prefix "char-fold ")
(defun isearch-toggle-lax-whitespace ()
"Toggle whitespace matching in searching on or off.
- [Emacs-diffs] master updated (b6c6629 -> 816f78c), Artur Malabarba, 2015/10/24
- [Emacs-diffs] master 79fac08 1/6: * lisp/custom.el (custom-declare-variable): Shorten code a bit, Artur Malabarba, 2015/10/24
- [Emacs-diffs] master cfd9ef5 3/6: * lisp/isearch.el (search-default-regexp-mode): New variable, Artur Malabarba, 2015/10/24
- [Emacs-diffs] master c5f9ccf 4/6: * lisp/isearch.el: Generalize definition of regexp-function toggles,
Artur Malabarba <=
- [Emacs-diffs] master fa647ec 2/6: * lisp/isearch.el: Delete redundant :group entries, Artur Malabarba, 2015/10/24
- [Emacs-diffs] master 816f78c 6/6: * lisp/isearch.el: Make character-fold search the default again, Artur Malabarba, 2015/10/24
- [Emacs-diffs] master f5f18f9 5/6: * lisp/character-fold.el: Many improvements, Artur Malabarba, 2015/10/24