- (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.
-In ordinary search, toggles the value of the variable
-`isearch-lax-whitespace'. In regexp search, toggles the
-value of the variable `isearch-regexp-lax-whitespace'."
- (interactive)
- (if isearch-regexp
- (setq isearch-regexp-lax-whitespace (not isearch-regexp-lax-whitespace))
- (setq isearch-lax-whitespace (not isearch-lax-whitespace)))
- (let ((message-log-max nil))
- (message "%s%s [%s]"
- (isearch-message-prefix nil isearch-nonincremental)
- isearch-message
- (if (if isearch-regexp
- isearch-regexp-lax-whitespace
- isearch-lax-whitespace)
- "match spaces loosely"
- "match spaces literally")))
- (setq isearch-success t isearch-adjusted t)
- (sit-for 1)
- (isearch-update))
+ (define-key isearch-mode-map ,key #',command-name)
+ ,@(when (and function (symbolp function))
+ `((put ',function 'isearch-message-prefix ,(format "%s " mode))
+ (put ',function :advertised-binding ,key)
+ (cl-callf (lambda (types) (cons 'choice
+ (cons '(const :tag ,(capitalize (format "%s search" mode)) ,function)
+ (cdr types))))
+ (get 'search-default-mode 'custom-type)))))))
+
+(isearch-define-mode-toggle word "w" word-search-regexp "\
+Turning on word search turns off regexp mode.")
+(isearch-define-mode-toggle symbol "_" isearch-symbol-regexp "\
+Turning on symbol search turns off regexp mode.")
+(isearch-define-mode-toggle char-fold "'" char-fold-to-regexp "\
+Turning on character-folding turns off regexp mode.")
+(put 'char-fold-to-regexp 'isearch-message-prefix "char-fold ")
+
+(isearch-define-mode-toggle regexp "r" nil nil
+ (setq isearch-regexp (not isearch-regexp))
+ (if isearch-regexp (setq isearch-regexp-function nil)))