From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jonathan Goldblatt Newsgroups: gmane.emacs.bugs Subject: Bug/Patch view.el Date: Wed, 12 Sep 2007 19:52:21 +0000 (UTC) Message-ID: <45268.0611204871$1189626740@news.gmane.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1189626741 974 80.91.229.12 (12 Sep 2007 19:52:21 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 12 Sep 2007 19:52:21 +0000 (UTC) To: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 12 21:52:18 2007 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IVYFx-0003T8-DQ for geb-bug-gnu-emacs@m.gmane.org; Wed, 12 Sep 2007 21:52:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IVYFx-0001Eq-5F for geb-bug-gnu-emacs@m.gmane.org; Wed, 12 Sep 2007 15:52:13 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IVYFt-0001EI-PM for bug-gnu-emacs@gnu.org; Wed, 12 Sep 2007 15:52:09 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IVYFr-0001DM-MQ for bug-gnu-emacs@gnu.org; Wed, 12 Sep 2007 15:52:09 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IVYFr-0001DG-Dk for bug-gnu-emacs@gnu.org; Wed, 12 Sep 2007 15:52:07 -0400 Original-Received: from smtp101.plus.mail.re1.yahoo.com ([69.147.102.64]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1IVYFq-0000Mq-TD for bug-gnu-emacs@gnu.org; Wed, 12 Sep 2007 15:52:07 -0400 Original-Received: (qmail 93141 invoked from network); 12 Sep 2007 19:52:05 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-YMail-OSG:Received:Resent-Message-ID:Resent-Date:Resent-To:MIME-Version:Content-Type:Content-Transfer-Encoding:From:To:Subject:X-YMail-OSG:X-Mailer:Resent-From; b=6dzXzFXR6a6DJoJlkzFEP7bv+hEBWBFPwc4A8Bedel5bAcOJkkGuFriqw4T3PmTGe3VDjHM9nQR7YPgKR9Kjqe97H4KlL4lE3w/QMmCXSg02EsRLq+6hSJYUep+LmLAgoQ029anfTk4UuVYrJSkWbpEarIrcWYCPyFrh/I7DHag= ; Original-Received: from unknown (HELO tower.localdomain) (pseudonymous6@76.160.64.172 with plain) by smtp101.plus.mail.re1.yahoo.com with SMTP; 12 Sep 2007 19:52:05 -0000 X-YMail-OSG: Y3if0CMVM1kW6Z8DGAItOvSX8Dd6f_EgkrrTmcdEVtbPcAQMkl9uO0V3J58ieHRsF8OPFMKH2w-- Original-Received: from jonathan by tower.localdomain with local (Exim 4.50) id 1IVYFo-0001c8-1c for bug-gnu-emacs@gnu.org; Wed, 12 Sep 2007 15:52:04 -0400 Resent-Message-ID: <18152.17251.853581.603425@tower.localdomain> Resent-Date: Wed, 12 Sep 2007 15:52:03 -0400 Resent-To: bug-gnu-emacs@gnu.org X-YMail-OSG: XYHtYGUVM1lEagbr0ziCX_mPR7lOMlUqjK5CXatc7N6A.8O3d0vOpCHaLVoHRYaCp0SmYzHVzw-- X-Mailer: VM 7.18 under Emacs 21.4.1 Resent-From: Jonathan Goldblatt X-Detected-Kernel: FreeBSD 4.7-5.2 (or MacOS X 10.2-10.4) (2) X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:16544 Archived-At: Here is a little test script that demonstrates some problems in view-search-no-match-lines followed by a patch to replace it. Just run the form to see the anomalies. It generates a file that contains many lines "abc" with a very few "123" lines interspered. If you do /!a looking for a non-abc line you wind up with the highlight on the line after the 123 line. If you do it twice and then try to go backwards with a p, the previous hit isn't found at all?? The test script also shows problems with sit-for in a windowed environment. If you just do a sit-for it doesn't wait at all. It seems like the work-around of doing a short sit-for followed by another sit-for seems to wait much longer than the specified time. Also tried to use display-buffer with a specified frame and didn't get the test buffer showing up in the new frame?? This was on Linux version 2.4.21 (root@xeon.localdomain) (gcc version 3.2.3 20030316 (Debian prerelease)) #1 Sat Mar 13 13:25:10 EST 2004 GNU Emacs 21.4.1 (i386-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2005-03-17 on trouble, modified by Debian Hope this helps. Test script: (let* ((test-buffer (generate-new-buffer "test")) (test-frame (let ((pop-up-frames t)) (pop-to-buffer test-buffer 't) (window-frame (selected-window)))) (i 1) (j 1)) (progn (with-current-buffer test-buffer (while (< j 4) (while (< i 200) (insert "abc\n") (setq i (1+ i))) (insert "123\n") (setq i 1) (setq j (1+ j))) (view-mode) (goto-char (point-min)) (View-search-regexp-forward 1 "!a") (message "Simulated /!a.in view mode. Notice highlight one line too far. Line 200 is \"123\" Press any key to continue.") (sit-for 1) (if (not(sit-for 60)) (read-char)) (View-search-last-regexp-forward 1) (message "Simulated n. Notice highlight one line too far. Current line is 401. Press any key to continue.") (sit-for 1) (if (not(sit-for 60)) (read-char)) (View-search-last-regexp-backward 1) (sit-for 1) (if (not(sit-for 5)) (read-char)) (message "That was a simulated p. Notice can't find line 200?!. Press any key to end.") (sit-for 1) (if (not(sit-for 60)) (read-char)) (if (y-or-n-p "Remove buffer?") (kill-buffer test-buffer)) (if (y-or-n-p "Remove frame?") (delete-frame test-frame))))) Here's the patch: 2007-09-12 Jonathan Goldblatt * view.el (view-search-no-match-lines): Rewrote to work in more, possibly all, cases. *** /usr/share/emacs/21.4/lisp/view.el Tue Sep 4 08:52:36 2001 --- /home/jonathan/.emacs.d/lisp/view.el Thu Sep 6 16:37:46 2007 *************** *** 972,995 **** (defun view-search-no-match-lines (times regexp) ;; Search for the TIMESt occurrence of line with no match for REGEXP. ! (let ((back (and (< times 0) (setq times (- times)) -1)) ! n) ! (while (> times 0) ! (save-excursion (beginning-of-line (if back (- times) (1+ times))) ! (setq n (point))) ! (setq times ! (cond ! ((< (count-lines (point) n) times) -1) ; Not enough lines. ! ((or (null (re-search-forward regexp nil t back)) ! (if back (and (< (match-end 0) n) ! (> (count-lines (match-end 0) n) 1)) ! (and (< n (match-beginning 0)) ! (> (count-lines n (match-beginning 0)) 1)))) ! 0) ; No match within lines. ! (back (count-lines (max n (match-beginning 0)) (match-end 0))) ! (t (count-lines (match-beginning 0) (min n (match-end 0)))))) ! (goto-char n)) ! (and (zerop times) (looking-at "^.*$")))) (provide 'view) --- 987,1026 ---- (defun view-search-no-match-lines (times regexp) ;; Search for the TIMESt occurrence of line with no match for REGEXP. ! ;; times > 0 for forward search; < 0 for backward search ! (let ((count (abs times)) ! (hit-count 0) ! (fwd-one ;parm used by forward-line to ! ;move 1 line in search ! ;direction ! (if (> times 0) 1 -1)) ! (bkwd-one ;parm used by forward-line to ! ;move 1 line in opposite ! ;direction of search ! (if (> times 0) -1 1)) ! end-search ! searching) ! (while (> count 0) ! (setq searching 't) ! (while searching ! (forward-line fwd-one) ! (if (/= 0 (forward-line fwd-one)) ;not bob or eob ! (setq searching 'nil ! count 0) ! (forward-line bkwd-one) ! (forward-line 1) ! (setq end-search (point)) ! (forward-line -1) ;reset point ! (setq searching (re-search-forward regexp end-search 't)) ! (if (not searching) ! (progn ! (forward-line 0) ! (setq hit-count (1+ hit-count)))))) ! (setq count (1- count))) ! (re-search-forward "^.*\n" (point-max) 't) ; setup to highlight ! ; line ! (forward-line -1) ; reset point after search ! (= hit-count (abs times)))) (provide 'view)