aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2003-01-18 23:34:14 +0000
committerKim F. Storm2003-01-18 23:34:14 +0000
commitbe5936a745c91f51584fd6ab60472af39bd06ef3 (patch)
treeed33c3b2a1a8d6a0bbb8fdafd8a974cd7ebe08e6
parent5a9ac14b684ae85e54ed236cad679eaae7eb26a5 (diff)
downloademacs-be5936a745c91f51584fd6ab60472af39bd06ef3.tar.gz
emacs-be5936a745c91f51584fd6ab60472af39bd06ef3.zip
(kill-new, kill-append, kill-region): New optional parameter yank-handler.
(yank-excluded-properties): Add yank-handler to list. (yank-undo-function): New variable. (yank): Use it to undo previous yank or yank-pop command. Allow insert-for-yank to override this-command.
-rw-r--r--lisp/simple.el52
1 files changed, 36 insertions, 16 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index fe92a0e367d..a35269c1204 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1756,12 +1756,19 @@ ring directly.")
1756(defvar kill-ring-yank-pointer nil 1756(defvar kill-ring-yank-pointer nil
1757 "The tail of the kill ring whose car is the last thing yanked.") 1757 "The tail of the kill ring whose car is the last thing yanked.")
1758 1758
1759(defun kill-new (string &optional replace) 1759(defun kill-new (string &optional replace yank-handler)
1760 "Make STRING the latest kill in the kill ring. 1760 "Make STRING the latest kill in the kill ring.
1761Set `kill-ring-yank-pointer' to point to it. 1761Set `kill-ring-yank-pointer' to point to it.
1762If `interprogram-cut-function' is non-nil, apply it to STRING. 1762If `interprogram-cut-function' is non-nil, apply it to STRING.
1763Optional second argument REPLACE non-nil means that STRING will replace 1763Optional second argument REPLACE non-nil means that STRING will replace
1764the front of the kill ring, rather than being added to the list." 1764the front of the kill ring, rather than being added to the list.
1765
1766Optional third arguments YANK-HANDLER controls how the STRING is later
1767inserted into a buffer; see `insert-for-yank' for details."
1768 (when (> (length string) 0)
1769 (if yank-handler
1770 (put-text-property 0 1 'yank-handler yank-handler string)
1771 (remove-text-properties 0 1 '(yank-handler nil) string)))
1765 (and (fboundp 'menu-bar-update-yank-menu) 1772 (and (fboundp 'menu-bar-update-yank-menu)
1766 (menu-bar-update-yank-menu string (and replace (car kill-ring)))) 1773 (menu-bar-update-yank-menu string (and replace (car kill-ring))))
1767 (if (and replace kill-ring) 1774 (if (and replace kill-ring)
@@ -1773,15 +1780,20 @@ the front of the kill ring, rather than being added to the list."
1773 (if interprogram-cut-function 1780 (if interprogram-cut-function
1774 (funcall interprogram-cut-function string (not replace)))) 1781 (funcall interprogram-cut-function string (not replace))))
1775 1782
1776(defun kill-append (string before-p) 1783(defun kill-append (string before-p &optional yank-handler)
1777 "Append STRING to the end of the latest kill in the kill ring. 1784 "Append STRING to the end of the latest kill in the kill ring.
1778If BEFORE-P is non-nil, prepend STRING to the kill. 1785If BEFORE-P is non-nil, prepend STRING to the kill.
1779If `interprogram-cut-function' is set, pass the resulting kill to 1786Optional third argument YANK-HANDLER specifies the yank-handler text
1780it." 1787property to be set on the combined kill ring string. If the specified
1781 (kill-new (if before-p 1788yank-handler arg differs from the yank-handler property of the latest
1782 (concat string (car kill-ring)) 1789kill string, STRING is added as a new kill ring element instead of
1783 (concat (car kill-ring) string)) 1790being appending to the last kill.
1784 t)) 1791If `interprogram-cut-function' is set, pass the resulting kill to it."
1792 (let* ((cur (car kill-ring)))
1793 (kill-new (if before-p (concat string cur) (concat cur string))
1794 (or (= (length cur) 0)
1795 (equal yank-handler (get-text-property 0 'yank-handler cur)))
1796 yank-handler)))
1785 1797
1786(defun current-kill (n &optional do-not-move) 1798(defun current-kill (n &optional do-not-move)
1787 "Rotate the yanking point by N places, and then return that kill. 1799 "Rotate the yanking point by N places, and then return that kill.
@@ -1823,7 +1835,7 @@ yanking point; just return the Nth kill forward."
1823 '(text-read-only buffer-read-only error)) 1835 '(text-read-only buffer-read-only error))
1824(put 'text-read-only 'error-message "Text is read-only") 1836(put 'text-read-only 'error-message "Text is read-only")
1825 1837
1826(defun kill-region (beg end) 1838(defun kill-region (beg end &optional yank-handler)
1827 "Kill between point and mark. 1839 "Kill between point and mark.
1828The text is deleted but saved in the kill ring. 1840The text is deleted but saved in the kill ring.
1829The command \\[yank] can retrieve it from there. 1841The command \\[yank] can retrieve it from there.
@@ -1842,15 +1854,18 @@ Supply two arguments, character numbers indicating the stretch of text
1842Any command that calls this function is a \"kill command\". 1854Any command that calls this function is a \"kill command\".
1843If the previous command was also a kill command, 1855If the previous command was also a kill command,
1844the text killed this time appends to the text killed last time 1856the text killed this time appends to the text killed last time
1845to make one entry in the kill ring." 1857to make one entry in the kill ring.
1858
1859In lisp code, optional third arg YANK-HANDLER specifies the yank-handler
1860text property to be set on the killed text. See `insert-for-yank'."
1846 (interactive "r") 1861 (interactive "r")
1847 (condition-case nil 1862 (condition-case nil
1848 (let ((string (delete-and-extract-region beg end))) 1863 (let ((string (delete-and-extract-region beg end)))
1849 (when string ;STRING is nil if BEG = END 1864 (when string ;STRING is nil if BEG = END
1850 ;; Add that string to the kill ring, one way or another. 1865 ;; Add that string to the kill ring, one way or another.
1851 (if (eq last-command 'kill-region) 1866 (if (eq last-command 'kill-region)
1852 (kill-append string (< end beg)) 1867 (kill-append string (< end beg) yank-handler)
1853 (kill-new string))) 1868 (kill-new string nil yank-handler)))
1854 (setq this-command 'kill-region)) 1869 (setq this-command 'kill-region))
1855 ((buffer-read-only text-read-only) 1870 ((buffer-read-only text-read-only)
1856 ;; The code above failed because the buffer, or some of the characters 1871 ;; The code above failed because the buffer, or some of the characters
@@ -1941,13 +1956,16 @@ The argument is used for internal purposes; do not supply one."
1941 1956
1942;; This is actually used in subr.el but defcustom does not work there. 1957;; This is actually used in subr.el but defcustom does not work there.
1943(defcustom yank-excluded-properties 1958(defcustom yank-excluded-properties
1944 '(read-only invisible intangible field mouse-face help-echo local-map keymap) 1959 '(read-only invisible intangible field mouse-face help-echo local-map keymap
1960 yank-handler)
1945 "*Text properties to discard when yanking." 1961 "*Text properties to discard when yanking."
1946 :type '(choice (const :tag "All" t) (repeat symbol)) 1962 :type '(choice (const :tag "All" t) (repeat symbol))
1947 :group 'editing 1963 :group 'editing
1948 :version "21.4") 1964 :version "21.4")
1949 1965
1950(defvar yank-window-start nil) 1966(defvar yank-window-start nil)
1967(defvar yank-undo-function nil
1968 "If non-nil, function used by `yank-pop' to delete last stretch of yanked text.")
1951 1969
1952(defun yank-pop (arg) 1970(defun yank-pop (arg)
1953 "Replace just-yanked stretch of killed text with a different stretch. 1971 "Replace just-yanked stretch of killed text with a different stretch.
@@ -1968,7 +1986,8 @@ comes the newest one."
1968 (setq this-command 'yank) 1986 (setq this-command 'yank)
1969 (let ((inhibit-read-only t) 1987 (let ((inhibit-read-only t)
1970 (before (< (point) (mark t)))) 1988 (before (< (point) (mark t))))
1971 (delete-region (point) (mark t)) 1989 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
1990 (setq yank-undo-function nil)
1972 (set-marker (mark-marker) (point) (current-buffer)) 1991 (set-marker (mark-marker) (point) (current-buffer))
1973 (insert-for-yank (current-kill arg)) 1992 (insert-for-yank (current-kill arg))
1974 ;; Set the window start back where it was in the yank command, 1993 ;; Set the window start back where it was in the yank command,
@@ -2007,7 +2026,8 @@ See also the command \\[yank-pop]."
2007 (goto-char (prog1 (mark t) 2026 (goto-char (prog1 (mark t)
2008 (set-marker (mark-marker) (point) (current-buffer))))) 2027 (set-marker (mark-marker) (point) (current-buffer)))))
2009 ;; If we do get all the way thru, make this-command indicate that. 2028 ;; If we do get all the way thru, make this-command indicate that.
2010 (setq this-command 'yank) 2029 (if (eq this-command t)
2030 (setq this-command 'yank))
2011 nil) 2031 nil)
2012 2032
2013(defun rotate-yank-pointer (arg) 2033(defun rotate-yank-pointer (arg)