diff options
| author | Chong Yidong | 2012-08-18 13:11:38 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-08-18 13:11:38 +0800 |
| commit | 2170b1bdd500484349deec2d946119e6a653e198 (patch) | |
| tree | 516c6e5f25a53a94c403f3524a18518c3b290983 | |
| parent | 6a09a33b5551348f15c7c6f5a6182c57e0ee8ef4 (diff) | |
| download | emacs-2170b1bdd500484349deec2d946119e6a653e198.tar.gz emacs-2170b1bdd500484349deec2d946119e6a653e198.zip | |
Add yank-handled-properties; use it for `font-lock-face' and `category'
properties, instead of hard-coding these properties' special handling.
* lisp/simple.el (yank-handled-properties): New defcustom.
(yank-excluded-properties): Add font-lock-face and category.
(yank): Doc fix.
* lisp/subr.el (remove-yank-excluded-properties): Obey
yank-handled-properties. The special handling of font-lock-face
and category is now done this way, instead of being hard-coded.
(insert-for-yank-1): Remove font-lock-face handling.
(yank-handle-font-lock-face-property)
(yank-handle-category-property): New function.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/ChangeLog | 13 | ||||
| -rw-r--r-- | lisp/simple.el | 47 | ||||
| -rw-r--r-- | lisp/subr.el | 133 |
4 files changed, 115 insertions, 82 deletions
| @@ -160,6 +160,10 @@ The PCL-CVS commands are still available via the keyboard. | |||
| 160 | 160 | ||
| 161 | * Editing Changes in Emacs 24.3 | 161 | * Editing Changes in Emacs 24.3 |
| 162 | 162 | ||
| 163 | ** New option `yank-handled-properties' allows processing of text | ||
| 164 | properties on yanked text, in more ways that are more general than | ||
| 165 | just removing them, as done by `yank-excluded-properties'. | ||
| 166 | |||
| 163 | ** New option `delete-trailing-lines' specifies whether the M-x | 167 | ** New option `delete-trailing-lines' specifies whether the M-x |
| 164 | delete-trailing-whitespace command should delete trailing lines at the | 168 | delete-trailing-whitespace command should delete trailing lines at the |
| 165 | end of the buffer. It defaults to t. | 169 | end of the buffer. It defaults to t. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 84a8ec18507..ec89b3784d9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2012-08-18 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * simple.el (yank-handled-properties): New defcustom. | ||
| 4 | (yank-excluded-properties): Add font-lock-face and category. | ||
| 5 | (yank): Doc fix. | ||
| 6 | |||
| 7 | * subr.el (remove-yank-excluded-properties): Obey | ||
| 8 | yank-handled-properties. The special handling of font-lock-face | ||
| 9 | and category is now done this way, instead of being hard-coded. | ||
| 10 | (insert-for-yank-1): Remove font-lock-face handling. | ||
| 11 | (yank-handle-font-lock-face-property) | ||
| 12 | (yank-handle-category-property): New function. | ||
| 13 | |||
| 1 | 2012-08-17 Glenn Morris <rgm@gnu.org> | 14 | 2012-08-17 Glenn Morris <rgm@gnu.org> |
| 2 | 15 | ||
| 3 | * mail/rmailout.el (rmail-output-read-file-name): | 16 | * mail/rmailout.el (rmail-output-read-file-name): |
diff --git a/lisp/simple.el b/lisp/simple.el index 76243a202bc..1080757f7d2 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -3474,16 +3474,36 @@ The argument is used for internal purposes; do not supply one." | |||
| 3474 | 3474 | ||
| 3475 | ;; Yanking. | 3475 | ;; Yanking. |
| 3476 | 3476 | ||
| 3477 | (defcustom yank-handled-properties | ||
| 3478 | '((font-lock-face . yank-handle-font-lock-face-property) | ||
| 3479 | (category . yank-handle-category-property)) | ||
| 3480 | "List of special text property handling conditions for yanking. | ||
| 3481 | Each element should have the form (PROP . FUN), where PROP is a | ||
| 3482 | property symbol and FUN is a function. When the `yank' command | ||
| 3483 | inserts text into the buffer, it scans the inserted text for | ||
| 3484 | stretches of text that have `eq' values of the text property | ||
| 3485 | PROP; for each such stretch of text, FUN is called with three | ||
| 3486 | arguments: the property's value in that text, and the start and | ||
| 3487 | end positions of the text. | ||
| 3488 | |||
| 3489 | This is done prior to removing the properties specified by | ||
| 3490 | `yank-excluded-properties'." | ||
| 3491 | :group 'killing | ||
| 3492 | :version "24.3") | ||
| 3493 | |||
| 3477 | ;; This is actually used in subr.el but defcustom does not work there. | 3494 | ;; This is actually used in subr.el but defcustom does not work there. |
| 3478 | (defcustom yank-excluded-properties | 3495 | (defcustom yank-excluded-properties |
| 3479 | '(read-only invisible intangible field mouse-face help-echo local-map keymap | 3496 | '(category field follow-link fontified font-lock-face help-echo |
| 3480 | yank-handler follow-link fontified) | 3497 | intangible invisible keymap local-map mouse-face read-only |
| 3498 | yank-handler) | ||
| 3481 | "Text properties to discard when yanking. | 3499 | "Text properties to discard when yanking. |
| 3482 | The value should be a list of text properties to discard or t, | 3500 | The value should be a list of text properties to discard or t, |
| 3483 | which means to discard all text properties." | 3501 | which means to discard all text properties. |
| 3502 | |||
| 3503 | See also `yank-handled-properties'." | ||
| 3484 | :type '(choice (const :tag "All" t) (repeat symbol)) | 3504 | :type '(choice (const :tag "All" t) (repeat symbol)) |
| 3485 | :group 'killing | 3505 | :group 'killing |
| 3486 | :version "22.1") | 3506 | :version "24.3") |
| 3487 | 3507 | ||
| 3488 | (defvar yank-window-start nil) | 3508 | (defvar yank-window-start nil) |
| 3489 | (defvar yank-undo-function nil | 3509 | (defvar yank-undo-function nil |
| @@ -3535,15 +3555,16 @@ doc string for `insert-for-yank-1', which see." | |||
| 3535 | 3555 | ||
| 3536 | (defun yank (&optional arg) | 3556 | (defun yank (&optional arg) |
| 3537 | "Reinsert (\"paste\") the last stretch of killed text. | 3557 | "Reinsert (\"paste\") the last stretch of killed text. |
| 3538 | More precisely, reinsert the stretch of killed text most recently | 3558 | More precisely, reinsert the most recent kill, which is the |
| 3539 | killed OR yanked. Put point at end, and set mark at beginning. | 3559 | stretch of killed text most recently killed OR yanked. Put point |
| 3540 | With just \\[universal-argument] as argument, same but put point at beginning (and mark at end). | 3560 | at the end, and set mark at the beginning without activating it. |
| 3541 | With argument N, reinsert the Nth most recently killed stretch of killed | 3561 | With just \\[universal-argument] as argument, put point at beginning, and mark at end. |
| 3542 | text. | 3562 | With argument N, reinsert the Nth most recent kill. |
| 3543 | 3563 | ||
| 3544 | When this command inserts killed text into the buffer, it honors | 3564 | When this command inserts text into the buffer, it honors the |
| 3545 | `yank-excluded-properties' and `yank-handler' as described in the | 3565 | `yank-handled-properties' and `yank-excluded-properties' |
| 3546 | doc string for `insert-for-yank-1', which see. | 3566 | variables, and the `yank-handler' text property. See |
| 3567 | `insert-for-yank-1' for details. | ||
| 3547 | 3568 | ||
| 3548 | See also the command `yank-pop' (\\[yank-pop])." | 3569 | See also the command `yank-pop' (\\[yank-pop])." |
| 3549 | (interactive "*P") | 3570 | (interactive "*P") |
diff --git a/lisp/subr.el b/lisp/subr.el index 1e367a155d0..74afd59f8d5 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -2805,35 +2805,24 @@ if it's an autoloaded macro." | |||
| 2805 | 2805 | ||
| 2806 | ;;;; Support for yanking and text properties. | 2806 | ;;;; Support for yanking and text properties. |
| 2807 | 2807 | ||
| 2808 | (defvar yank-handled-properties) | ||
| 2808 | (defvar yank-excluded-properties) | 2809 | (defvar yank-excluded-properties) |
| 2809 | 2810 | ||
| 2810 | (defun remove-yank-excluded-properties (start end) | 2811 | (defun remove-yank-excluded-properties (start end) |
| 2811 | "Remove `yank-excluded-properties' between START and END positions. | 2812 | "Process text properties between START and END, inserted for a `yank'. |
| 2812 | Replaces `category' properties with their defined properties." | 2813 | Perform the handling specified by `yank-handled-properties', then |
| 2814 | remove properties specified by `yank-excluded-properties'." | ||
| 2813 | (let ((inhibit-read-only t)) | 2815 | (let ((inhibit-read-only t)) |
| 2814 | ;; Replace any `category' property with the properties it stands | 2816 | (dolist (handler yank-handled-properties) |
| 2815 | ;; for. This is to remove `mouse-face' properties that are placed | 2817 | (let ((prop (car handler)) |
| 2816 | ;; on categories in *Help* buffers' buttons. See | 2818 | (fun (cdr handler)) |
| 2817 | ;; http://lists.gnu.org/archive/html/emacs-devel/2002-04/msg00648.html | 2819 | (run-start start)) |
| 2818 | ;; for the details. | 2820 | (while (< run-start end) |
| 2819 | (unless (memq yank-excluded-properties '(t nil)) | 2821 | (let ((value (get-text-property run-start prop)) |
| 2820 | (save-excursion | 2822 | (run-end (next-single-property-change |
| 2821 | (goto-char start) | 2823 | run-start prop nil end))) |
| 2822 | (while (< (point) end) | 2824 | (funcall fun value run-start run-end) |
| 2823 | (let ((cat (get-text-property (point) 'category)) | 2825 | (setq run-start run-end))))) |
| 2824 | run-end) | ||
| 2825 | (setq run-end | ||
| 2826 | (next-single-property-change (point) 'category nil end)) | ||
| 2827 | (when cat | ||
| 2828 | (let (run-end2 original) | ||
| 2829 | (remove-list-of-text-properties (point) run-end '(category)) | ||
| 2830 | (while (< (point) run-end) | ||
| 2831 | (setq run-end2 (next-property-change (point) nil run-end)) | ||
| 2832 | (setq original (text-properties-at (point))) | ||
| 2833 | (set-text-properties (point) run-end2 (symbol-plist cat)) | ||
| 2834 | (add-text-properties (point) run-end2 original) | ||
| 2835 | (goto-char run-end2)))) | ||
| 2836 | (goto-char run-end))))) | ||
| 2837 | (if (eq yank-excluded-properties t) | 2826 | (if (eq yank-excluded-properties t) |
| 2838 | (set-text-properties start end nil) | 2827 | (set-text-properties start end nil) |
| 2839 | (remove-list-of-text-properties start end yank-excluded-properties)))) | 2828 | (remove-list-of-text-properties start end yank-excluded-properties)))) |
| @@ -2851,29 +2840,31 @@ See `insert-for-yank-1' for more details." | |||
| 2851 | (insert-for-yank-1 string)) | 2840 | (insert-for-yank-1 string)) |
| 2852 | 2841 | ||
| 2853 | (defun insert-for-yank-1 (string) | 2842 | (defun insert-for-yank-1 (string) |
| 2854 | "Insert STRING at point, stripping some text properties. | 2843 | "Insert STRING at point for the `yank' command. |
| 2855 | 2844 | This function is like `insert', except it honors the variables | |
| 2856 | Strip text properties from the inserted text according to | 2845 | `yank-handled-properties' and `yank-excluded-properties', and the |
| 2857 | `yank-excluded-properties'. Otherwise just like (insert STRING). | 2846 | `yank-handler' text property. |
| 2858 | 2847 | ||
| 2859 | If STRING has a non-nil `yank-handler' property on the first character, | 2848 | Properties listed in `yank-handled-properties' are processed, |
| 2860 | the normal insert behavior is modified in various ways. The value of | 2849 | then those listed in `yank-excluded-properties' are discarded. |
| 2861 | the yank-handler property must be a list with one to four elements | 2850 | |
| 2862 | with the following format: (FUNCTION PARAM NOEXCLUDE UNDO). | 2851 | If STRING has a non-nil `yank-handler' property on its first |
| 2863 | When FUNCTION is present and non-nil, it is called instead of `insert' | 2852 | character, the normal insert behavior is altered. The value of |
| 2864 | to insert the string. FUNCTION takes one argument--the object to insert. | 2853 | the `yank-handler' property must be a list of one to four |
| 2865 | If PARAM is present and non-nil, it replaces STRING as the object | 2854 | elements, of the form (FUNCTION PARAM NOEXCLUDE UNDO). |
| 2866 | passed to FUNCTION (or `insert'); for example, if FUNCTION is | 2855 | FUNCTION, if non-nil, should be a function of one argument, an |
| 2867 | `yank-rectangle', PARAM may be a list of strings to insert as a | 2856 | object to insert; it is called instead of `insert'. |
| 2868 | rectangle. | 2857 | PARAM, if present and non-nil, replaces STRING as the argument to |
| 2869 | If NOEXCLUDE is present and non-nil, the normal removal of the | 2858 | FUNCTION or `insert'; e.g. if FUNCTION is `yank-rectangle', PARAM |
| 2859 | may be a list of strings to insert as a rectangle. | ||
| 2860 | If NOEXCLUDE is present and non-nil, the normal removal of | ||
| 2870 | `yank-excluded-properties' is not performed; instead FUNCTION is | 2861 | `yank-excluded-properties' is not performed; instead FUNCTION is |
| 2871 | responsible for removing those properties. This may be necessary | 2862 | responsible for the removal. This may be necessary if FUNCTION |
| 2872 | if FUNCTION adjusts point before or after inserting the object. | 2863 | adjusts point before or after inserting the object. |
| 2873 | If UNDO is present and non-nil, it is a function that will be called | 2864 | UNDO, if present and non-nil, should be a function to be called |
| 2874 | by `yank-pop' to undo the insertion of the current object. It is | 2865 | by `yank-pop' to undo the insertion of the current object. It is |
| 2875 | called with two arguments, the start and end of the current region. | 2866 | given two arguments, the start and end of the region. FUNCTION |
| 2876 | FUNCTION may set `yank-undo-function' to override the UNDO value." | 2867 | may set `yank-undo-function' to override UNDO." |
| 2877 | (let* ((handler (and (stringp string) | 2868 | (let* ((handler (and (stringp string) |
| 2878 | (get-text-property 0 'yank-handler string))) | 2869 | (get-text-property 0 'yank-handler string))) |
| 2879 | (param (or (nth 1 handler) string)) | 2870 | (param (or (nth 1 handler) string)) |
| @@ -2882,7 +2873,7 @@ If UNDO is present and non-nil, it is a function that will be called | |||
| 2882 | end) | 2873 | end) |
| 2883 | 2874 | ||
| 2884 | (setq yank-undo-function t) | 2875 | (setq yank-undo-function t) |
| 2885 | (if (nth 0 handler) ;; FUNCTION | 2876 | (if (nth 0 handler) ; FUNCTION |
| 2886 | (funcall (car handler) param) | 2877 | (funcall (car handler) param) |
| 2887 | (insert param)) | 2878 | (insert param)) |
| 2888 | (setq end (point)) | 2879 | (setq end (point)) |
| @@ -2891,34 +2882,17 @@ If UNDO is present and non-nil, it is a function that will be called | |||
| 2891 | ;; following text property changes. | 2882 | ;; following text property changes. |
| 2892 | (setq inhibit-read-only t) | 2883 | (setq inhibit-read-only t) |
| 2893 | 2884 | ||
| 2894 | ;; What should we do with `font-lock-face' properties? | 2885 | (unless (nth 2 handler) ; NOEXCLUDE |
| 2895 | (if font-lock-defaults | 2886 | (remove-yank-excluded-properties opoint end)) |
| 2896 | ;; No, just wipe them. | ||
| 2897 | (remove-list-of-text-properties opoint end '(font-lock-face)) | ||
| 2898 | ;; Convert them to `face'. | ||
| 2899 | (save-excursion | ||
| 2900 | (goto-char opoint) | ||
| 2901 | (while (< (point) end) | ||
| 2902 | (let ((face (get-text-property (point) 'font-lock-face)) | ||
| 2903 | run-end) | ||
| 2904 | (setq run-end | ||
| 2905 | (next-single-property-change (point) 'font-lock-face nil end)) | ||
| 2906 | (when face | ||
| 2907 | (remove-text-properties (point) run-end '(font-lock-face nil)) | ||
| 2908 | (put-text-property (point) run-end 'face face)) | ||
| 2909 | (goto-char run-end))))) | ||
| 2910 | |||
| 2911 | (unless (nth 2 handler) ;; NOEXCLUDE | ||
| 2912 | (remove-yank-excluded-properties opoint (point))) | ||
| 2913 | 2887 | ||
| 2914 | ;; If last inserted char has properties, mark them as rear-nonsticky. | 2888 | ;; If last inserted char has properties, mark them as rear-nonsticky. |
| 2915 | (if (and (> end opoint) | 2889 | (if (and (> end opoint) |
| 2916 | (text-properties-at (1- end))) | 2890 | (text-properties-at (1- end))) |
| 2917 | (put-text-property (1- end) end 'rear-nonsticky t)) | 2891 | (put-text-property (1- end) end 'rear-nonsticky t)) |
| 2918 | 2892 | ||
| 2919 | (if (eq yank-undo-function t) ;; not set by FUNCTION | 2893 | (if (eq yank-undo-function t) ; not set by FUNCTION |
| 2920 | (setq yank-undo-function (nth 3 handler))) ;; UNDO | 2894 | (setq yank-undo-function (nth 3 handler))) ; UNDO |
| 2921 | (if (nth 4 handler) ;; COMMAND | 2895 | (if (nth 4 handler) ; COMMAND |
| 2922 | (setq this-command (nth 4 handler))))) | 2896 | (setq this-command (nth 4 handler))))) |
| 2923 | 2897 | ||
| 2924 | (defun insert-buffer-substring-no-properties (buffer &optional start end) | 2898 | (defun insert-buffer-substring-no-properties (buffer &optional start end) |
| @@ -2944,6 +2918,27 @@ Strip text properties from the inserted text according to | |||
| 2944 | (insert-buffer-substring buffer start end) | 2918 | (insert-buffer-substring buffer start end) |
| 2945 | (remove-yank-excluded-properties opoint (point)))) | 2919 | (remove-yank-excluded-properties opoint (point)))) |
| 2946 | 2920 | ||
| 2921 | (defun yank-handle-font-lock-face-property (face start end) | ||
| 2922 | "If `font-lock-defaults' is nil, apply FACE as a `face' property. | ||
| 2923 | START and END denote the start and end of the text to act on. | ||
| 2924 | Do nothing if FACE is nil." | ||
| 2925 | (and face | ||
| 2926 | (null font-lock-defaults) | ||
| 2927 | (put-text-property start end 'face face))) | ||
| 2928 | |||
| 2929 | ;; This removes `mouse-face' properties in *Help* buffer buttons: | ||
| 2930 | ;; http://lists.gnu.org/archive/html/emacs-devel/2002-04/msg00648.html | ||
| 2931 | (defun yank-handle-category-property (category start end) | ||
| 2932 | "Apply property category CATEGORY's properties between START and END." | ||
| 2933 | (when category | ||
| 2934 | (let ((start2 start)) | ||
| 2935 | (while (< start2 end) | ||
| 2936 | (let ((end2 (next-property-change start2 nil end)) | ||
| 2937 | (original (text-properties-at start2))) | ||
| 2938 | (set-text-properties start2 end2 (symbol-plist category)) | ||
| 2939 | (add-text-properties start2 end2 original) | ||
| 2940 | (setq start2 end2)))))) | ||
| 2941 | |||
| 2947 | 2942 | ||
| 2948 | ;;;; Synchronous shell commands. | 2943 | ;;;; Synchronous shell commands. |
| 2949 | 2944 | ||