Mercurial > emacs
comparison lisp/info.el @ 56866:867d96c29584
(Info-search-whitespace-regexp): Fix backslashes.
(Info-search): Add new optional arguments for the sake of isearch.
Replace whitespace in Info-search-whitespace-regexp literally.
Add backward search. Don't call `Info-select-node' if regexp is
found in the same Info node. Don't add node to Info-history for
wrapped isearch.
(Info-search-backward, Info-isearch-search, Info-isearch-wrap)
(Info-isearch-push-state, Info-isearch-pop-state): New funs.
(Info-mode): Set local variables `isearch-search-fun-function',
`isearch-wrap-function', `isearch-push-state-function',
`search-whitespace-regexp'.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Wed, 01 Sep 2004 19:29:28 +0000 |
parents | 7aad97855e39 |
children | dca3dbca04cc |
comparison
equal
deleted
inserted
replaced
56865:6492b471e635 | 56866:867d96c29584 |
---|---|
186 file, so be prepared for a few surprises if you enable this feature." | 186 file, so be prepared for a few surprises if you enable this feature." |
187 :version "21.4" | 187 :version "21.4" |
188 :type 'boolean | 188 :type 'boolean |
189 :group 'info) | 189 :group 'info) |
190 | 190 |
191 (defcustom Info-search-whitespace-regexp "\\\\(?:\\\\s-+\\\\)" | 191 (defcustom Info-search-whitespace-regexp "\\(?:\\s-+\\)" |
192 "*If non-nil, regular expression to match a sequence of whitespace chars. | 192 "*If non-nil, regular expression to match a sequence of whitespace chars. |
193 This applies to Info search for regular expressions. | 193 This applies to Info search for regular expressions. |
194 You might want to use something like \"[ \\t\\r\\n]+\" instead. | 194 You might want to use something like \"[ \\t\\r\\n]+\" instead. |
195 In the Customization buffer, that is `[' followed by a space, | 195 In the Customization buffer, that is `[' followed by a space, |
196 a tab, a carriage return (control-M), a newline, and `]+'." | 196 a tab, a carriage return (control-M), a newline, and `]+'." |
1440 "The history list for `Info-search'.") | 1440 "The history list for `Info-search'.") |
1441 | 1441 |
1442 (defvar Info-search-case-fold nil | 1442 (defvar Info-search-case-fold nil |
1443 "The value of `case-fold-search' from previous `Info-search' command.") | 1443 "The value of `case-fold-search' from previous `Info-search' command.") |
1444 | 1444 |
1445 (defun Info-search (regexp) | 1445 (defun Info-search (regexp &optional bound noerror count direction) |
1446 "Search for REGEXP, starting from point, and select node it's found in." | 1446 "Search for REGEXP, starting from point, and select node it's found in. |
1447 If DIRECTION is `backward', search in the reverse direction." | |
1447 (interactive (list (read-string | 1448 (interactive (list (read-string |
1448 (if Info-search-history | 1449 (if Info-search-history |
1449 (format "Regexp search%s (default `%s'): " | 1450 (format "Regexp search%s (default `%s'): " |
1450 (if case-fold-search "" " case-sensitively") | 1451 (if case-fold-search "" " case-sensitively") |
1451 (car Info-search-history)) | 1452 (car Info-search-history)) |
1456 (deactivate-mark)) | 1457 (deactivate-mark)) |
1457 (when (equal regexp "") | 1458 (when (equal regexp "") |
1458 (setq regexp (car Info-search-history))) | 1459 (setq regexp (car Info-search-history))) |
1459 (when regexp | 1460 (when regexp |
1460 (let (found beg-found give-up | 1461 (let (found beg-found give-up |
1462 (backward (eq direction 'backward)) | |
1461 (onode Info-current-node) | 1463 (onode Info-current-node) |
1462 (ofile Info-current-file) | 1464 (ofile Info-current-file) |
1463 (opoint (point)) | 1465 (opoint (point)) |
1466 (opoint-min (point-min)) | |
1467 (opoint-max (point-max)) | |
1464 (ostart (window-start)) | 1468 (ostart (window-start)) |
1465 (osubfile Info-current-subfile)) | 1469 (osubfile Info-current-subfile)) |
1466 (when Info-search-whitespace-regexp | 1470 (when Info-search-whitespace-regexp |
1467 (setq regexp (replace-regexp-in-string | 1471 (setq regexp |
1468 "[ \t\n]+" Info-search-whitespace-regexp regexp))) | 1472 (mapconcat 'identity (split-string regexp "[ \t\n]+") |
1473 Info-search-whitespace-regexp))) | |
1469 (setq Info-search-case-fold case-fold-search) | 1474 (setq Info-search-case-fold case-fold-search) |
1470 (save-excursion | 1475 (save-excursion |
1471 (save-restriction | 1476 (save-restriction |
1472 (widen) | 1477 (widen) |
1473 (while (and (not give-up) | 1478 (while (and (not give-up) |
1474 (or (null found) | 1479 (or (null found) |
1475 (isearch-range-invisible beg-found found))) | 1480 (if backward |
1476 (if (re-search-forward regexp nil t) | 1481 (isearch-range-invisible found beg-found) |
1477 (setq found (point) beg-found (match-beginning 0)) | 1482 (isearch-range-invisible beg-found found)))) |
1483 (if (if backward | |
1484 (re-search-backward regexp bound t) | |
1485 (re-search-forward regexp bound t)) | |
1486 (setq found (point) beg-found (if backward (match-end 0) | |
1487 (match-beginning 0))) | |
1478 (setq give-up t))))) | 1488 (setq give-up t))))) |
1479 ;; If no subfiles, give error now. | 1489 ;; If no subfiles, give error now. |
1480 (if give-up | 1490 (if give-up |
1481 (if (null Info-current-subfile) | 1491 (if (null Info-current-subfile) |
1482 (re-search-forward regexp) | 1492 (if backward |
1493 (re-search-backward regexp) | |
1494 (re-search-forward regexp)) | |
1483 (setq found nil))) | 1495 (setq found nil))) |
1484 | 1496 |
1485 (unless found | 1497 (unless (or found bound) |
1486 (unwind-protect | 1498 (unwind-protect |
1487 ;; Try other subfiles. | 1499 ;; Try other subfiles. |
1488 (let ((list ())) | 1500 (let ((list ())) |
1489 (save-excursion | 1501 (save-excursion |
1490 (set-buffer (marker-buffer Info-tag-table-marker)) | 1502 (set-buffer (marker-buffer Info-tag-table-marker)) |
1496 (1- (point)))) | 1508 (1- (point)))) |
1497 (goto-char (point-min)) | 1509 (goto-char (point-min)) |
1498 ;; Find the subfile we just searched. | 1510 ;; Find the subfile we just searched. |
1499 (search-forward (concat "\n" osubfile ": ")) | 1511 (search-forward (concat "\n" osubfile ": ")) |
1500 ;; Skip that one. | 1512 ;; Skip that one. |
1501 (forward-line 1) | 1513 (forward-line (if backward 0 1)) |
1502 ;; Make a list of all following subfiles. | 1514 ;; Make a list of all following subfiles. |
1503 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME). | 1515 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME). |
1504 (while (not (eobp)) | 1516 (while (not (if backward (bobp) (eobp))) |
1505 (re-search-forward "\\(^.*\\): [0-9]+$") | 1517 (if backward |
1518 (re-search-backward "\\(^.*\\): [0-9]+$") | |
1519 (re-search-forward "\\(^.*\\): [0-9]+$")) | |
1506 (goto-char (+ (match-end 1) 2)) | 1520 (goto-char (+ (match-end 1) 2)) |
1507 (setq list (cons (cons (+ (point-min) | 1521 (setq list (cons (cons (+ (point-min) |
1508 (read (current-buffer))) | 1522 (read (current-buffer))) |
1509 (match-string-no-properties 1)) | 1523 (match-string-no-properties 1)) |
1510 list)) | 1524 list)) |
1511 (goto-char (1+ (match-end 0)))) | 1525 (goto-char (if backward |
1526 (1- (match-beginning 0)) | |
1527 (1+ (match-end 0))))) | |
1512 ;; Put in forward order | 1528 ;; Put in forward order |
1513 (setq list (nreverse list)))) | 1529 (setq list (nreverse list)))) |
1514 (while list | 1530 (while list |
1515 (message "Searching subfile %s..." (cdr (car list))) | 1531 (message "Searching subfile %s..." (cdr (car list))) |
1516 (Info-read-subfile (car (car list))) | 1532 (Info-read-subfile (car (car list))) |
1533 (if backward (goto-char (point-max))) | |
1517 (setq list (cdr list)) | 1534 (setq list (cdr list)) |
1518 (setq give-up nil found nil) | 1535 (setq give-up nil found nil) |
1519 (while (and (not give-up) | 1536 (while (and (not give-up) |
1520 (or (null found) | 1537 (or (null found) |
1521 (isearch-range-invisible beg-found found))) | 1538 (if backward |
1522 (if (re-search-forward regexp nil t) | 1539 (isearch-range-invisible found beg-found) |
1523 (setq found (point) beg-found (match-beginning 0)) | 1540 (isearch-range-invisible beg-found found)))) |
1541 (if (if backward | |
1542 (re-search-backward regexp nil t) | |
1543 (re-search-forward regexp nil t)) | |
1544 (setq found (point) beg-found (if backward (match-end 0) | |
1545 (match-beginning 0))) | |
1524 (setq give-up t))) | 1546 (setq give-up t))) |
1525 (if give-up | 1547 (if give-up |
1526 (setq found nil)) | 1548 (setq found nil)) |
1527 (if found | 1549 (if found |
1528 (setq list nil))) | 1550 (setq list nil))) |
1532 (if (not found) | 1554 (if (not found) |
1533 (progn (Info-read-subfile osubfile) | 1555 (progn (Info-read-subfile osubfile) |
1534 (goto-char opoint) | 1556 (goto-char opoint) |
1535 (Info-select-node) | 1557 (Info-select-node) |
1536 (set-window-start (selected-window) ostart))))) | 1558 (set-window-start (selected-window) ostart))))) |
1537 (widen) | 1559 |
1538 (goto-char found) | 1560 (if (and (string= osubfile Info-current-subfile) |
1539 (Info-select-node) | 1561 (> found opoint-min) |
1562 (< found opoint-max)) | |
1563 ;; Search landed in the same node | |
1564 (goto-char found) | |
1565 (widen) | |
1566 (goto-char found) | |
1567 (save-match-data (Info-select-node))) | |
1568 | |
1540 ;; Use string-equal, not equal, to ignore text props. | 1569 ;; Use string-equal, not equal, to ignore text props. |
1541 (or (and (string-equal onode Info-current-node) | 1570 (or (and (string-equal onode Info-current-node) |
1542 (equal ofile Info-current-file)) | 1571 (equal ofile Info-current-file)) |
1572 (and isearch-mode isearch-wrapped (eq opoint opoint-min)) | |
1543 (setq Info-history (cons (list ofile onode opoint) | 1573 (setq Info-history (cons (list ofile onode opoint) |
1544 Info-history)))))) | 1574 Info-history)))))) |
1545 | 1575 |
1546 (defun Info-search-case-sensitively () | 1576 (defun Info-search-case-sensitively () |
1547 "Search for a regexp case-sensitively." | 1577 "Search for a regexp case-sensitively." |
1554 (interactive) | 1584 (interactive) |
1555 (let ((case-fold-search Info-search-case-fold)) | 1585 (let ((case-fold-search Info-search-case-fold)) |
1556 (if Info-search-history | 1586 (if Info-search-history |
1557 (Info-search (car Info-search-history)) | 1587 (Info-search (car Info-search-history)) |
1558 (call-interactively 'Info-search)))) | 1588 (call-interactively 'Info-search)))) |
1589 | |
1590 (defun Info-search-backward (regexp &optional bound noerror count) | |
1591 "Search for REGEXP in the reverse direction." | |
1592 (interactive (list (read-string | |
1593 (if Info-search-history | |
1594 (format "Regexp search%s backward (default `%s'): " | |
1595 (if case-fold-search "" " case-sensitively") | |
1596 (car Info-search-history)) | |
1597 (format "Regexp search%s backward: " | |
1598 (if case-fold-search "" " case-sensitively"))) | |
1599 nil 'Info-search-history))) | |
1600 (Info-search regexp bound noerror count 'backward)) | |
1601 | |
1602 (defun Info-isearch-search () | |
1603 (cond | |
1604 (isearch-word | |
1605 (if isearch-forward 'word-search-forward 'word-search-backward)) | |
1606 (isearch-regexp | |
1607 (lambda (regexp bound noerror) | |
1608 (condition-case nil | |
1609 (progn | |
1610 (Info-search regexp bound noerror nil | |
1611 (unless isearch-forward 'backward)) | |
1612 (point)) | |
1613 (error nil)))) | |
1614 (t | |
1615 (if isearch-forward 'search-forward 'search-backward)))) | |
1616 | |
1617 (defun Info-isearch-wrap () | |
1618 (if isearch-regexp | |
1619 (if isearch-forward (Info-top-node) (Info-final-node)) | |
1620 (goto-char (if isearch-forward (point-min) (point-max))))) | |
1621 | |
1622 (defun Info-isearch-push-state () | |
1623 `(lambda (cmd) | |
1624 (Info-isearch-pop-state cmd ,Info-current-file ,Info-current-node))) | |
1625 | |
1626 (defun Info-isearch-pop-state (cmd file node) | |
1627 (or (and (string= Info-current-file file) | |
1628 (string= Info-current-node node)) | |
1629 (progn (Info-find-node file node) (sit-for 0)))) | |
1630 | |
1559 | 1631 |
1560 (defun Info-extract-pointer (name &optional errorname) | 1632 (defun Info-extract-pointer (name &optional errorname) |
1561 "Extract the value of the node-pointer named NAME. | 1633 "Extract the value of the node-pointer named NAME. |
1562 If there is none, use ERRORNAME in the error message; | 1634 If there is none, use ERRORNAME in the error message; |
1563 if ERRORNAME is nil, just return nil." | 1635 if ERRORNAME is nil, just return nil." |
3062 (setq line-move-ignore-invisible t) | 3134 (setq line-move-ignore-invisible t) |
3063 (make-local-variable 'desktop-save-buffer) | 3135 (make-local-variable 'desktop-save-buffer) |
3064 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data) | 3136 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data) |
3065 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t) | 3137 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t) |
3066 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) | 3138 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) |
3139 (set (make-local-variable 'isearch-search-fun-function) | |
3140 'Info-isearch-search) | |
3141 (set (make-local-variable 'isearch-wrap-function) | |
3142 'Info-isearch-wrap) | |
3143 (set (make-local-variable 'isearch-push-state-function) | |
3144 'Info-isearch-push-state) | |
3145 (set (make-local-variable 'search-whitespace-regexp) | |
3146 Info-search-whitespace-regexp) | |
3067 (Info-set-mode-line) | 3147 (Info-set-mode-line) |
3068 (run-hooks 'Info-mode-hook)) | 3148 (run-hooks 'Info-mode-hook)) |
3069 | 3149 |
3070 (defun Info-clone-buffer-hook () | 3150 (defun Info-clone-buffer-hook () |
3071 (when (bufferp Info-tag-table-buffer) | 3151 (when (bufferp Info-tag-table-buffer) |