aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorKarl Heuer1998-01-18 02:53:16 +0000
committerKarl Heuer1998-01-18 02:53:16 +0000
commit0f0a7f7cf462fb6f30e753e430966204bd3daba1 (patch)
tree73a3a7c24dd8c17b8a63c38434a778bb6c500b45 /lisp/replace.el
parent0c4b86dac8b03efbc25977ed7ea5096a46948c12 (diff)
downloademacs-0f0a7f7cf462fb6f30e753e430966204bd3daba1.tar.gz
emacs-0f0a7f7cf462fb6f30e753e430966204bd3daba1.zip
(occur): If the matching line has no final newline,
insert one anyway. Compensate for that when inserting line nums.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el21
1 files changed, 17 insertions, 4 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index bfe47d20d6c..b38a8165720 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -491,6 +491,7 @@ the matching is case-sensitive."
491 (tag (format "%5d" linenum)) 491 (tag (format "%5d" linenum))
492 (empty (make-string (length tag) ?\ )) 492 (empty (make-string (length tag) ?\ ))
493 tem 493 tem
494 insertion-start
494 ;; Number of lines of context to show for current match. 495 ;; Number of lines of context to show for current match.
495 occur-marker 496 occur-marker
496 ;; Marker pointing to end of match in source buffer. 497 ;; Marker pointing to end of match in source buffer.
@@ -515,7 +516,21 @@ the matching is case-sensitive."
515 ;; Insert matching text including context lines from 516 ;; Insert matching text including context lines from
516 ;; source buffer into *Occur* 517 ;; source buffer into *Occur*
517 (set-marker text-beg (point)) 518 (set-marker text-beg (point))
519 (setq insertion-start (point))
518 (insert-buffer-substring buffer start end) 520 (insert-buffer-substring buffer start end)
521 (or (and (/= (+ start match-beg) end)
522 (with-current-buffer buffer
523 (eq (char-before end) ?\n)))
524 (insert "\n"))
525 (set-marker final-context-start
526 (+ (- (point) (- end (match-end 0)))
527 (if (save-excursion
528 (set-buffer buffer)
529 (save-excursion
530 (goto-char (match-end 0))
531 (end-of-line)
532 (bolp)))
533 1 0)))
519 (set-marker text-end (point)) 534 (set-marker text-end (point))
520 535
521 ;; Highlight text that was matched. 536 ;; Highlight text that was matched.
@@ -531,12 +546,10 @@ the matching is case-sensitive."
531 (+ (marker-position text-beg) match-beg match-len) 546 (+ (marker-position text-beg) match-beg match-len)
532 (+ (marker-position text-beg) match-beg match-len 1) 547 (+ (marker-position text-beg) match-beg match-len 1)
533 'occur-point t) 548 'occur-point t)
534 (set-marker final-context-start
535 (- (point) (- end (match-end 0))))
536 549
537 ;; Now go back to the start of the matching text 550 ;; Now go back to the start of the matching text
538 ;; adding the space and colon to the start of each line. 551 ;; adding the space and colon to the start of each line.
539 (goto-char (- (point) (- end start))) 552 (goto-char insertion-start)
540 ;; Insert space and colon for lines of context before match. 553 ;; Insert space and colon for lines of context before match.
541 (setq tem (if (< linenum nlines) 554 (setq tem (if (< linenum nlines)
542 (- nlines linenum) 555 (- nlines linenum)
@@ -556,7 +569,7 @@ the matching is case-sensitive."
556 (forward-line 1) 569 (forward-line 1)
557 (setq tag nil) 570 (setq tag nil)
558 (setq this-linenum (1+ this-linenum))) 571 (setq this-linenum (1+ this-linenum)))
559 (while (<= (point) final-context-start) 572 (while (and (not (eobp)) (<= (point) final-context-start))
560 (insert empty ?:) 573 (insert empty ?:)
561 (forward-line 1) 574 (forward-line 1)
562 (setq this-linenum (1+ this-linenum)))) 575 (setq this-linenum (1+ this-linenum))))