From: Jonathan Goldblatt <jonathangoldblatt@yahoo.com>
To: bug-gnu-emacs@gnu.org
Subject: Bug/Patch view.el
Date: Wed, 12 Sep 2007 19:52:21 +0000 (UTC) [thread overview]
Message-ID: <45268.0611204871$1189626740@news.gmane.org> (raw)
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 <jonathangoldblatt@yahoo.com>
* 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)
next reply other threads:[~2007-09-12 19:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-12 19:52 Jonathan Goldblatt [this message]
[not found] <1t8x7bfyoe.fsf@totally-fudged-out-message-id>
2007-09-22 18:39 ` Bug/Patch view.el Glenn Morris
2007-09-24 11:35 ` Jonathan Goldblatt
2007-09-24 19:31 ` Glenn Morris
2007-09-25 2:30 ` Glenn Morris
2007-09-25 7:06 ` Glenn Morris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='45268.0611204871$1189626740@news.gmane.org' \
--to=jonathangoldblatt@yahoo.com \
--cc=bug-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.