aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorJuri Linkov2004-12-16 13:17:32 +0000
committerJuri Linkov2004-12-16 13:17:32 +0000
commitf1f007dc5b598aae3dec020a26afb94c2b2d3fd2 (patch)
tree8636b502d548c16bc96aaf5229d5e7829c47dbfa /lisp/replace.el
parent8b18fb8fff58f0063ae8500a62eafb09434676c3 (diff)
downloademacs-f1f007dc5b598aae3dec020a26afb94c2b2d3fd2.tar.gz
emacs-f1f007dc5b598aae3dec020a26afb94c2b2d3fd2.zip
(occur-accumulate-lines, occur-engine):
Fontify unfontified matching lines in the source buffer before copying them. (occur-engine): Don't put mouse-face on context lines. (occur-next-error): Set point to line beginning/end before searching for prev/next property to skip multiple matches on a line (not supported by occur engine). Remove redundant prefix-numeric-value.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el66
1 files changed, 36 insertions, 30 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 872e5e290a8..8f81a53bf7e 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -735,16 +735,17 @@ Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
735Compatibility function for \\[next-error] invocations." 735Compatibility function for \\[next-error] invocations."
736 (interactive "p") 736 (interactive "p")
737 ;; we need to run occur-find-match from within the Occur buffer 737 ;; we need to run occur-find-match from within the Occur buffer
738 (with-current-buffer 738 (with-current-buffer
739 (if (next-error-buffer-p (current-buffer)) 739 (if (next-error-buffer-p (current-buffer))
740 (current-buffer) 740 (current-buffer)
741 (next-error-find-buffer nil nil (lambda() (eq major-mode 'occur-mode)))) 741 (next-error-find-buffer nil nil (lambda() (eq major-mode 'occur-mode))))
742 742
743 (when reset 743 (goto-char (cond (reset (point-min))
744 (goto-char (point-min))) 744 ((< argp 0) (line-beginning-position))
745 ((line-end-position))))
745 (occur-find-match 746 (occur-find-match
746 (abs (prefix-numeric-value argp)) 747 (abs argp)
747 (if (> 0 (prefix-numeric-value argp)) 748 (if (> 0 argp)
748 #'previous-single-property-change 749 #'previous-single-property-change
749 #'next-single-property-change) 750 #'next-single-property-change)
750 "No more matches") 751 "No more matches")
@@ -790,18 +791,22 @@ If the value is nil, don't highlight the buffer names specially."
790(defun occur-accumulate-lines (count &optional keep-props) 791(defun occur-accumulate-lines (count &optional keep-props)
791 (save-excursion 792 (save-excursion
792 (let ((forwardp (> count 0)) 793 (let ((forwardp (> count 0))
793 (result nil)) 794 result beg end)
794 (while (not (or (zerop count) 795 (while (not (or (zerop count)
795 (if forwardp 796 (if forwardp
796 (eobp) 797 (eobp)
797 (bobp)))) 798 (bobp))))
798 (setq count (+ count (if forwardp -1 1))) 799 (setq count (+ count (if forwardp -1 1)))
800 (setq beg (line-beginning-position)
801 end (line-end-position))
802 (if (and keep-props font-lock-mode
803 (text-property-not-all beg end 'fontified t))
804 (font-lock-fontify-region beg end))
799 (push 805 (push
800 (funcall (if keep-props 806 (funcall (if keep-props
801 #'buffer-substring 807 #'buffer-substring
802 #'buffer-substring-no-properties) 808 #'buffer-substring-no-properties)
803 (line-beginning-position) 809 beg end)
804 (line-end-position))
805 result) 810 result)
806 (forward-line (if forwardp 1 -1))) 811 (forward-line (if forwardp 1 -1)))
807 (nreverse result)))) 812 (nreverse result))))
@@ -996,14 +1001,17 @@ See also `multi-occur'."
996 (when (setq endpt (re-search-forward regexp nil t)) 1001 (when (setq endpt (re-search-forward regexp nil t))
997 (setq matches (1+ matches)) ;; increment match count 1002 (setq matches (1+ matches)) ;; increment match count
998 (setq matchbeg (match-beginning 0)) 1003 (setq matchbeg (match-beginning 0))
999 (setq begpt (save-excursion
1000 (goto-char matchbeg)
1001 (line-beginning-position)))
1002 (setq lines (+ lines (1- (count-lines origpt endpt)))) 1004 (setq lines (+ lines (1- (count-lines origpt endpt))))
1005 (save-excursion
1006 (goto-char matchbeg)
1007 (setq begpt (line-beginning-position)
1008 endpt (line-end-position)))
1003 (setq marker (make-marker)) 1009 (setq marker (make-marker))
1004 (set-marker marker matchbeg) 1010 (set-marker marker matchbeg)
1005 (setq curstring (buffer-substring begpt 1011 (if (and keep-props font-lock-mode
1006 (line-end-position))) 1012 (text-property-not-all begpt endpt 'fontified t))
1013 (font-lock-fontify-region begpt endpt))
1014 (setq curstring (buffer-substring begpt endpt))
1007 ;; Depropertize the string, and maybe 1015 ;; Depropertize the string, and maybe
1008 ;; highlight the matches 1016 ;; highlight the matches
1009 (let ((len (length curstring)) 1017 (let ((len (length curstring))
@@ -1012,17 +1020,15 @@ See also `multi-occur'."
1012 (set-text-properties 0 len nil curstring)) 1020 (set-text-properties 0 len nil curstring))
1013 (while (and (< start len) 1021 (while (and (< start len)
1014 (string-match regexp curstring start)) 1022 (string-match regexp curstring start))
1015 (add-text-properties (match-beginning 0) 1023 (add-text-properties
1016 (match-end 0) 1024 (match-beginning 0) (match-end 0)
1017 (append 1025 (append
1018 `(occur-match t) 1026 `(occur-match t)
1019 (when match-face 1027 (when match-face
1020 ;; Use `face' rather than 1028 ;; Use `face' rather than `font-lock-face' here
1021 ;; `font-lock-face' here 1029 ;; so as to override faces copied from the buffer.
1022 ;; so as to override faces 1030 `(face ,match-face)))
1023 ;; copied from the buffer. 1031 curstring)
1024 `(face ,match-face)))
1025 curstring)
1026 (setq start (match-end 0)))) 1032 (setq start (match-end 0))))
1027 ;; Generate the string to insert for this match 1033 ;; Generate the string to insert for this match
1028 (let* ((out-line 1034 (let* ((out-line
@@ -1033,7 +1039,10 @@ See also `multi-occur'."
1033 (when prefix-face 1039 (when prefix-face
1034 `(font-lock-face prefix-face)) 1040 `(font-lock-face prefix-face))
1035 '(occur-prefix t))) 1041 '(occur-prefix t)))
1036 curstring 1042 ;; We don't put `mouse-face' on the newline,
1043 ;; because that loses. And don't put it
1044 ;; on context lines to reduce flicker.
1045 (propertize curstring 'mouse-face 'highlight)
1037 "\n")) 1046 "\n"))
1038 (data 1047 (data
1039 (if (= nlines 0) 1048 (if (= nlines 0)
@@ -1057,10 +1066,7 @@ See also `multi-occur'."
1057 (insert "-------\n")) 1066 (insert "-------\n"))
1058 (add-text-properties 1067 (add-text-properties
1059 beg end 1068 beg end
1060 `(occur-target ,marker help-echo "mouse-2: go to this occurrence")) 1069 `(occur-target ,marker help-echo "mouse-2: go to this occurrence")))))
1061 ;; We don't put `mouse-face' on the newline,
1062 ;; because that loses.
1063 (add-text-properties beg (1- end) '(mouse-face highlight)))))
1064 (goto-char endpt)) 1070 (goto-char endpt))
1065 (if endpt 1071 (if endpt
1066 (progn 1072 (progn