comparison lisp/isearch.el @ 14169:83f275dcd93a

Update FSF's address.
author Erik Naggum <erik@naggum.no>
date Sun, 14 Jan 1996 07:34:30 +0000
parents 0297cd54b530
children dbb66b58d8f4
comparison
equal deleted inserted replaced
14168:3b925cc52931 14169:83f275dcd93a
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details. 18 ;; GNU General Public License for more details.
19 19
20 ;; You should have received a copy of the GNU General Public License 20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
23 24
24 ;;; Commentary: 25 ;;; Commentary:
25 26
26 ;;;====================================================================
27 ;; Instructions 27 ;; Instructions
28 28
29 ;; For programmed use of isearch-mode, e.g. calling (isearch-forward), 29 ;; For programmed use of isearch-mode, e.g. calling (isearch-forward),
30 ;; isearch-mode behaves modally and does not return until the search 30 ;; isearch-mode behaves modally and does not return until the search
31 ;; is completed. It uses a recursive-edit to behave this way. Note: 31 ;; is completed. It uses a recursive-edit to behave this way. Note:
63 ;; - Think about incorporating query-replace. 63 ;; - Think about incorporating query-replace.
64 ;; - Hooks and options for failed search. 64 ;; - Hooks and options for failed search.
65 65
66 ;;; Change Log: 66 ;;; Change Log:
67 67
68 ;;; Changes before those recorded in ChangeLog: 68 ;; Changes before those recorded in ChangeLog:
69 69
70 ;;; Revision 1.4 92/09/14 16:26:02 liberte 70 ;; Revision 1.4 92/09/14 16:26:02 liberte
71 ;;; Added prefix args to isearch-forward, etc. to switch between 71 ;; Added prefix args to isearch-forward, etc. to switch between
72 ;;; string and regular expression searching. 72 ;; string and regular expression searching.
73 ;;; Added some support for lemacs. 73 ;; Added some support for lemacs.
74 ;;; Added general isearch-highlight option - but only for lemacs so far. 74 ;; Added general isearch-highlight option - but only for lemacs so far.
75 ;;; Added support for frame switching in emacs 19. 75 ;; Added support for frame switching in emacs 19.
76 ;;; Added word search option to isearch-edit-string. 76 ;; Added word search option to isearch-edit-string.
77 ;;; Renamed isearch-quit to isearch-abort. 77 ;; Renamed isearch-quit to isearch-abort.
78 ;;; Numerous changes to comments and doc strings. 78 ;; Numerous changes to comments and doc strings.
79 ;;; 79 ;;
80 ;;; Revision 1.3 92/06/29 13:10:08 liberte 80 ;; Revision 1.3 92/06/29 13:10:08 liberte
81 ;;; Moved modal isearch-mode handling into isearch-mode. 81 ;; Moved modal isearch-mode handling into isearch-mode.
82 ;;; Got rid of buffer-local isearch variables. 82 ;; Got rid of buffer-local isearch variables.
83 ;;; isearch-edit-string used by ring adjustments, completion, and 83 ;; isearch-edit-string used by ring adjustments, completion, and
84 ;;; nonincremental searching. C-s and C-r are additional exit commands. 84 ;; nonincremental searching. C-s and C-r are additional exit commands.
85 ;;; Renamed all regex to regexp. 85 ;; Renamed all regex to regexp.
86 ;;; Got rid of found-start and found-point globals. 86 ;; Got rid of found-start and found-point globals.
87 ;;; Generalized handling of upper-case chars. 87 ;; Generalized handling of upper-case chars.
88 88
89 ;;; Revision 1.2 92/05/27 11:33:57 liberte 89 ;; Revision 1.2 92/05/27 11:33:57 liberte
90 ;;; Emacs version 19 has a search ring, which is supported here. 90 ;; Emacs version 19 has a search ring, which is supported here.
91 ;;; Other fixes found in the version 19 isearch are included here. 91 ;; Other fixes found in the version 19 isearch are included here.
92 ;;; 92 ;;
93 ;;; Also see variables search-caps-disable-folding, 93 ;; Also see variables search-caps-disable-folding,
94 ;;; search-nonincremental-instead, search-whitespace-regexp, and 94 ;; search-nonincremental-instead, search-whitespace-regexp, and
95 ;;; commands isearch-toggle-regexp, isearch-edit-string. 95 ;; commands isearch-toggle-regexp, isearch-edit-string.
96 ;;; 96 ;;
97 ;;; semi-modal isearching is supported. 97 ;; semi-modal isearching is supported.
98 98
99 ;;; Changes for 1.1 99 ;; Changes for 1.1
100 ;;; 3/18/92 Fixed invalid-regexp. 100 ;; 3/18/92 Fixed invalid-regexp.
101 ;;; 3/18/92 Fixed yanking in regexps. 101 ;; 3/18/92 Fixed yanking in regexps.
102 102
103 ;;; Code: 103 ;;; Code:
104 104
105 105
106 ;;;========================================================================
107 ;;; Some additional options and constants. 106 ;;; Some additional options and constants.
108 107
109 (defconst search-exit-option t 108 (defconst search-exit-option t
110 "*Non-nil means random control characters terminate incremental search.") 109 "*Non-nil means random control characters terminate incremental search.")
111 110
143 "Function(s) to call after starting up an incremental search.") 142 "Function(s) to call after starting up an incremental search.")
144 143
145 (defvar isearch-mode-end-hook nil 144 (defvar isearch-mode-end-hook nil
146 "Function(s) to call after terminating an incremental search.") 145 "Function(s) to call after terminating an incremental search.")
147 146
148 ;;;==================================================================
149 ;;; Search ring. 147 ;;; Search ring.
150 148
151 (defvar search-ring nil 149 (defvar search-ring nil
152 "List of search string sequences.") 150 "List of search string sequences.")
153 (defvar regexp-search-ring nil 151 (defvar regexp-search-ring nil
167 165
168 (defvar search-ring-update nil 166 (defvar search-ring-update nil
169 "*Non-nil if advancing or retreating in the search ring should cause search. 167 "*Non-nil if advancing or retreating in the search ring should cause search.
170 Default value, nil, means edit the string instead.") 168 Default value, nil, means edit the string instead.")
171 169
172 ;;;====================================================
173 ;;; Define isearch-mode keymap. 170 ;;; Define isearch-mode keymap.
174 171
175 (defvar isearch-mode-map nil 172 (defvar isearch-mode-map nil
176 "Keymap for isearch-mode.") 173 "Keymap for isearch-mode.")
177 174
277 (define-key map "\C-s" 'isearch-forward-exit-minibuffer) 274 (define-key map "\C-s" 'isearch-forward-exit-minibuffer)
278 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer) 275 (define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
279 (setq minibuffer-local-isearch-map map) 276 (setq minibuffer-local-isearch-map map)
280 )) 277 ))
281 278
282 ;;;========================================================
283 ;; Internal variables declared globally for byte-compiler. 279 ;; Internal variables declared globally for byte-compiler.
284 ;; These are all set with setq while isearching 280 ;; These are all set with setq while isearching
285 ;; and bound locally while editing the search string. 281 ;; and bound locally while editing the search string.
286 282
287 (defvar isearch-forward nil) ; Searching in the forward direction. 283 (defvar isearch-forward nil) ; Searching in the forward direction.
329 325
330 ;; New value of isearch-forward after isearch-edit-string. 326 ;; New value of isearch-forward after isearch-edit-string.
331 (defvar isearch-new-forward nil) 327 (defvar isearch-new-forward nil)
332 328
333 329
334 ;;;==============================================================
335 ;; Minor-mode-alist changes - kind of redundant with the 330 ;; Minor-mode-alist changes - kind of redundant with the
336 ;; echo area, but if isearching in multiple windows, it can be useful. 331 ;; echo area, but if isearching in multiple windows, it can be useful.
337 332
338 (or (assq 'isearch-mode minor-mode-alist) 333 (or (assq 'isearch-mode minor-mode-alist)
339 (nconc minor-mode-alist 334 (nconc minor-mode-alist
345 (define-key global-map "\C-s" 'isearch-forward) 340 (define-key global-map "\C-s" 'isearch-forward)
346 (define-key esc-map "\C-s" 'isearch-forward-regexp) 341 (define-key esc-map "\C-s" 'isearch-forward-regexp)
347 (define-key global-map "\C-r" 'isearch-backward) 342 (define-key global-map "\C-r" 'isearch-backward)
348 (define-key esc-map "\C-r" 'isearch-backward-regexp) 343 (define-key esc-map "\C-r" 'isearch-backward-regexp)
349 344
350 ;;;===============================================================
351 ;;; Entry points to isearch-mode. 345 ;;; Entry points to isearch-mode.
352 ;;; These four functions should replace those in loaddefs.el 346 ;;; These four functions should replace those in loaddefs.el
353 ;;; An alternative is to defalias isearch-forward etc to isearch-mode, 347 ;;; An alternative is to defalias isearch-forward etc to isearch-mode,
354 ;;; and look at this-command to set the options accordingly. 348 ;;; and look at this-command to set the options accordingly.
355 349
426 (interactive) 420 (interactive)
427 (describe-function 'isearch-forward) 421 (describe-function 'isearch-forward)
428 (isearch-update)) 422 (isearch-update))
429 423
430 424
431 ;;;==================================================================
432 ;; isearch-mode only sets up incremental search for the minor mode. 425 ;; isearch-mode only sets up incremental search for the minor mode.
433 ;; All the work is done by the isearch-mode commands. 426 ;; All the work is done by the isearch-mode commands.
434 427
435 ;; Not used yet: 428 ;; Not used yet:
436 ;;(defconst isearch-commands '(isearch-forward isearch-backward 429 ;;(defconst isearch-commands '(isearch-forward isearch-backward
491 (let ((isearch-recursive-edit t)) 484 (let ((isearch-recursive-edit t))
492 (recursive-edit))) 485 (recursive-edit)))
493 isearch-success) 486 isearch-success)
494 487
495 488
496 ;;;====================================================
497 ;; Some high level utilities. Others below. 489 ;; Some high level utilities. Others below.
498 490
499 (defun isearch-update () 491 (defun isearch-update ()
500 ;; Called after each command to update the display. 492 ;; Called after each command to update the display.
501 (if (null unread-command-events) 493 (if (null unread-command-events)
585 (progn 577 (progn
586 (setq search-ring (cons string search-ring)) 578 (setq search-ring (cons string search-ring))
587 (if (> (length search-ring) search-ring-max) 579 (if (> (length search-ring) search-ring-max)
588 (setcdr (nthcdr (1- search-ring-max) search-ring) nil)))))) 580 (setcdr (nthcdr (1- search-ring-max) search-ring) nil))))))
589 581
590 ;;;=======================================================
591 ;;; Switching buffers should first terminate isearch-mode. 582 ;;; Switching buffers should first terminate isearch-mode.
592 ;;; This is done quite differently for each variant of emacs. 583 ;;; This is done quite differently for each variant of emacs.
593 ;;; For lemacs, see Exiting in lemacs below 584 ;;; For lemacs, see Exiting in lemacs below
594 585
595 ;; For Emacs 19, the frame switch event is handled. 586 ;; For Emacs 19, the frame switch event is handled.
597 (interactive) ;; Is this necessary? 588 (interactive) ;; Is this necessary?
598 ;; First terminate isearch-mode. 589 ;; First terminate isearch-mode.
599 (isearch-done) 590 (isearch-done)
600 (handle-switch-frame (car (cdr (isearch-last-command-char))))) 591 (handle-switch-frame (car (cdr (isearch-last-command-char)))))
601 592
602 ;;;========================================================
603
604 593
605 ;;;====================================================
606 ;; Commands active while inside of the isearch minor mode. 594 ;; Commands active while inside of the isearch minor mode.
607 595
608 (defun isearch-exit () 596 (defun isearch-exit ()
609 "Exit search normally. 597 "Exit search normally.
610 However, if this is the first command after starting incremental 598 However, if this is the first command after starting incremental
1122 (setq isearch-string (concat isearch-string string) 1110 (setq isearch-string (concat isearch-string string)
1123 isearch-message (concat isearch-message message)) 1111 isearch-message (concat isearch-message message))
1124 (isearch-search-and-update)) 1112 (isearch-search-and-update))
1125 1113
1126 1114
1127 ;;===========================================================
1128 ;; Search Ring 1115 ;; Search Ring
1129 1116
1130 (defun isearch-ring-adjust1 (advance) 1117 (defun isearch-ring-adjust1 (advance)
1131 ;; Helper for isearch-ring-adjust 1118 ;; Helper for isearch-ring-adjust
1132 (let* ((ring (if isearch-regexp regexp-search-ring search-ring)) 1119 (let* ((ring (if isearch-regexp regexp-search-ring search-ring))
1254 (progn 1241 (progn
1255 (erase-buffer) 1242 (erase-buffer)
1256 (insert isearch-string)))) 1243 (insert isearch-string))))
1257 1244
1258 1245
1259 ;;;==============================================================
1260 ;; The search status stack (and isearch window-local variables, not used). 1246 ;; The search status stack (and isearch window-local variables, not used).
1261 ;; Need a structure for this. 1247 ;; Need a structure for this.
1262 1248
1263 (defun isearch-top-state () 1249 (defun isearch-top-state ()
1264 (let ((cmd (car isearch-cmds))) 1250 (let ((cmd (car isearch-cmds)))
1288 isearch-invalid-regexp isearch-wrapped isearch-barrier 1274 isearch-invalid-regexp isearch-wrapped isearch-barrier
1289 isearch-within-brackets isearch-case-fold-search) 1275 isearch-within-brackets isearch-case-fold-search)
1290 isearch-cmds))) 1276 isearch-cmds)))
1291 1277
1292 1278
1293 ;;;==================================================================
1294 ;; Message string 1279 ;; Message string
1295 1280
1296 (defun isearch-message (&optional c-q-hack ellipsis) 1281 (defun isearch-message (&optional c-q-hack ellipsis)
1297 ;; Generate and print the message string. 1282 ;; Generate and print the message string.
1298 (let ((cursor-in-echo-area ellipsis) 1283 (let ((cursor-in-echo-area ellipsis)
1339 (if isearch-invalid-regexp 1324 (if isearch-invalid-regexp
1340 (concat " [" isearch-invalid-regexp "]") 1325 (concat " [" isearch-invalid-regexp "]")
1341 ""))) 1326 "")))
1342 1327
1343 1328
1344 ;;;========================================================
1345 ;;; Searching 1329 ;;; Searching
1346 1330
1347 (defun isearch-search () 1331 (defun isearch-search ()
1348 ;; Do the search with the current search string. 1332 ;; Do the search with the current search string.
1349 (isearch-message nil t) 1333 (isearch-message nil t)
1393 (ding)) 1377 (ding))
1394 (goto-char (nth 2 (car isearch-cmds))))) 1378 (goto-char (nth 2 (car isearch-cmds)))))
1395 1379
1396 1380
1397 1381
1398 ;;;========================================================
1399 ;;; Highlighting 1382 ;;; Highlighting
1400 1383
1401 (defvar isearch-overlay nil) 1384 (defvar isearch-overlay nil)
1402 1385
1403 (defun isearch-highlight (beg end) 1386 (defun isearch-highlight (beg end)
1411 1394
1412 (defun isearch-dehighlight (totally) 1395 (defun isearch-dehighlight (totally)
1413 (if isearch-overlay 1396 (if isearch-overlay
1414 (delete-overlay isearch-overlay))) 1397 (delete-overlay isearch-overlay)))
1415 1398
1416 ;;;===========================================================
1417 ;;; General utilities 1399 ;;; General utilities
1418 1400
1419 1401
1420 (defun isearch-no-upper-case-p (string regexp-flag) 1402 (defun isearch-no-upper-case-p (string regexp-flag)
1421 "Return t if there are no upper case chars in STRING. 1403 "Return t if there are no upper case chars in STRING.
1425 (not (string-match (if regexp-flag "\\(^\\|\\\\\\\\\\|[^\\]\\)[A-Z]" 1407 (not (string-match (if regexp-flag "\\(^\\|\\\\\\\\\\|[^\\]\\)[A-Z]"
1426 "[A-Z]") 1408 "[A-Z]")
1427 string)))) 1409 string))))
1428 1410
1429 1411
1430 ;;;=================================================
1431 ;; Portability functions to support various Emacs versions. 1412 ;; Portability functions to support various Emacs versions.
1432 1413
1433 ;; To quiet the byte-compiler. 1414 ;; To quiet the byte-compiler.
1434 (defvar unread-command-event) 1415 (defvar unread-command-event)
1435 (defvar unread-command-events) 1416 (defvar unread-command-events)