aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorRichard M. Stallman1997-07-25 22:21:49 +0000
committerRichard M. Stallman1997-07-25 22:21:49 +0000
commite09d403394b2b79312f60b0f80a898ed8d74658a (patch)
tree5960c7b578536659c238ad420d306df6a12301d9 /lisp/replace.el
parentf26d8cd6e82f1ae7bc0041b4337b0aea27884f63 (diff)
downloademacs-e09d403394b2b79312f60b0f80a898ed8d74658a.tar.gz
emacs-e09d403394b2b79312f60b0f80a898ed8d74658a.zip
(occur): Local variable line-start redundant.
`occur-marker' extends to the end of the line rather than one char before end.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el98
1 files changed, 70 insertions, 28 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index a13916bf280..3d5b012f43a 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -250,8 +250,14 @@ Applies to lines after point."
250 (define-key occur-mode-map "\M-p" 'occur-prev) 250 (define-key occur-mode-map "\M-p" 'occur-prev)
251 (define-key occur-mode-map "g" 'revert-buffer)) 251 (define-key occur-mode-map "g" 'revert-buffer))
252 252
253(defvar occur-buffer nil) 253
254(defvar occur-nlines nil) 254(defvar occur-buffer nil
255 "Name of buffer for last occur.")
256
257
258(defvar occur-nlines nil
259 "Number of lines of context to show around matching line.")
260
255(defvar occur-command-arguments nil 261(defvar occur-command-arguments nil
256 "Arguments that were given to `occur' when it made this buffer.") 262 "Arguments that were given to `occur' when it made this buffer.")
257 263
@@ -393,14 +399,20 @@ the matching is case-sensitive."
393 (prefix-numeric-value nlines) 399 (prefix-numeric-value nlines)
394 list-matching-lines-default-context-lines)) 400 list-matching-lines-default-context-lines))
395 (first t) 401 (first t)
402 ;;flag to prevent printing separator for first match
396 (occur-num-matches 0) 403 (occur-num-matches 0)
397 (buffer (current-buffer)) 404 (buffer (current-buffer))
398 (dir default-directory) 405 (dir default-directory)
399 (linenum 1) 406 (linenum 1)
400 (prevpos (point-min)) 407 (prevpos
408 ;;position of most recent match
409 (point-min))
401 (case-fold-search (and case-fold-search 410 (case-fold-search (and case-fold-search
402 (isearch-no-upper-case-p regexp t))) 411 (isearch-no-upper-case-p regexp t)))
403 (final-context-start (make-marker))) 412 (final-context-start
413 ;; Marker to the start of context immediately following
414 ;; the matched text in *Occur*.
415 (make-marker)))
404;;; (save-excursion 416;;; (save-excursion
405;;; (beginning-of-line) 417;;; (beginning-of-line)
406;;; (setq linenum (1+ (count-lines (point-min) (point)))) 418;;; (setq linenum (1+ (count-lines (point-min) (point))))
@@ -438,24 +450,44 @@ the matching is case-sensitive."
438 (setq linenum (+ linenum (count-lines prevpos (point))))) 450 (setq linenum (+ linenum (count-lines prevpos (point)))))
439 (setq prevpos (point)) 451 (setq prevpos (point))
440 (goto-char (match-end 0)) 452 (goto-char (match-end 0))
441 (let* ((start (save-excursion 453 (let* ((start
454 ;;start point of text in source buffer to be put
455 ;;into *Occur*
456 (save-excursion
442 (goto-char (match-beginning 0)) 457 (goto-char (match-beginning 0))
443 (forward-line (if (< nlines 0) nlines (- nlines))) 458 (forward-line (if (< nlines 0)
459 nlines
460 (- nlines)))
444 (point))) 461 (point)))
445 (end (save-excursion 462 (end
446 (goto-char (match-end 0)) 463 ;; end point of text in source buffer to be put
447 (if (> nlines 0) 464 ;; into *Occur*
448 (forward-line (1+ nlines)) 465 (save-excursion
449 (forward-line 1)) 466 (goto-char (match-end 0))
450 (point))) 467 (if (> nlines 0)
451 (match-beg (- (match-beginning 0) start)) 468 (forward-line (1+ nlines))
452 (match-len (- (match-end 0) (match-beginning 0))) 469 (forward-line 1))
470 (point)))
471 (match-beg
472 ;; Amount of context before matching text
473 (- (match-beginning 0) start))
474 (match-len
475 ;; Length of matching text
476 (- (match-end 0) (match-beginning 0)))
453 (tag (format "%5d" linenum)) 477 (tag (format "%5d" linenum))
454 (empty (make-string (length tag) ?\ )) 478 (empty (make-string (length tag) ?\ ))
455 tem 479 tem
456 occur-marker 480 ;; Number of lines of context to show for current match.
457 (text-beg (make-marker)) 481 occur-marker
458 (text-end (make-marker)) 482 ;; Marker pointing to end of match in source buffer.
483 (text-beg
484 ;; Marker pointing to start of text for one
485 ;; match in *Occur*.
486 (make-marker))
487 (text-end
488 ;; Marker pointing to end of text for one match
489 ;; in *Occur*.
490 (make-marker))
459 ) 491 )
460 (save-excursion 492 (save-excursion
461 (setq occur-marker (make-marker)) 493 (setq occur-marker (make-marker))
@@ -465,25 +497,33 @@ the matching is case-sensitive."
465 (or first (zerop nlines) 497 (or first (zerop nlines)
466 (insert "--------\n")) 498 (insert "--------\n"))
467 (setq first nil) 499 (setq first nil)
500
501 ;; Insert matching text including context lines from
502 ;; source buffer into *Occur*
468 (set-marker text-beg (point)) 503 (set-marker text-beg (point))
469 (insert-buffer-substring buffer start end) 504 (insert-buffer-substring buffer start end)
470 (set-marker text-end (point)) 505 (set-marker text-end (point))
506
507 ;; Highlight text that was matched.
471 (if list-matching-lines-face 508 (if list-matching-lines-face
472 (put-text-property 509 (put-text-property
473 (+ (marker-position text-beg) match-beg) 510 (+ (marker-position text-beg) match-beg)
474 (+ (marker-position text-beg) match-beg match-len) 511 (+ (marker-position text-beg) match-beg match-len)
475 'face list-matching-lines-face)) 512 'face list-matching-lines-face))
476 513
477 ;; Identify a place for occur-next and occur-prev 514 ;; `occur-point' property is used by occur-next and
478 ;; to move to. 515 ;; occur-prev to move between matching lines.
479 (put-text-property 516 (put-text-property
480 (+ (marker-position text-beg) match-beg match-len) 517 (+ (marker-position text-beg) match-beg match-len)
481 (+ (marker-position text-beg) match-beg match-len 1) 518 (+ (marker-position text-beg) match-beg match-len 1)
482 'occur-point t) 519 'occur-point t)
483 (set-marker final-context-start 520 (set-marker final-context-start
484 (- (point) (- end (match-end 0)))) 521 (- (point) (- end (match-end 0))))
522
523 ;; Now go back to the start of the matching text
524 ;; adding the space and colon to the start of each line.
485 (goto-char (- (point) (- end start))) 525 (goto-char (- (point) (- end start)))
486 ;;(setq tem nlines) 526 ;; Insert space and colon for lines of context before match.
487 (setq tem (if (< linenum nlines) 527 (setq tem (if (< linenum nlines)
488 (- nlines linenum) 528 (- nlines linenum)
489 nlines)) 529 nlines))
@@ -491,16 +531,14 @@ the matching is case-sensitive."
491 (insert empty ?:) 531 (insert empty ?:)
492 (forward-line 1) 532 (forward-line 1)
493 (setq tem (1- tem))) 533 (setq tem (1- tem)))
494 (let ((this-linenum linenum) 534
495 line-start) 535 ;; Insert line number and colon for the lines of
536 ;; matching text.
537 (let ((this-linenum linenum))
496 (while (< (point) final-context-start) 538 (while (< (point) final-context-start)
497 (if (null tag) 539 (if (null tag)
498 (setq tag (format "%5d" this-linenum))) 540 (setq tag (format "%5d" this-linenum)))
499 (insert tag ?:) 541 (insert tag ?:)
500 (setq line-start
501 (save-excursion
502 (beginning-of-line)
503 (point)))
504 (forward-line 1) 542 (forward-line 1)
505 (setq tag nil) 543 (setq tag nil)
506 (setq this-linenum (1+ this-linenum))) 544 (setq this-linenum (1+ this-linenum)))
@@ -508,6 +546,8 @@ the matching is case-sensitive."
508 (insert empty ?:) 546 (insert empty ?:)
509 (forward-line 1) 547 (forward-line 1)
510 (setq this-linenum (1+ this-linenum)))) 548 (setq this-linenum (1+ this-linenum))))
549
550 ;; Insert space and colon for lines of context after match.
511 (while (and (< (point) (point-max)) (< tem nlines)) 551 (while (and (< (point) (point-max)) (< tem nlines))
512 (insert empty ?:) 552 (insert empty ?:)
513 (forward-line 1) 553 (forward-line 1)
@@ -520,11 +560,13 @@ the matching is case-sensitive."
520 (- (marker-position text-end) 1) 560 (- (marker-position text-end) 1)
521 'mouse-face 'highlight) 561 'mouse-face 'highlight)
522 (put-text-property (marker-position text-beg) 562 (put-text-property (marker-position text-beg)
523 (- (marker-position text-end) 1) 563 (marker-position text-end)
524 'occur occur-marker) 564 'occur occur-marker)
525 (goto-char (point-max))) 565 (goto-char (point-max)))
526 (forward-line 1))) 566 (forward-line 1)))
527 (set-buffer standard-output) 567 (set-buffer standard-output)
568 ;; Go back to top of *Occur* and finish off by printing the
569 ;; number of matching lines.
528 (goto-char (point-min)) 570 (goto-char (point-min))
529 (let ((message-string 571 (let ((message-string
530 (if (= occur-num-matches 1) 572 (if (= occur-num-matches 1)