From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: [jonathangoldblatt@yahoo.com: Bug/Patch view.el] Date: Fri, 14 Sep 2007 03:04:18 -0400 Message-ID: Reply-To: rms@gnu.org NNTP-Posting-Host: lo.gmane.org Content-Type: text/plain; charset=ISO-8859-15 X-Trace: sea.gmane.org 1189755400 10197 80.91.229.12 (14 Sep 2007 07:36:40 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 14 Sep 2007 07:36:40 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Sep 14 09:36:39 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IW5j6-0007Lv-KD for ged-emacs-devel@m.gmane.org; Fri, 14 Sep 2007 09:36:33 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IW5j5-0001kf-V8 for ged-emacs-devel@m.gmane.org; Fri, 14 Sep 2007 03:36:32 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IW5dw-0007Dk-IH for emacs-devel@gnu.org; Fri, 14 Sep 2007 03:31:12 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IW5dt-0007Bn-RD for emacs-devel@gnu.org; Fri, 14 Sep 2007 03:31:11 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IW5dt-0007BS-DI for emacs-devel@gnu.org; Fri, 14 Sep 2007 03:31:09 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IW5dr-0005J6-Qc for emacs-devel@gnu.org; Fri, 14 Sep 2007 03:31:08 -0400 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.60) (envelope-from ) id 1IW5Du-000555-Q6; Fri, 14 Sep 2007 03:04:18 -0400 X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:78839 Archived-At: Can someone please test this on EMACS_22_BASE and say whether the bug still exists? ------- Start of forwarded message ------- Date: Wed, 12 Sep 2007 15:52:01 EST X-Spam-Status: No, score=1.4 required=5.0 tests=DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_WHOIS,UNPARSEABLE_RELAY autolearn=no version=3.1.0 Resent-To: bug-gnu-emacs@gnu.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii From: Jonathan Goldblatt To: bug-gnu-emacs@gnu.org Resent-From: Jonathan Goldblatt Subject: Bug/Patch view.el 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) ------- End of forwarded message -------