X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/641a3472ef245157ebcb2114f2d608cb3cb401a7..700afe62a4cbd9ecf24551ddc4747e6319fb51a2:/lisp/isearch.el diff --git a/lisp/isearch.el b/lisp/isearch.el index e636ccc0d2..eabf05b0b1 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -222,9 +222,9 @@ It is nil if none yet.") Default value, nil, means edit the string instead." :type 'boolean) -(autoload 'character-fold-to-regexp "character-fold") +(autoload 'char-fold-to-regexp "char-fold") -(defcustom search-default-regexp-mode #'character-fold-to-regexp +(defcustom search-default-mode nil "Default mode to use when starting isearch. Value is nil, t, or a function. @@ -234,9 +234,9 @@ If t, default to regexp searches (as if typing `\\[isearch-toggle-regexp]' durin isearch). If a function, use that function as an `isearch-regexp-function'. -Example functions are `word-search-regexp' \(`\\[isearch-toggle-word]'), -`isearch-symbol-regexp' \(`\\[isearch-toggle-symbol]'), and -`character-fold-to-regexp' \(`\\[isearch-toggle-character-fold]')." +Example functions (and the keys to toggle them during isearch) +are `word-search-regexp' \(`\\[isearch-toggle-word]'), `isearch-symbol-regexp' +\(`\\[isearch-toggle-symbol]'), and `char-fold-to-regexp' \(`\\[isearch-toggle-char-fold]')." ;; :type is set below by `isearch-define-mode-toggle'. :type '(choice (const :tag "Literal search" nil) (const :tag "Regexp search" t) @@ -510,6 +510,7 @@ This is like `describe-bindings', but displays only Isearch keys." ;; People expect to be able to paste with the mouse. (define-key map [mouse-2] #'isearch-mouse-2) (define-key map [down-mouse-2] nil) + (define-key map [xterm-paste] #'isearch-xterm-paste) ;; Some bindings you may want to put in your isearch-mode-hook. ;; Suggest some alternates... @@ -558,7 +559,11 @@ If the value is a function (e.g. `isearch-symbol-regexp'), it is called to convert a plain search string to a regexp used by regexp search functions. The symbol property `isearch-message-prefix' put on this function -specifies the prefix string displayed in the search message.") +specifies the prefix string displayed in the search message. + +This variable is set and changed during isearch. To change the +default behaviour used for searches, see `search-default-mode' +instead.") ;; We still support setting this to t for backwards compatibility. (define-obsolete-variable-alias 'isearch-word 'isearch-regexp-function "25.1") @@ -714,7 +719,7 @@ Type \\[isearch-toggle-invisible] to toggle search in invisible text. Type \\[isearch-toggle-regexp] to toggle regular-expression mode. Type \\[isearch-toggle-word] to toggle word mode. Type \\[isearch-toggle-symbol] to toggle symbol mode. -Type \\[isearch-toggle-character-fold] to toggle character folding. +Type \\[isearch-toggle-char-fold] to toggle character folding. Type \\[isearch-toggle-lax-whitespace] to toggle whitespace matching. In incremental searches, a space or spaces normally matches any whitespace @@ -833,10 +838,10 @@ See the command `isearch-forward-symbol' for more information." (buffer-substring-no-properties (car bounds) (cdr bounds)))) (t (setq isearch-error "No symbol at point") + (isearch-push-state) (isearch-update))))) -(defvar cursor-sensor-inhibit) ;; isearch-mode only sets up incremental search for the minor mode. ;; All the work is done by the isearch-mode commands. @@ -868,11 +873,11 @@ used to set the value of `isearch-regexp-function'." (setq isearch-forward forward isearch-regexp (or regexp (and (not regexp-function) - (eq search-default-regexp-mode t))) + (eq search-default-mode t))) isearch-regexp-function (or regexp-function - (and (functionp search-default-regexp-mode) + (and (functionp search-default-mode) (not regexp) - search-default-regexp-mode)) + search-default-mode)) isearch-op-fun op-fun isearch-last-case-fold-search isearch-case-fold-search isearch-case-fold-search case-fold-search @@ -969,8 +974,6 @@ The last thing is to trigger a new round of lazy highlighting." (setq cursor-sensor-inhibit (delq 'isearch cursor-sensor-inhibit)))) (setq isearch--current-buffer (current-buffer)) (make-local-variable 'cursor-sensor-inhibit) - (unless (boundp 'cursor-sensor-inhibit) - (setq cursor-sensor-inhibit nil)) ;; Suspend things like cursor-intangible during Isearch so we can search ;; even within intangible text. (push 'isearch cursor-sensor-inhibit)) @@ -1256,6 +1259,11 @@ You can update the global isearch variables by setting new values to (isearch-adjusted isearch-adjusted) (isearch-yank-flag isearch-yank-flag) (isearch-error isearch-error) + + (multi-isearch-file-list-new multi-isearch-file-list) + (multi-isearch-buffer-list-new multi-isearch-buffer-list) + (multi-isearch-next-buffer-function multi-isearch-next-buffer-current-function) + (multi-isearch-current-buffer-new multi-isearch-current-buffer) ;;; Don't bind this. We want isearch-search, below, to set it. ;;; And the old value won't matter after that. ;;; (isearch-other-end isearch-other-end) @@ -1310,7 +1318,10 @@ You can update the global isearch variables by setting new values to isearch-message isearch-new-message isearch-forward isearch-new-forward isearch-regexp-function isearch-new-regexp-function - isearch-case-fold-search isearch-new-case-fold) + isearch-case-fold-search isearch-new-case-fold + multi-isearch-current-buffer multi-isearch-current-buffer-new + multi-isearch-file-list multi-isearch-file-list-new + multi-isearch-buffer-list multi-isearch-buffer-list-new) ;; Restore the minibuffer message before moving point. (funcall (or isearch-message-function #'isearch-message) nil t) @@ -1506,7 +1517,7 @@ Use `isearch-exit' to quit without signaling." (isearch-repeat 'backward)) -;;; Toggles for `isearch-regexp-function' and `search-default-regexp-mode'. +;;; 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 @@ -1527,26 +1538,26 @@ The command then executes BODY and updates the isearch prompt." `((setq isearch-regexp-function (unless (eq isearch-regexp-function #',function) #',function)) - (when isearch-regexp-function (setq isearch-regexp nil)))) + (setq isearch-regexp nil))) ,@body (setq isearch-success t isearch-adjusted t) (isearch-update)) (define-key isearch-mode-map ,key #',command-name) - ,@(when (symbolp function) + ,@(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-regexp-mode 'custom-type))))))) + (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 character-fold "'" character-fold-to-regexp "\ +(isearch-define-mode-toggle char-fold "'" char-fold-to-regexp "\ Turning on character-folding turns off regexp mode.") -(put 'character-fold-to-regexp 'isearch-message-prefix "char-fold ") +(put 'char-fold-to-regexp 'isearch-message-prefix "char-fold ") (isearch-define-mode-toggle regexp "r" nil nil (setq isearch-regexp (not isearch-regexp)) @@ -1999,6 +2010,13 @@ is bound to outside of Isearch." (when (functionp binding) (call-interactively binding))))) +(declare-function xterm--pasted-text "term/xterm" ()) + +(defun isearch-xterm-paste () + "Pull terminal paste into search string." + (interactive) + (isearch-yank-string (xterm--pasted-text))) + (defun isearch-yank-internal (jumpform) "Pull the text from point to the point reached by JUMPFORM. JUMPFORM is a lambda expression that takes no arguments and returns @@ -2570,16 +2588,30 @@ the word mode." (when (eq regexp-function t) (setq regexp-function #'word-search-regexp)) (let ((description - ;; Don't use a description on the default search mode. - (cond ((equal regexp-function search-default-regexp-mode) "") - (regexp-function - (and (symbolp regexp-function) - (or (get regexp-function 'isearch-message-prefix) - ""))) - (isearch-regexp "regexp ") - ;; We're in literal mode. If the default mode is not - ;; literal, then describe it. - ((functionp search-default-regexp-mode) "literal ")))) + (cond + ;; 1. Do not use a description on the default search mode, + ;; but only if the default search mode is non-nil. + ((or (and search-default-mode + (equal search-default-mode regexp-function)) + ;; Special case where `search-default-mode' is t + ;; (defaults to regexp searches). + (and (eq search-default-mode t) + (eq search-default-mode isearch-regexp))) "") + ;; 2. Use the `isearch-message-prefix' set for + ;; `regexp-function' if available. + (regexp-function + (and (symbolp regexp-function) + (or (get regexp-function 'isearch-message-prefix) + ""))) + ;; 3. Else if `isearch-regexp' is non-nil, set description + ;; to "regexp ". + (isearch-regexp "regexp ") + ;; 4. Else if we're in literal mode (and if the default + ;; mode is also not literal), describe it. + ((functionp search-default-mode) "literal ") + ;; 5. And finally, if none of the above is true, set the + ;; description to an empty string. + (t "")))) (if space-before ;; Move space from the end to the beginning. (replace-regexp-in-string "\\(.*\\) \\'" " \\1" description) @@ -2647,10 +2679,12 @@ the word mode." "Non-default value overrides the behavior of `isearch-search-fun-default'. This variable's value should be a function, which will be called with no arguments, and should return a function that takes three -arguments: STRING, BOUND, and NOERROR. +arguments: STRING, BOUND, and NOERROR. STRING is the string to +be searched for. See `re-search-forward' for the meaning of +BOUND and NOERROR arguments. This returned function will be used by `isearch-search-string' to -search for the first occurrence of STRING or its translation.") +search for the first occurrence of STRING.") (defun isearch-search-fun () "Return the function to use for the search. @@ -2695,8 +2729,14 @@ Can be changed via `isearch-search-fun-function' for special needs." (defun isearch-search-string (string bound noerror) "Search for the first occurrence of STRING or its translation. +STRING's characters are translated using `translation-table-for-input' +if that is non-nil. If found, move point to the end of the occurrence, -update the match data, and return point." +update the match data, and return point. +An optional second argument bounds the search; it is a buffer position. +The match found must not extend after that position. +Optional third argument, if t, means if fail just return nil (no error). + If not nil and not t, move to limit of search and return nil." (let* ((func (isearch-search-fun)) (pos1 (save-excursion (funcall func string bound noerror))) pos2)