75 |
;; Added word search option to isearch-edit-string. |
;; Added word search option to isearch-edit-string. |
76 |
;; Renamed isearch-quit to isearch-abort. |
;; Renamed isearch-quit to isearch-abort. |
77 |
;; Numerous changes to comments and doc strings. |
;; Numerous changes to comments and doc strings. |
78 |
;; |
;; |
79 |
;; Revision 1.3 92/06/29 13:10:08 liberte |
;; Revision 1.3 92/06/29 13:10:08 liberte |
80 |
;; Moved modal isearch-mode handling into isearch-mode. |
;; Moved modal isearch-mode handling into isearch-mode. |
81 |
;; Got rid of buffer-local isearch variables. |
;; Got rid of buffer-local isearch variables. |
182 |
This variable makes a difference when `search-invisible' is set to `open'. |
This variable makes a difference when `search-invisible' is set to `open'. |
183 |
It means that after search makes some invisible text visible |
It means that after search makes some invisible text visible |
184 |
to show the match, it makes the text invisible again when the match moves. |
to show the match, it makes the text invisible again when the match moves. |
185 |
Ordinarily the text becomes invisible again at the end of the search." |
Ordinarily the text becomes invisible again at the end of the search." |
186 |
:type 'boolean |
:type 'boolean |
187 |
:group 'isearch) |
:group 'isearch) |
188 |
|
|
189 |
(defvar isearch-mode-hook nil |
(defvar isearch-mode-hook nil |
238 |
;; Make function keys, etc, exit the search. |
;; Make function keys, etc, exit the search. |
239 |
(define-key map [t] 'isearch-other-control-char) |
(define-key map [t] 'isearch-other-control-char) |
240 |
;; Control chars, by default, end isearch mode transparently. |
;; Control chars, by default, end isearch mode transparently. |
241 |
;; We need these explicit definitions because, in a dense keymap, |
;; We need these explicit definitions because, in a dense keymap, |
242 |
;; the binding for t does not affect characters. |
;; the binding for t does not affect characters. |
243 |
;; We use a dense keymap to save space. |
;; We use a dense keymap to save space. |
244 |
(while (< i ?\ ) |
(while (< i ?\ ) |
277 |
(error "Inconsistency in isearch.el")) |
(error "Inconsistency in isearch.el")) |
278 |
(define-key map "\e\e\e" 'isearch-cancel) |
(define-key map "\e\e\e" 'isearch-cancel) |
279 |
(define-key map [escape escape escape] 'isearch-cancel) |
(define-key map [escape escape escape] 'isearch-cancel) |
280 |
|
|
281 |
(define-key map "\C-q" 'isearch-quote-char) |
(define-key map "\C-q" 'isearch-quote-char) |
282 |
|
|
283 |
(define-key map "\r" 'isearch-exit) |
(define-key map "\r" 'isearch-exit) |
285 |
(define-key map "\t" 'isearch-printing-char) |
(define-key map "\t" 'isearch-printing-char) |
286 |
(define-key map " " 'isearch-whitespace-chars) |
(define-key map " " 'isearch-whitespace-chars) |
287 |
(define-key map [?\S-\ ] 'isearch-whitespace-chars) |
(define-key map [?\S-\ ] 'isearch-whitespace-chars) |
288 |
|
|
289 |
(define-key map "\C-w" 'isearch-yank-word) |
(define-key map "\C-w" 'isearch-yank-word) |
290 |
(define-key map "\C-y" 'isearch-yank-line) |
(define-key map "\C-y" 'isearch-yank-line) |
291 |
|
|
428 |
With a prefix argument, do an incremental regular expression search instead. |
With a prefix argument, do an incremental regular expression search instead. |
429 |
\\<isearch-mode-map> |
\\<isearch-mode-map> |
430 |
As you type characters, they add to the search string and are found. |
As you type characters, they add to the search string and are found. |
431 |
The following non-printing keys are bound in `isearch-mode-map'. |
The following non-printing keys are bound in `isearch-mode-map'. |
432 |
|
|
433 |
Type \\[isearch-delete-char] to cancel characters from end of search string. |
Type \\[isearch-delete-char] to cancel characters from end of search string. |
434 |
Type \\[isearch-exit] to exit, leaving point at location found. |
Type \\[isearch-exit] to exit, leaving point at location found. |
459 |
Type \\[isearch-complete] to complete the search string using the search ring. |
Type \\[isearch-complete] to complete the search string using the search ring. |
460 |
|
|
461 |
If an input method is turned on in the current buffer, that input |
If an input method is turned on in the current buffer, that input |
462 |
method is also active while you are typing a characters to search. To |
method is also active while you are typing characters to search. To |
463 |
toggle the input method, type \\[isearch-toggle-input-method]. It |
toggle the input method, type \\[isearch-toggle-input-method]. It |
464 |
also toggles the input method in the current buffer. |
also toggles the input method in the current buffer. |
465 |
|
|
467 |
\\[isearch-toggle-specified-input-method], and specify an input method |
\\[isearch-toggle-specified-input-method], and specify an input method |
468 |
you want to use. |
you want to use. |
469 |
|
|
470 |
The above keys, bound in `isearch-mode-map', are often controlled by |
The above keys, bound in `isearch-mode-map', are often controlled by |
471 |
options; do M-x apropos on search-.* to find them. |
options; do M-x apropos on search-.* to find them. |
472 |
Other control and meta characters terminate the search |
Other control and meta characters terminate the search |
473 |
and are then executed normally (depending on `search-exit-option'). |
and are then executed normally (depending on `search-exit-option'). |
519 |
;;(defvar isearch-commands '(isearch-forward isearch-backward |
;;(defvar isearch-commands '(isearch-forward isearch-backward |
520 |
;; isearch-forward-regexp isearch-backward-regexp) |
;; isearch-forward-regexp isearch-backward-regexp) |
521 |
;; "List of commands for which isearch-mode does not recursive-edit.") |
;; "List of commands for which isearch-mode does not recursive-edit.") |
522 |
|
|
523 |
|
|
524 |
(defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p) |
(defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p) |
525 |
"Start isearch minor mode. Called by `isearch-forward', etc. |
"Start isearch minor mode. Called by `isearch-forward', etc. |
592 |
(add-hook 'mouse-leave-buffer-hook 'isearch-done) |
(add-hook 'mouse-leave-buffer-hook 'isearch-done) |
593 |
(add-hook 'kbd-macro-termination-hook 'isearch-done) |
(add-hook 'kbd-macro-termination-hook 'isearch-done) |
594 |
|
|
595 |
;; isearch-mode can be made modal (in the sense of not returning to |
;; isearch-mode can be made modal (in the sense of not returning to |
596 |
;; the calling function until searching is completed) by entering |
;; the calling function until searching is completed) by entering |
597 |
;; a recursive-edit and exiting it when done isearching. |
;; a recursive-edit and exiting it when done isearching. |
598 |
(if recursive-edit |
(if recursive-edit |
599 |
(let ((isearch-recursive-edit t)) |
(let ((isearch-recursive-edit t)) |
604 |
;; Some high level utilities. Others below. |
;; Some high level utilities. Others below. |
605 |
|
|
606 |
(defun isearch-update () |
(defun isearch-update () |
607 |
;; Called after each command to update the display. |
;; Called after each command to update the display. |
608 |
(if (null unread-command-events) |
(if (null unread-command-events) |
609 |
(progn |
(progn |
610 |
(if (not (input-pending-p)) |
(if (not (input-pending-p)) |
611 |
(isearch-message)) |
(isearch-message)) |
612 |
(if (and isearch-slow-terminal-mode |
(if (and isearch-slow-terminal-mode |
613 |
(not (or isearch-small-window |
(not (or isearch-small-window |
614 |
(pos-visible-in-window-p)))) |
(pos-visible-in-window-p)))) |
615 |
(let ((found-point (point))) |
(let ((found-point (point))) |
616 |
(setq isearch-small-window t) |
(setq isearch-small-window t) |
708 |
(defun isearch-update-ring (string &optional regexp) |
(defun isearch-update-ring (string &optional regexp) |
709 |
"Add STRING to the beginning of the search ring. |
"Add STRING to the beginning of the search ring. |
710 |
REGEXP says which ring to use." |
REGEXP says which ring to use." |
711 |
(if regexp |
(if regexp |
712 |
(if (or (null regexp-search-ring) |
(if (or (null regexp-search-ring) |
713 |
(not (string= string (car regexp-search-ring)))) |
(not (string= string (car regexp-search-ring)))) |
714 |
(progn |
(progn |
730 |
;;; (interactive) ;; Is this necessary? |
;;; (interactive) ;; Is this necessary? |
731 |
;;; ;; First terminate isearch-mode. |
;;; ;; First terminate isearch-mode. |
732 |
;;; (isearch-done) |
;;; (isearch-done) |
733 |
;;; (isearch-clean-overlays) |
;;; (isearch-clean-overlays) |
734 |
;;; (handle-switch-frame (car (cdr last-command-char)))) |
;;; (handle-switch-frame (car (cdr last-command-char)))) |
735 |
|
|
736 |
|
|
742 |
search and `search-nonincremental-instead' is non-nil, do a |
search and `search-nonincremental-instead' is non-nil, do a |
743 |
nonincremental search instead via `isearch-edit-string'." |
nonincremental search instead via `isearch-edit-string'." |
744 |
(interactive) |
(interactive) |
745 |
(if (and search-nonincremental-instead |
(if (and search-nonincremental-instead |
746 |
(= 0 (length isearch-string))) |
(= 0 (length isearch-string))) |
747 |
(let ((isearch-nonincremental t)) |
(let ((isearch-nonincremental t)) |
748 |
(isearch-edit-string))) |
(isearch-edit-string))) |
814 |
) |
) |
815 |
|
|
816 |
;; Actually terminate isearching until editing is done. |
;; Actually terminate isearching until editing is done. |
817 |
;; This is so that the user can do anything without failure, |
;; This is so that the user can do anything without failure, |
818 |
;; like switch buffers and start another isearch, and return. |
;; like switch buffers and start another isearch, and return. |
819 |
(condition-case err |
(condition-case err |
820 |
(isearch-done t t) |
(isearch-done t t) |
822 |
|
|
823 |
(isearch-message) ;; for read-char |
(isearch-message) ;; for read-char |
824 |
(unwind-protect |
(unwind-protect |
825 |
(let* (;; Why does following read-char echo? |
(let* (;; Why does following read-char echo? |
826 |
;;(echo-keystrokes 0) ;; not needed with above message |
;;(echo-keystrokes 0) ;; not needed with above message |
827 |
(e (let ((cursor-in-echo-area t)) |
(e (let ((cursor-in-echo-area t)) |
828 |
(read-event))) |
(read-event))) |
855 |
(mapconcat 'isearch-text-char-description |
(mapconcat 'isearch-text-char-description |
856 |
isearch-new-string ""))) |
isearch-new-string ""))) |
857 |
;; Always resume isearching by restarting it. |
;; Always resume isearching by restarting it. |
858 |
(isearch-mode isearch-forward |
(isearch-mode isearch-forward |
859 |
isearch-regexp |
isearch-regexp |
860 |
isearch-op-fun |
isearch-op-fun |
861 |
nil |
nil |
862 |
isearch-word) |
isearch-word) |
863 |
|
|
884 |
;; Reinvoke the pending search. |
;; Reinvoke the pending search. |
885 |
(isearch-search) |
(isearch-search) |
886 |
(isearch-update) |
(isearch-update) |
887 |
(if isearch-nonincremental |
(if isearch-nonincremental |
888 |
(progn |
(progn |
889 |
;; (sit-for 1) ;; needed if isearch-done does: (message "") |
;; (sit-for 1) ;; needed if isearch-done does: (message "") |
890 |
(isearch-done)))) |
(isearch-done)))) |
1012 |
(isearch-update)) |
(isearch-update)) |
1013 |
|
|
1014 |
(defun isearch-delete-char () |
(defun isearch-delete-char () |
1015 |
"Discard last input item and move point back. |
"Discard last input item and move point back. |
1016 |
If no previous match was done, just beep." |
If no previous match was done, just beep." |
1017 |
(interactive) |
(interactive) |
1018 |
(if (null (cdr isearch-cmds)) |
(if (null (cdr isearch-cmds)) |
1111 |
(regexp-quote isearch-string)))) |
(regexp-quote isearch-string)))) |
1112 |
(error nil)) |
(error nil)) |
1113 |
(or isearch-yank-flag |
(or isearch-yank-flag |
1114 |
(<= (match-end 0) |
(<= (match-end 0) |
1115 |
(min isearch-opoint isearch-barrier)))) |
(min isearch-opoint isearch-barrier)))) |
1116 |
(progn |
(progn |
1117 |
(setq isearch-success t |
(setq isearch-success t |
1118 |
isearch-invalid-regexp nil |
isearch-invalid-regexp nil |
1119 |
isearch-within-brackets nil |
isearch-within-brackets nil |
1120 |
isearch-other-end (match-end 0)) |
isearch-other-end (match-end 0)) |
1124 |
;; Not regexp, not reverse, or no match at point. |
;; Not regexp, not reverse, or no match at point. |
1125 |
(if (and isearch-other-end (not isearch-adjusted)) |
(if (and isearch-other-end (not isearch-adjusted)) |
1126 |
(goto-char (if isearch-forward isearch-other-end |
(goto-char (if isearch-forward isearch-other-end |
1127 |
(min isearch-opoint |
(min isearch-opoint |
1128 |
isearch-barrier |
isearch-barrier |
1129 |
(1+ isearch-other-end))))) |
(1+ isearch-other-end))))) |
1130 |
(isearch-search) |
(isearch-search) |
1131 |
)) |
)) |
1143 |
(defun isearch-*-char () |
(defun isearch-*-char () |
1144 |
"Handle * and ? specially in regexps." |
"Handle * and ? specially in regexps." |
1145 |
(interactive) |
(interactive) |
1146 |
(if isearch-regexp |
(if isearch-regexp |
1147 |
(let ((idx (length isearch-string))) |
(let ((idx (length isearch-string))) |
1148 |
(while (and (> idx 0) |
(while (and (> idx 0) |
1149 |
(eq (aref isearch-string (1- idx)) ?\\)) |
(eq (aref isearch-string (1- idx)) ?\\)) |
1162 |
(max cs isearch-barrier) |
(max cs isearch-barrier) |
1163 |
(min cs isearch-barrier))))))) |
(min cs isearch-barrier))))))) |
1164 |
(isearch-process-search-char last-command-char)) |
(isearch-process-search-char last-command-char)) |
1165 |
|
|
1166 |
|
|
1167 |
(defun isearch-|-char () |
(defun isearch-|-char () |
1168 |
"If in regexp search, jump to the barrier." |
"If in regexp search, jump to the barrier." |
1249 |
(when (and (> (length key) 1) |
(when (and (> (length key) 1) |
1250 |
(symbolp (aref key 0)) |
(symbolp (aref key 0)) |
1251 |
(listp (aref key 1)) |
(listp (aref key 1)) |
1252 |
(not (numberp (posn-point |
(not (numberp (posn-point |
1253 |
(event-start (aref key 1)))))) |
(event-start (aref key 1)))))) |
1254 |
(pop unread-command-events) |
(pop unread-command-events) |
1255 |
(setq main-event (car unread-command-events))) |
(setq main-event (car unread-command-events))) |
1263 |
;; obviously wrong for the case that a down-mouse event |
;; obviously wrong for the case that a down-mouse event |
1264 |
;; on another window invokes this function. The event |
;; on another window invokes this function. The event |
1265 |
;; will contain the window clicked on and that window's |
;; will contain the window clicked on and that window's |
1266 |
;; buffer is certainaly not always in Isearch mode. |
;; buffer is certainly not always in Isearch mode. |
1267 |
;; |
;; |
1268 |
;; Leave the code in, but check for current buffer not |
;; Leave the code in, but check for current buffer not |
1269 |
;; being in Isearch mode for now, until someone tells |
;; being in Isearch mode for now, until someone tells |
1325 |
"Match all whitespace chars, if in regexp mode. |
"Match all whitespace chars, if in regexp mode. |
1326 |
If you want to search for just a space, type \\[quoted-insert] SPC." |
If you want to search for just a space, type \\[quoted-insert] SPC." |
1327 |
(interactive) |
(interactive) |
1328 |
(if isearch-regexp |
(if isearch-regexp |
1329 |
(if (and search-whitespace-regexp (not isearch-within-brackets) |
(if (and search-whitespace-regexp (not isearch-within-brackets) |
1330 |
(not isearch-invalid-regexp)) |
(not isearch-invalid-regexp)) |
1331 |
(isearch-process-search-string search-whitespace-regexp " ") |
(isearch-process-search-string search-whitespace-regexp " ") |
1339 |
|
|
1340 |
(defun isearch-process-search-char (char) |
(defun isearch-process-search-char (char) |
1341 |
;; Append the char to the search string, update the message and re-search. |
;; Append the char to the search string, update the message and re-search. |
1342 |
(isearch-process-search-string |
(isearch-process-search-string |
1343 |
(char-to-string char) |
(char-to-string char) |
1344 |
(if (>= char ?\200) |
(if (>= char ?\200) |
1345 |
(char-to-string char) |
(char-to-string char) |
1346 |
(isearch-text-char-description char)))) |
(isearch-text-char-description char)))) |
1454 |
(progn |
(progn |
1455 |
(if completion-auto-help |
(if completion-auto-help |
1456 |
(with-output-to-temp-buffer "*Isearch completions*" |
(with-output-to-temp-buffer "*Isearch completions*" |
1457 |
(display-completion-list |
(display-completion-list |
1458 |
(all-completions isearch-string alist)))) |
(all-completions isearch-string alist)))) |
1459 |
t) |
t) |
1460 |
(and completion |
(and completion |
1507 |
(isearch-top-state)) |
(isearch-top-state)) |
1508 |
|
|
1509 |
(defun isearch-push-state () |
(defun isearch-push-state () |
1510 |
(setq isearch-cmds |
(setq isearch-cmds |
1511 |
(cons (list isearch-string isearch-message (point) |
(cons (list isearch-string isearch-message (point) |
1512 |
isearch-success isearch-forward isearch-other-end |
isearch-success isearch-forward isearch-other-end |
1513 |
isearch-word |
isearch-word |
1514 |
isearch-invalid-regexp isearch-wrapped isearch-barrier |
isearch-invalid-regexp isearch-wrapped isearch-barrier |
1515 |
isearch-within-brackets isearch-case-fold-search) |
isearch-within-brackets isearch-case-fold-search) |
1612 |
(quit (isearch-unread ?\C-g) |
(quit (isearch-unread ?\C-g) |
1613 |
(setq isearch-success nil)) |
(setq isearch-success nil)) |
1614 |
|
|
1615 |
(invalid-regexp |
(invalid-regexp |
1616 |
(setq isearch-invalid-regexp (car (cdr lossage))) |
(setq isearch-invalid-regexp (car (cdr lossage))) |
1617 |
(setq isearch-within-brackets (string-match "\\`Unmatched \\[" |
(setq isearch-within-brackets (string-match "\\`Unmatched \\[" |
1618 |
isearch-invalid-regexp)) |
isearch-invalid-regexp)) |
1634 |
|
|
1635 |
;;; Called when opening an overlay, and we are still in isearch. |
;;; Called when opening an overlay, and we are still in isearch. |
1636 |
(defun isearch-open-overlay-temporary (ov) |
(defun isearch-open-overlay-temporary (ov) |
1637 |
(if (not (null (overlay-get ov 'isearch-open-invisible-temporary))) |
(if (not (null (overlay-get ov 'isearch-open-invisible-temporary))) |
1638 |
;; Some modes would want to open the overlays temporary during |
;; Some modes would want to open the overlays temporary during |
1639 |
;; isearch in their own way, they should set the |
;; isearch in their own way, they should set the |
1640 |
;; `isearch-open-invisible-temporary' to a function doing this. |
;; `isearch-open-invisible-temporary' to a function doing this. |
1657 |
;;; point returns to the original location which surely is not contain |
;;; point returns to the original location which surely is not contain |
1658 |
;;; in any of these overlays, se we are safe in this case too. |
;;; in any of these overlays, se we are safe in this case too. |
1659 |
(defun isearch-open-necessary-overlays (ov) |
(defun isearch-open-necessary-overlays (ov) |
1660 |
(let ((inside-overlay (and (> (point) (overlay-start ov)) |
(let ((inside-overlay (and (> (point) (overlay-start ov)) |
1661 |
(< (point) (overlay-end ov)))) |
(< (point) (overlay-end ov)))) |
1662 |
;; If this exists it means that the overlay was opened using |
;; If this exists it means that the overlay was opened using |
1663 |
;; this function, not by us tweaking the overlay properties. |
;; this function, not by us tweaking the overlay properties. |
1722 |
(can-be-opened (eq search-invisible 'open)) |
(can-be-opened (eq search-invisible 'open)) |
1723 |
;; the list of overlays that could be opened |
;; the list of overlays that could be opened |
1724 |
(crt-overlays nil)) |
(crt-overlays nil)) |
1725 |
(when (and can-be-opened isearch-hide-immediately) |
(when (and can-be-opened isearch-hide-immediately) |
1726 |
(isearch-close-unnecessary-overlays beg end)) |
(isearch-close-unnecessary-overlays beg end)) |
1727 |
;; If the following character is currently invisible, |
;; If the following character is currently invisible, |
1728 |
;; skip all characters with that same `invisible' property value. |
;; skip all characters with that same `invisible' property value. |
1735 |
(or (memq prop buffer-invisibility-spec) |
(or (memq prop buffer-invisibility-spec) |
1736 |
(assq prop buffer-invisibility-spec))))) |
(assq prop buffer-invisibility-spec))))) |
1737 |
(if (get-text-property (point) 'invisible) |
(if (get-text-property (point) 'invisible) |
1738 |
(progn |
(progn |
1739 |
(goto-char (next-single-property-change (point) 'invisible |
(goto-char (next-single-property-change (point) 'invisible |
1740 |
nil end)) |
nil end)) |
1741 |
;; if text is hidden by an `invisible' text property |
;; if text is hidden by an `invisible' text property |
1760 |
;; cannot be opened. |
;; cannot be opened. |
1761 |
(setq can-be-opened nil))) |
(setq can-be-opened nil))) |
1762 |
(setq overlays (cdr overlays))) |
(setq overlays (cdr overlays))) |
1763 |
(if can-be-opened |
(if can-be-opened |
1764 |
;; It makes sense to append to the open |
;; It makes sense to append to the open |
1765 |
;; overlays list only if we know that this is |
;; overlays list only if we know that this is |
1766 |
;; t. |
;; t. |
1806 |
"Return t if there are no upper case chars in STRING. |
"Return t if there are no upper case chars in STRING. |
1807 |
If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\') |
If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\') |
1808 |
since they have special meaning in a regexp." |
since they have special meaning in a regexp." |
1809 |
(let (quote-flag (i 0) (len (length string)) found) |
(let (quote-flag (i 0) (len (length string)) found) |
1810 |
(while (and (not found) (< i len)) |
(while (and (not found) (< i len)) |
1811 |
(let ((char (aref string i))) |
(let ((char (aref string i))) |
1812 |
(if (and regexp-flag (eq char ?\\)) |
(if (and regexp-flag (eq char ?\\)) |
2069 |
isearch-message message |
isearch-message message |
2070 |
isearch-case-fold-search case-fold) |
isearch-case-fold-search case-fold) |
2071 |
(isearch-search)) |
(isearch-search)) |
2072 |
|
|
2073 |
;;; isearch.el ends here |
;;; isearch.el ends here |