aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2015-10-25 01:31:04 +0100
committerArtur Malabarba2015-10-25 01:11:59 +0000
commitc5f9ccfce272e06be568182c2c088f628add4eaf (patch)
treefaa3978cc176904033f359ef6fc1facf3e3adb4a
parentcfd9ef52b2adbb38d9ca84d2088a735e9e69dc40 (diff)
downloademacs-c5f9ccfce272e06be568182c2c088f628add4eaf.tar.gz
emacs-c5f9ccfce272e06be568182c2c088f628add4eaf.zip
* 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'.
-rw-r--r--lisp/isearch.el63
1 files changed, 29 insertions, 34 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 13864733804..2c031aa582a 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -521,10 +521,8 @@ This is like `describe-bindings', but displays only Isearch keys."
521 (define-key map "\M-sc" 'isearch-toggle-case-fold) 521 (define-key map "\M-sc" 'isearch-toggle-case-fold)
522 (define-key map "\M-si" 'isearch-toggle-invisible) 522 (define-key map "\M-si" 'isearch-toggle-invisible)
523 (define-key map "\M-sr" 'isearch-toggle-regexp) 523 (define-key map "\M-sr" 'isearch-toggle-regexp)
524 (define-key map "\M-sw" 'isearch-toggle-word)
525 (define-key map "\M-s_" 'isearch-toggle-symbol)
526 (define-key map "\M-s " 'isearch-toggle-lax-whitespace) 524 (define-key map "\M-s " 'isearch-toggle-lax-whitespace)
527 (define-key map "\M-s'" #'isearch-toggle-character-fold) 525 ;; More toggles defined by `isearch-specify-regexp-function'.
528 526
529 (define-key map [?\M-%] 'isearch-query-replace) 527 (define-key map [?\M-%] 'isearch-query-replace)
530 (define-key map [?\C-\M-%] 'isearch-query-replace-regexp) 528 (define-key map [?\C-\M-%] 'isearch-query-replace-regexp)
@@ -845,7 +843,6 @@ See the command `isearch-forward-symbol' for more information."
845;; "List of commands for which isearch-mode does not recursive-edit.") 843;; "List of commands for which isearch-mode does not recursive-edit.")
846 844
847(autoload 'character-fold-to-regexp "character-fold") 845(autoload 'character-fold-to-regexp "character-fold")
848(put 'character-fold-to-regexp 'isearch-message-prefix "char-fold ")
849 846
850(defun isearch-mode (forward &optional regexp op-fun recursive-edit regexp-function) 847(defun isearch-mode (forward &optional regexp op-fun recursive-edit regexp-function)
851 "Start Isearch minor mode. 848 "Start Isearch minor mode.
@@ -1506,36 +1503,34 @@ Use `isearch-exit' to quit without signaling."
1506 (setq isearch-success t isearch-adjusted t) 1503 (setq isearch-success t isearch-adjusted t)
1507 (isearch-update)) 1504 (isearch-update))
1508 1505
1509(defun isearch-toggle-word () 1506;;; Toggles for `isearch-regexp-function' and `search-default-regexp-mode'.
1510 "Toggle word searching on or off." 1507(defmacro isearch-specify-regexp-function (mode function key)
1511 ;; The status stack is left unchanged. 1508 "Define a search MODE in which `isearch-regexp-function' is set to FUNCTION.
1512 (interactive) 1509Define a command called `isearch-toggle-MODE' and bind it to
1513 (setq isearch-regexp-function 1510`isearch-mode-map' under `M-s KEY'.
1514 (if (memq isearch-regexp-function '(t word-search-regexp)) 1511Also set the `isearch-message-prefix' property of FUNCTION."
1515 nil #'word-search-regexp)) 1512 (let ((command-name (intern (format "isearch-toggle-%s" mode))))
1516 (when isearch-regexp-function (setq isearch-regexp nil)) 1513 `(progn
1517 (setq isearch-success t isearch-adjusted t) 1514 (defun ,command-name ()
1518 (isearch-update)) 1515 ,(format "Toggle %s searching on or off." mode)
1519 1516 (interactive)
1520(defun isearch-toggle-symbol () 1517 (setq isearch-regexp-function
1521 "Toggle symbol searching on or off." 1518 (unless (eq isearch-regexp-function #',function)
1522 (interactive) 1519 #',function))
1523 (setq isearch-regexp-function 1520 (when isearch-regexp-function (setq isearch-regexp nil))
1524 (unless (eq isearch-regexp-function #'isearch-symbol-regexp) 1521 (setq isearch-success t isearch-adjusted t)
1525 'isearch-symbol-regexp)) 1522 (isearch-update))
1526 (when isearch-regexp-function (setq isearch-regexp nil)) 1523 (define-key isearch-mode-map ,(concat "\M-s" key) #',command-name)
1527 (setq isearch-success t isearch-adjusted t) 1524 (put ',function 'isearch-message-prefix ,(format "%s " mode))
1528 (isearch-update)) 1525 (cl-callf (lambda (types) (cons 'choice
1529 1526 (cons '(const :tag ,(capitalize (format "%s search" mode)) ,function)
1530(defun isearch-toggle-character-fold () 1527 (cdr types))))
1531 "Toggle character folding in searching on or off." 1528 (get 'search-default-regexp-mode 'custom-type)))))
1532 (interactive) 1529
1533 (setq isearch-regexp-function 1530(isearch-specify-regexp-function word word-search-regexp "w")
1534 (unless (eq isearch-regexp-function #'character-fold-to-regexp) 1531(isearch-specify-regexp-function symbol isearch-symbol-regexp "_")
1535 #'character-fold-to-regexp)) 1532(isearch-specify-regexp-function character-fold character-fold-to-regexp "'")
1536 (when isearch-regexp-function (setq isearch-regexp nil)) 1533(put 'character-fold-to-regexp 'isearch-message-prefix "char-fold ")
1537 (setq isearch-success t isearch-adjusted t)
1538 (isearch-update))
1539 1534
1540(defun isearch-toggle-lax-whitespace () 1535(defun isearch-toggle-lax-whitespace ()
1541 "Toggle whitespace matching in searching on or off. 1536 "Toggle whitespace matching in searching on or off.