Commit 5aca5ac3 authored by Glenn Morris's avatar Glenn Morris
Browse files

(view-search-no-match-lines): Add a doc string. Rewrite to simplify

and work better.
parent 17ee4625
2007-09-25 Glenn Morris <rgm@gnu.org>
* view.el (view-search-no-match-lines): Add a doc string.
Rewrite to simplify and work better.
2007-09-24 Dan Nicolaescu <dann@ics.uci.edu> 2007-09-24 Dan Nicolaescu <dann@ics.uci.edu>
* progmodes/cc-mode.el (c-mode-base-map): Use * progmodes/cc-mode.el (c-mode-base-map): Use
......
...@@ -990,27 +990,30 @@ for highlighting the match that is found." ...@@ -990,27 +990,30 @@ for highlighting the match that is found."
times (if no "no " "") regexp) times (if no "no " "") regexp)
(sit-for 4)))) (sit-for 4))))
;; This is the dumb approach, looking at each line. The original
;; version of this function looked like it might have been trying to
;; do something clever, but not succeeding:
;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-09/msg00073.html
(defun view-search-no-match-lines (times regexp) (defun view-search-no-match-lines (times regexp)
;; Search for the TIMESt occurrence of line with no match for REGEXP. "Search for the TIMESth occurrence of a line with no match for REGEXP.
(let ((back (and (< times 0) (setq times (- times)) -1)) If such a line is found, return non-nil and set the match-data to that line.
n) If TIMES is negative, search backwards."
(while (> times 0) (let ((step 1)
(save-excursion (beginning-of-line (if back (- times) (1+ times))) (noerror 'move))
(setq n (point))) (when (< times 0)
(setq times (setq times (- times)
(cond step -1
((< (count-lines (point) n) times) -1) ; Not enough lines. noerror t))
((or (null (re-search-forward regexp nil t back)) ;; Note that we do not check the current line.
(if back (and (< (match-end 0) n) (while (and (> times 0)
(> (count-lines (match-end 0) n) 1)) (zerop (forward-line step)))
(and (< n (match-beginning 0)) ;; Move only to handle eob in the forward case: on last line,
(> (count-lines n (match-beginning 0)) 1)))) ;; (forward-line 1) returns 0 before the end of line.
0) ; No match within lines. (or (re-search-forward regexp (line-end-position) noerror)
(back (count-lines (max n (match-beginning 0)) (match-end 0))) (setq times (1- times)))))
(t (count-lines (match-beginning 0) (min n (match-end 0)))))) (when (zerop times)
(goto-char n)) (forward-line 0)
(and (zerop times) (looking-at "^.*$")))) (looking-at ".*")))
(provide 'view) (provide 'view)
......
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