aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorGlenn Morris2017-11-20 13:08:35 -0500
committerGlenn Morris2017-11-20 13:08:35 -0500
commit33bfbfee7ef04392b0c30ca2ab5074a14c4ddad7 (patch)
tree1f9432682a7bff627f7208bcd8cc594bf7b5d60a /lisp/replace.el
parent7cf41d8088284c2fe8b1807d07fc082a270e6a78 (diff)
parent6e6bf60eab1e921605064e3d39ea080639f8e0f6 (diff)
downloademacs-33bfbfee7ef04392b0c30ca2ab5074a14c4ddad7.tar.gz
emacs-33bfbfee7ef04392b0c30ca2ab5074a14c4ddad7.zip
Merge from origin/emacs-26
6e6bf60 Don't let delete_frame select a tooltip frame (Bug#27647) e9dd580 Filter obtrusive events in help-read-key-sequence. 90075e8 Fix symlink flag in tramp-gvfs-handle-file-attributes c355529 Fix bug in tramp-handle-file-truename 4c21d04 Fix a typo in doc string of electric-indent-functions-without... 319c2de Avoid assertion violations in echo_area_display 63c7733 ; * lisp/ido.el (ido-find-alternate-file): Doc fix. (Bug#29278) cbd319a Fix case-folding in Occur 29520b0 Fix quick-calc in C mode with hex values 3e80124 Improve documentation of dired-next/prev-marked-file 90add18 Prevent aborts in line-move-visual 648c128 More fixes in src/.gdbinit 104f3e5 Document how to enter whitespace when using grep-read-files
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el346
1 files changed, 178 insertions, 168 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index cdaeb9240ad..80e584517ce 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1643,175 +1643,185 @@ See also `multi-occur'."
1643 (inhibit-field-text-motion t) 1643 (inhibit-field-text-motion t)
1644 (headerpt (with-current-buffer out-buf (point)))) 1644 (headerpt (with-current-buffer out-buf (point))))
1645 (with-current-buffer buf 1645 (with-current-buffer buf
1646 (or coding 1646 ;; The following binding is for when case-fold-search
1647 ;; Set CODING only if the current buffer locally 1647 ;; has a local binding in the original buffer, in which
1648 ;; binds buffer-file-coding-system. 1648 ;; case we cannot bind it globally and let that have
1649 (not (local-variable-p 'buffer-file-coding-system)) 1649 ;; effect in every buffer we search.
1650 (setq coding buffer-file-coding-system)) 1650 (let ((case-fold-search case-fold))
1651 (save-excursion 1651 (or coding
1652 (goto-char (point-min)) ;; begin searching in the buffer 1652 ;; Set CODING only if the current buffer locally
1653 (while (not (eobp)) 1653 ;; binds buffer-file-coding-system.
1654 (setq origpt (point)) 1654 (not (local-variable-p 'buffer-file-coding-system))
1655 (when (setq endpt (re-search-forward regexp nil t)) 1655 (setq coding buffer-file-coding-system))
1656 (setq lines (1+ lines)) ;; increment matching lines count 1656 (save-excursion
1657 (setq matchbeg (match-beginning 0)) 1657 (goto-char (point-min)) ;; begin searching in the buffer
1658 ;; Get beginning of first match line and end of the last. 1658 (while (not (eobp))
1659 (save-excursion 1659 (setq origpt (point))
1660 (goto-char matchbeg) 1660 (when (setq endpt (re-search-forward regexp nil t))
1661 (setq begpt (line-beginning-position)) 1661 (setq lines (1+ lines)) ;; increment matching lines count
1662 (goto-char endpt) 1662 (setq matchbeg (match-beginning 0))
1663 (setq endpt (line-end-position))) 1663 ;; Get beginning of first match line and end of the last.
1664 ;; Sum line numbers up to the first match line. 1664 (save-excursion
1665 (setq curr-line (+ curr-line (count-lines origpt begpt))) 1665 (goto-char matchbeg)
1666 (setq marker (make-marker)) 1666 (setq begpt (line-beginning-position))
1667 (set-marker marker matchbeg) 1667 (goto-char endpt)
1668 (setq curstring (occur-engine-line begpt endpt keep-props)) 1668 (setq endpt (line-end-position)))
1669 ;; Highlight the matches 1669 ;; Sum line numbers up to the first match line.
1670 (let ((len (length curstring)) 1670 (setq curr-line (+ curr-line (count-lines origpt begpt)))
1671 (start 0)) 1671 (setq marker (make-marker))
1672 ;; Count empty lines that don't use next loop (Bug#22062). 1672 (set-marker marker matchbeg)
1673 (when (zerop len) 1673 (setq curstring (occur-engine-line begpt endpt keep-props))
1674 (setq matches (1+ matches))) 1674 ;; Highlight the matches
1675 (while (and (< start len) 1675 (let ((len (length curstring))
1676 (string-match regexp curstring start)) 1676 (start 0))
1677 (setq matches (1+ matches)) 1677 ;; Count empty lines that don't use next loop (Bug#22062).
1678 (add-text-properties 1678 (when (zerop len)
1679 (match-beginning 0) (match-end 0) 1679 (setq matches (1+ matches)))
1680 '(occur-match t) curstring) 1680 (while (and (< start len)
1681 (when match-face 1681 (string-match regexp curstring start))
1682 ;; Add `match-face' to faces copied from the buffer. 1682 (setq matches (1+ matches))
1683 (add-face-text-property 1683 (add-text-properties
1684 (match-beginning 0) (match-end 0) 1684 (match-beginning 0) (match-end 0)
1685 match-face nil curstring)) 1685 '(occur-match t) curstring)
1686 ;; Avoid infloop (Bug#7593). 1686 (when match-face
1687 (let ((end (match-end 0))) 1687 ;; Add `match-face' to faces copied from the buffer.
1688 (setq start (if (= start end) (1+ start) end))))) 1688 (add-face-text-property
1689 ;; Generate the string to insert for this match 1689 (match-beginning 0) (match-end 0)
1690 (let* ((match-prefix 1690 match-face nil curstring))
1691 ;; Using 7 digits aligns tabs properly. 1691 ;; Avoid infloop (Bug#7593).
1692 (apply #'propertize (format "%7d:" curr-line) 1692 (let ((end (match-end 0)))
1693 (append 1693 (setq start (if (= start end) (1+ start) end)))))
1694 (when prefix-face 1694 ;; Generate the string to insert for this match
1695 `(font-lock-face ,prefix-face)) 1695 (let* ((match-prefix
1696 `(occur-prefix t mouse-face (highlight) 1696 ;; Using 7 digits aligns tabs properly.
1697 ;; Allow insertion of text at 1697 (apply #'propertize (format "%7d:" curr-line)
1698 ;; the end of the prefix (for 1698 (append
1699 ;; Occur Edit mode). 1699 (when prefix-face
1700 front-sticky t rear-nonsticky t 1700 `(font-lock-face ,prefix-face))
1701 occur-target ,marker follow-link t 1701 `(occur-prefix t mouse-face (highlight)
1702 help-echo "mouse-2: go to this occurrence")))) 1702 ;; Allow insertion of text
1703 (match-str 1703 ;; at the end of the prefix
1704 ;; We don't put `mouse-face' on the newline, 1704 ;; (for Occur Edit mode).
1705 ;; because that loses. And don't put it 1705 front-sticky t
1706 ;; on context lines to reduce flicker. 1706 rear-nonsticky t
1707 (propertize curstring 'mouse-face (list 'highlight) 1707 occur-target ,marker
1708 'occur-target marker 1708 follow-link t
1709 'follow-link t 1709 help-echo "mouse-2: go to this occurrence"))))
1710 'help-echo 1710 (match-str
1711 "mouse-2: go to this occurrence")) 1711 ;; We don't put `mouse-face' on the newline,
1712 (out-line 1712 ;; because that loses. And don't put it
1713 (concat 1713 ;; on context lines to reduce flicker.
1714 match-prefix 1714 (propertize curstring 'mouse-face (list 'highlight)
1715 ;; Add non-numeric prefix to all non-first lines 1715 'occur-target marker
1716 ;; of multi-line matches. 1716 'follow-link t
1717 (replace-regexp-in-string 1717 'help-echo
1718 "\n" 1718 "mouse-2: go to this occurrence"))
1719 (if prefix-face 1719 (out-line
1720 (propertize "\n :" 'font-lock-face prefix-face) 1720 (concat
1721 "\n :") 1721 match-prefix
1722 match-str) 1722 ;; Add non-numeric prefix to all non-first lines
1723 ;; Add marker at eol, but no mouse props. 1723 ;; of multi-line matches.
1724 (propertize "\n" 'occur-target marker))) 1724 (replace-regexp-in-string
1725 (data 1725 "\n"
1726 (if (= nlines 0) 1726 (if prefix-face
1727 ;; The simple display style 1727 (propertize
1728 out-line 1728 "\n :" 'font-lock-face prefix-face)
1729 ;; The complex multi-line display style. 1729 "\n :")
1730 (setq ret (occur-context-lines 1730 match-str)
1731 out-line nlines keep-props begpt endpt 1731 ;; Add marker at eol, but no mouse props.
1732 curr-line prev-line prev-after-lines 1732 (propertize "\n" 'occur-target marker)))
1733 prefix-face)) 1733 (data
1734 ;; Set first elem of the returned list to `data', 1734 (if (= nlines 0)
1735 ;; and the second elem to `prev-after-lines'. 1735 ;; The simple display style
1736 (setq prev-after-lines (nth 1 ret)) 1736 out-line
1737 (nth 0 ret)))) 1737 ;; The complex multi-line display style.
1738 ;; Actually insert the match display data 1738 (setq ret (occur-context-lines
1739 (with-current-buffer out-buf 1739 out-line nlines keep-props begpt
1740 (when (and list-matching-lines-jump-to-current-line 1740 endpt curr-line prev-line
1741 (not multi-occur-p) 1741 prev-after-lines prefix-face))
1742 (not orig-line-shown-p) 1742 ;; Set first elem of the returned list to `data',
1743 (>= curr-line orig-line)) 1743 ;; and the second elem to `prev-after-lines'.
1744 (insert 1744 (setq prev-after-lines (nth 1 ret))
1745 (concat 1745 (nth 0 ret))))
1746 (propertize 1746 ;; Actually insert the match display data
1747 (format "%7d:%s" orig-line orig-line-str) 1747 (with-current-buffer out-buf
1748 'face list-matching-lines-current-line-face 1748 (when (and list-matching-lines-jump-to-current-line
1749 'mouse-face 'mode-line-highlight 1749 (not multi-occur-p)
1750 'help-echo "Current line") "\n")) 1750 (not orig-line-shown-p)
1751 (setq orig-line-shown-p t finalpt (point))) 1751 (>= curr-line orig-line))
1752 (insert data))) 1752 (insert
1753 (goto-char endpt)) 1753 (concat
1754 (if endpt 1754 (propertize
1755 (progn 1755 (format "%7d:%s" orig-line orig-line-str)
1756 ;; Sum line numbers between first and last match lines. 1756 'face list-matching-lines-current-line-face
1757 (setq curr-line (+ curr-line (count-lines begpt endpt) 1757 'mouse-face 'mode-line-highlight
1758 ;; Add 1 for empty last match line since 1758 'help-echo "Current line") "\n"))
1759 ;; count-lines returns 1 line less. 1759 (setq orig-line-shown-p t finalpt (point)))
1760 (if (and (bolp) (eolp)) 1 0))) 1760 (insert data)))
1761 ;; On to the next match... 1761 (goto-char endpt))
1762 (forward-line 1)) 1762 (if endpt
1763 (goto-char (point-max))) 1763 (progn
1764 (setq prev-line (1- curr-line))) 1764 ;; Sum line numbers between first and last match lines.
1765 ;; Insert original line if haven't done yet. 1765 (setq curr-line (+ curr-line (count-lines begpt endpt)
1766 (when (and list-matching-lines-jump-to-current-line 1766 ;; Add 1 for empty last match line
1767 (not multi-occur-p) 1767 ;; since count-lines returns one
1768 (not orig-line-shown-p)) 1768 ;; line less.
1769 (with-current-buffer out-buf 1769 (if (and (bolp) (eolp)) 1 0)))
1770 (insert 1770 ;; On to the next match...
1771 (concat 1771 (forward-line 1))
1772 (propertize 1772 (goto-char (point-max)))
1773 (format "%7d:%s" orig-line orig-line-str) 1773 (setq prev-line (1- curr-line)))
1774 'face list-matching-lines-current-line-face 1774 ;; Insert original line if haven't done yet.
1775 'mouse-face 'mode-line-highlight 1775 (when (and list-matching-lines-jump-to-current-line
1776 'help-echo "Current line") "\n")))) 1776 (not multi-occur-p)
1777 ;; Flush remaining context after-lines. 1777 (not orig-line-shown-p))
1778 (when prev-after-lines 1778 (with-current-buffer out-buf
1779 (with-current-buffer out-buf 1779 (insert
1780 (insert (apply #'concat (occur-engine-add-prefix 1780 (concat
1781 prev-after-lines prefix-face))))))) 1781 (propertize
1782 (when (not (zerop lines)) ;; is the count zero? 1782 (format "%7d:%s" orig-line orig-line-str)
1783 (setq global-lines (+ global-lines lines) 1783 'face list-matching-lines-current-line-face
1784 global-matches (+ global-matches matches)) 1784 'mouse-face 'mode-line-highlight
1785 (with-current-buffer out-buf 1785 'help-echo "Current line") "\n"))))
1786 (goto-char headerpt) 1786 ;; Flush remaining context after-lines.
1787 (let ((beg (point)) 1787 (when prev-after-lines
1788 end) 1788 (with-current-buffer out-buf
1789 (insert (propertize 1789 (insert (apply #'concat (occur-engine-add-prefix
1790 (format "%d match%s%s%s in buffer: %s%s\n" 1790 prev-after-lines prefix-face)))))))
1791 matches (if (= matches 1) "" "es") 1791 (when (not (zerop lines)) ;; is the count zero?
1792 ;; Don't display the same number of lines 1792 (setq global-lines (+ global-lines lines)
1793 ;; and matches in case of 1 match per line. 1793 global-matches (+ global-matches matches))
1794 (if (= lines matches) 1794 (with-current-buffer out-buf
1795 "" (format " in %d line%s" 1795 (goto-char headerpt)
1796 lines (if (= lines 1) "" "s"))) 1796 (let ((beg (point))
1797 ;; Don't display regexp for multi-buffer. 1797 end)
1798 (if (> (length buffers) 1) 1798 (insert (propertize
1799 "" (occur-regexp-descr regexp)) 1799 (format "%d match%s%s%s in buffer: %s%s\n"
1800 (buffer-name buf) 1800 matches (if (= matches 1) "" "es")
1801 (if in-region-p 1801 ;; Don't display the same number of lines
1802 (format " within region: %d-%d" 1802 ;; and matches in case of 1 match per line.
1803 occur--region-start 1803 (if (= lines matches)
1804 occur--region-end) 1804 "" (format " in %d line%s"
1805 "")) 1805 lines
1806 'read-only t)) 1806 (if (= lines 1) "" "s")))
1807 (setq end (point)) 1807 ;; Don't display regexp for multi-buffer.
1808 (add-text-properties beg end `(occur-title ,buf)) 1808 (if (> (length buffers) 1)
1809 (when title-face 1809 "" (occur-regexp-descr regexp))
1810 (add-face-text-property beg end title-face)) 1810 (buffer-name buf)
1811 (goto-char (if finalpt 1811 (if in-region-p
1812 (setq occur--final-pos 1812 (format " within region: %d-%d"
1813 (cl-incf finalpt (- end beg))) 1813 occur--region-start
1814 (point-min))))))))) 1814 occur--region-end)
1815 ""))
1816 'read-only t))
1817 (setq end (point))
1818 (add-text-properties beg end `(occur-title ,buf))
1819 (when title-face
1820 (add-face-text-property beg end title-face))
1821 (goto-char (if finalpt
1822 (setq occur--final-pos
1823 (cl-incf finalpt (- end beg)))
1824 (point-min))))))))))
1815 ;; Display total match count and regexp for multi-buffer. 1825 ;; Display total match count and regexp for multi-buffer.
1816 (when (and (not (zerop global-lines)) (> (length buffers) 1)) 1826 (when (and (not (zerop global-lines)) (> (length buffers) 1))
1817 (goto-char (point-min)) 1827 (goto-char (point-min))