Commit 0b02cda9 authored by Juri Linkov's avatar Juri Linkov

(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'.
parent 8b3094c7
...@@ -188,7 +188,7 @@ file, so be prepared for a few surprises if you enable this feature." ...@@ -188,7 +188,7 @@ file, so be prepared for a few surprises if you enable this feature."
:type 'boolean :type 'boolean
:group 'info) :group 'info)
(defcustom Info-search-whitespace-regexp "\\\\(?:\\\\s-+\\\\)" (defcustom Info-search-whitespace-regexp "\\(?:\\s-+\\)"
"*If non-nil, regular expression to match a sequence of whitespace chars. "*If non-nil, regular expression to match a sequence of whitespace chars.
This applies to Info search for regular expressions. This applies to Info search for regular expressions.
You might want to use something like \"[ \\t\\r\\n]+\" instead. You might want to use something like \"[ \\t\\r\\n]+\" instead.
...@@ -1442,8 +1442,9 @@ If FORK is a string, it is the name to use for the new buffer." ...@@ -1442,8 +1442,9 @@ If FORK is a string, it is the name to use for the new buffer."
(defvar Info-search-case-fold nil (defvar Info-search-case-fold nil
"The value of `case-fold-search' from previous `Info-search' command.") "The value of `case-fold-search' from previous `Info-search' command.")
(defun Info-search (regexp) (defun Info-search (regexp &optional bound noerror count direction)
"Search for REGEXP, starting from point, and select node it's found in." "Search for REGEXP, starting from point, and select node it's found in.
If DIRECTION is `backward', search in the reverse direction."
(interactive (list (read-string (interactive (list (read-string
(if Info-search-history (if Info-search-history
(format "Regexp search%s (default `%s'): " (format "Regexp search%s (default `%s'): "
...@@ -1458,31 +1459,42 @@ If FORK is a string, it is the name to use for the new buffer." ...@@ -1458,31 +1459,42 @@ If FORK is a string, it is the name to use for the new buffer."
(setq regexp (car Info-search-history))) (setq regexp (car Info-search-history)))
(when regexp (when regexp
(let (found beg-found give-up (let (found beg-found give-up
(backward (eq direction 'backward))
(onode Info-current-node) (onode Info-current-node)
(ofile Info-current-file) (ofile Info-current-file)
(opoint (point)) (opoint (point))
(opoint-min (point-min))
(opoint-max (point-max))
(ostart (window-start)) (ostart (window-start))
(osubfile Info-current-subfile)) (osubfile Info-current-subfile))
(when Info-search-whitespace-regexp (when Info-search-whitespace-regexp
(setq regexp (replace-regexp-in-string (setq regexp
"[ \t\n]+" Info-search-whitespace-regexp regexp))) (mapconcat 'identity (split-string regexp "[ \t\n]+")
Info-search-whitespace-regexp)))
(setq Info-search-case-fold case-fold-search) (setq Info-search-case-fold case-fold-search)
(save-excursion (save-excursion
(save-restriction (save-restriction
(widen) (widen)
(while (and (not give-up) (while (and (not give-up)
(or (null found) (or (null found)
(isearch-range-invisible beg-found found))) (if backward
(if (re-search-forward regexp nil t) (isearch-range-invisible found beg-found)
(setq found (point) beg-found (match-beginning 0)) (isearch-range-invisible beg-found found))))
(if (if backward
(re-search-backward regexp bound t)
(re-search-forward regexp bound t))
(setq found (point) beg-found (if backward (match-end 0)
(match-beginning 0)))
(setq give-up t))))) (setq give-up t)))))
;; If no subfiles, give error now. ;; If no subfiles, give error now.
(if give-up (if give-up
(if (null Info-current-subfile) (if (null Info-current-subfile)
(re-search-forward regexp) (if backward
(re-search-backward regexp)
(re-search-forward regexp))
(setq found nil))) (setq found nil)))
(unless found (unless (or found bound)
(unwind-protect (unwind-protect
;; Try other subfiles. ;; Try other subfiles.
(let ((list ())) (let ((list ()))
...@@ -1498,29 +1510,39 @@ If FORK is a string, it is the name to use for the new buffer." ...@@ -1498,29 +1510,39 @@ If FORK is a string, it is the name to use for the new buffer."
;; Find the subfile we just searched. ;; Find the subfile we just searched.
(search-forward (concat "\n" osubfile ": ")) (search-forward (concat "\n" osubfile ": "))
;; Skip that one. ;; Skip that one.
(forward-line 1) (forward-line (if backward 0 1))
;; Make a list of all following subfiles. ;; Make a list of all following subfiles.
;; Each elt has the form (VIRT-POSITION . SUBFILENAME). ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
(while (not (eobp)) (while (not (if backward (bobp) (eobp)))
(re-search-forward "\\(^.*\\): [0-9]+$") (if backward
(re-search-backward "\\(^.*\\): [0-9]+$")
(re-search-forward "\\(^.*\\): [0-9]+$"))
(goto-char (+ (match-end 1) 2)) (goto-char (+ (match-end 1) 2))
(setq list (cons (cons (+ (point-min) (setq list (cons (cons (+ (point-min)
(read (current-buffer))) (read (current-buffer)))
(match-string-no-properties 1)) (match-string-no-properties 1))
list)) list))
(goto-char (1+ (match-end 0)))) (goto-char (if backward
(1- (match-beginning 0))
(1+ (match-end 0)))))
;; Put in forward order ;; Put in forward order
(setq list (nreverse list)))) (setq list (nreverse list))))
(while list (while list
(message "Searching subfile %s..." (cdr (car list))) (message "Searching subfile %s..." (cdr (car list)))
(Info-read-subfile (car (car list))) (Info-read-subfile (car (car list)))
(if backward (goto-char (point-max)))
(setq list (cdr list)) (setq list (cdr list))
(setq give-up nil found nil) (setq give-up nil found nil)
(while (and (not give-up) (while (and (not give-up)
(or (null found) (or (null found)
(isearch-range-invisible beg-found found))) (if backward
(if (re-search-forward regexp nil t) (isearch-range-invisible found beg-found)
(setq found (point) beg-found (match-beginning 0)) (isearch-range-invisible beg-found found))))
(if (if backward
(re-search-backward regexp nil t)
(re-search-forward regexp nil t))
(setq found (point) beg-found (if backward (match-end 0)
(match-beginning 0)))
(setq give-up t))) (setq give-up t)))
(if give-up (if give-up
(setq found nil)) (setq found nil))
...@@ -1534,12 +1556,20 @@ If FORK is a string, it is the name to use for the new buffer." ...@@ -1534,12 +1556,20 @@ If FORK is a string, it is the name to use for the new buffer."
(goto-char opoint) (goto-char opoint)
(Info-select-node) (Info-select-node)
(set-window-start (selected-window) ostart))))) (set-window-start (selected-window) ostart)))))
(widen)
(goto-char found) (if (and (string= osubfile Info-current-subfile)
(Info-select-node) (> found opoint-min)
(< found opoint-max))
;; Search landed in the same node
(goto-char found)
(widen)
(goto-char found)
(save-match-data (Info-select-node)))
;; Use string-equal, not equal, to ignore text props. ;; Use string-equal, not equal, to ignore text props.
(or (and (string-equal onode Info-current-node) (or (and (string-equal onode Info-current-node)
(equal ofile Info-current-file)) (equal ofile Info-current-file))
(and isearch-mode isearch-wrapped (eq opoint opoint-min))
(setq Info-history (cons (list ofile onode opoint) (setq Info-history (cons (list ofile onode opoint)
Info-history)))))) Info-history))))))
...@@ -1556,6 +1586,48 @@ If FORK is a string, it is the name to use for the new buffer." ...@@ -1556,6 +1586,48 @@ If FORK is a string, it is the name to use for the new buffer."
(if Info-search-history (if Info-search-history
(Info-search (car Info-search-history)) (Info-search (car Info-search-history))
(call-interactively 'Info-search)))) (call-interactively 'Info-search))))
(defun Info-search-backward (regexp &optional bound noerror count)
"Search for REGEXP in the reverse direction."
(interactive (list (read-string
(if Info-search-history
(format "Regexp search%s backward (default `%s'): "
(if case-fold-search "" " case-sensitively")
(car Info-search-history))
(format "Regexp search%s backward: "
(if case-fold-search "" " case-sensitively")))
nil 'Info-search-history)))
(Info-search regexp bound noerror count 'backward))
(defun Info-isearch-search ()
(cond
(isearch-word
(if isearch-forward 'word-search-forward 'word-search-backward))
(isearch-regexp
(lambda (regexp bound noerror)
(condition-case nil
(progn
(Info-search regexp bound noerror nil
(unless isearch-forward 'backward))
(point))
(error nil))))
(t
(if isearch-forward 'search-forward 'search-backward))))
(defun Info-isearch-wrap ()
(if isearch-regexp
(if isearch-forward (Info-top-node) (Info-final-node))
(goto-char (if isearch-forward (point-min) (point-max)))))
(defun Info-isearch-push-state ()
`(lambda (cmd)
(Info-isearch-pop-state cmd ,Info-current-file ,Info-current-node)))
(defun Info-isearch-pop-state (cmd file node)
(or (and (string= Info-current-file file)
(string= Info-current-node node))
(progn (Info-find-node file node) (sit-for 0))))
(defun Info-extract-pointer (name &optional errorname) (defun Info-extract-pointer (name &optional errorname)
"Extract the value of the node-pointer named NAME. "Extract the value of the node-pointer named NAME.
...@@ -3064,6 +3136,14 @@ Advanced commands: ...@@ -3064,6 +3136,14 @@ Advanced commands:
(setq desktop-save-buffer 'Info-desktop-buffer-misc-data) (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
(add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t) (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
(add-hook 'change-major-mode-hook 'font-lock-defontify nil t) (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
(set (make-local-variable 'isearch-search-fun-function)
'Info-isearch-search)
(set (make-local-variable 'isearch-wrap-function)
'Info-isearch-wrap)
(set (make-local-variable 'isearch-push-state-function)
'Info-isearch-push-state)
(set (make-local-variable 'search-whitespace-regexp)
Info-search-whitespace-regexp)
(Info-set-mode-line) (Info-set-mode-line)
(run-hooks 'Info-mode-hook)) (run-hooks 'Info-mode-hook))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment