Function: isearch-define-mode-toggle
isearch-define-mode-toggle is a macro defined in isearch.el.gz.
Signature
(isearch-define-mode-toggle MODE KEY FUNCTION &optional DOCSTRING &rest BODY)
Documentation
Define a command called isearch-toggle-MODE and bind it to M-s KEY.
The first line of the command's docstring is auto-generated, the
remainder may be provided in DOCSTRING.
If FUNCTION is a symbol, this command first toggles the value of
isearch-regexp-function between nil and FUNCTION. Also set the
isearch-message-prefix property of FUNCTION.
The command then executes BODY and updates the isearch prompt.
Source Code
;; Defined in /usr/src/emacs/lisp/isearch.el.gz
;;; Toggles for `isearch-regexp-function' and `search-default-mode'.
(defmacro isearch-define-mode-toggle (mode key function &optional docstring &rest body)
"Define a command called `isearch-toggle-MODE' and bind it to `M-s KEY'.
The first line of the command's docstring is auto-generated, the
remainder may be provided in DOCSTRING.
If FUNCTION is a symbol, this command first toggles the value of
`isearch-regexp-function' between nil and FUNCTION. Also set the
`isearch-message-prefix' property of FUNCTION.
The command then executes BODY and updates the isearch prompt."
(declare (indent defun))
(let ((command-name (intern (format "isearch-toggle-%s" mode)))
(key (concat "\M-s" key)))
`(progn
(defun ,command-name ()
,(format "Toggle %s searching on or off.%s" mode
(if docstring (concat "\n" docstring) ""))
(interactive)
(unless isearch-mode (isearch-mode t))
,@(when function
`((setq isearch-regexp-function
(unless (eq isearch-regexp-function #',function)
#',function))
(setq isearch-regexp nil)))
,@body
(setq isearch-success t isearch-adjusted 'toggle)
(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)))))))