Mercurial > emacs
comparison lisp/view.el @ 78890:77e66005aa88
(view-search-no-match-lines): Add a doc string. Rewrite to simplify
and work better.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 25 Sep 2007 02:27:03 +0000 |
parents | 7c8949dbfa0d |
children | f8144f59d4b3 |
comparison
equal
deleted
inserted
replaced
78889:45d26d6ca9ec | 78890:77e66005aa88 |
---|---|
988 (view-recenter)) | 988 (view-recenter)) |
989 (message "Can't find occurrence %d of %s%s" | 989 (message "Can't find occurrence %d of %s%s" |
990 times (if no "no " "") regexp) | 990 times (if no "no " "") regexp) |
991 (sit-for 4)))) | 991 (sit-for 4)))) |
992 | 992 |
993 ;; This is the dumb approach, looking at each line. The original | |
994 ;; version of this function looked like it might have been trying to | |
995 ;; do something clever, but not succeeding: | |
996 ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-09/msg00073.html | |
993 (defun view-search-no-match-lines (times regexp) | 997 (defun view-search-no-match-lines (times regexp) |
994 ;; Search for the TIMESt occurrence of line with no match for REGEXP. | 998 "Search for the TIMESth occurrence of a line with no match for REGEXP. |
995 (let ((back (and (< times 0) (setq times (- times)) -1)) | 999 If such a line is found, return non-nil and set the match-data to that line. |
996 n) | 1000 If TIMES is negative, search backwards." |
997 (while (> times 0) | 1001 (let ((step 1) |
998 (save-excursion (beginning-of-line (if back (- times) (1+ times))) | 1002 (noerror 'move)) |
999 (setq n (point))) | 1003 (when (< times 0) |
1000 (setq times | 1004 (setq times (- times) |
1001 (cond | 1005 step -1 |
1002 ((< (count-lines (point) n) times) -1) ; Not enough lines. | 1006 noerror t)) |
1003 ((or (null (re-search-forward regexp nil t back)) | 1007 ;; Note that we do not check the current line. |
1004 (if back (and (< (match-end 0) n) | 1008 (while (and (> times 0) |
1005 (> (count-lines (match-end 0) n) 1)) | 1009 (zerop (forward-line step))) |
1006 (and (< n (match-beginning 0)) | 1010 ;; Move only to handle eob in the forward case: on last line, |
1007 (> (count-lines n (match-beginning 0)) 1)))) | 1011 ;; (forward-line 1) returns 0 before the end of line. |
1008 0) ; No match within lines. | 1012 (or (re-search-forward regexp (line-end-position) noerror) |
1009 (back (count-lines (max n (match-beginning 0)) (match-end 0))) | 1013 (setq times (1- times))))) |
1010 (t (count-lines (match-beginning 0) (min n (match-end 0)))))) | 1014 (when (zerop times) |
1011 (goto-char n)) | 1015 (forward-line 0) |
1012 (and (zerop times) (looking-at "^.*$")))) | 1016 (looking-at ".*"))) |
1013 | |
1014 | 1017 |
1015 (provide 'view) | 1018 (provide 'view) |
1016 | 1019 |
1017 ;;; arch-tag: 6d0ace36-1d12-4de3-8de3-1fa3231636d7 | 1020 ;;; arch-tag: 6d0ace36-1d12-4de3-8de3-1fa3231636d7 |
1018 ;;; view.el ends here | 1021 ;;; view.el ends here |