comparison lisp/simple.el @ 61111:43d165e3db5b

(idle-update-delay): Move definition up. (buffer-substring-filters): New variable. (filter-buffer-substring): New function. (kill-region, copy-region-as-kill): Use it.
author Richard M. Stallman <rms@gnu.org>
date Tue, 29 Mar 2005 20:53:19 +0000
parents ed6d9a5fc534
children ca079ae96939
comparison
equal deleted inserted replaced
61110:a1569f3fbb77 61111:43d165e3db5b
33 33
34 (eval-when-compile 34 (eval-when-compile
35 (autoload 'widget-convert "wid-edit") 35 (autoload 'widget-convert "wid-edit")
36 (autoload 'shell-mode "shell")) 36 (autoload 'shell-mode "shell"))
37 37
38 (defcustom idle-update-delay 0.5
39 "*Idle time delay before updating various things on the screen.
40 Various Emacs features that update auxiliary information when point moves
41 wait this many seconds after Emacs becomes idle before doing an update."
42 :type 'number
43 :group 'display
44 :version "22.1")
38 45
39 (defgroup killing nil 46 (defgroup killing nil
40 "Killing and yanking commands." 47 "Killing and yanking commands."
41 :group 'editing) 48 :group 'editing)
42 49
2216 (append (nthcdr universal-argument-num-events keylist) 2223 (append (nthcdr universal-argument-num-events keylist)
2217 unread-command-events))) 2224 unread-command-events)))
2218 (reset-this-command-lengths) 2225 (reset-this-command-lengths)
2219 (restore-overriding-map)) 2226 (restore-overriding-map))
2220 2227
2228 (defvar buffer-substring-filters nil
2229 "List of filter functions for `filter-buffer-substring'.
2230 Each function must accept a single argument, a string, and return
2231 a string. The buffer substring is passed to the first function
2232 in the list, and the return value of each function is passed to
2233 the next. The return value of the last function is used as the
2234 return value of `filter-buffer-substring'.
2235
2236 If this variable is nil, no filtering is performed.")
2237
2238 (defun filter-buffer-substring (beg end &optional delete)
2239 "Return the buffer substring between BEG and END, after filtering.
2240 The buffer substring is passed through each of the filter
2241 functions in `buffer-substring-filters', and the value from the
2242 last filter function is returned. If `buffer-substring-filters'
2243 is nil, the buffer substring is returned unaltered.
2244
2245 If DELETE is non-nil, the text between BEG and END is deleted
2246 from the buffer.
2247
2248 Point is temporarily set to BEG before caling
2249 `buffer-substring-filters', in case the functions need to know
2250 where the text came from.
2251
2252 This function should be used instead of `buffer-substring' or
2253 `delete-and-extract-region' when you want to allow filtering to
2254 take place. For example, major or minor modes can use
2255 `buffer-substring-filters' to extract characters that are special
2256 to a buffer, and should not be copied into other buffers."
2257 (save-excursion
2258 (goto-char beg)
2259 (let ((string (if delete (delete-and-extract-region beg end)
2260 (buffer-substring beg end))))
2261 (dolist (filter buffer-substring-filters string)
2262 (setq string (funcall filter string))))))
2263
2221 ;;;; Window system cut and paste hooks. 2264 ;;;; Window system cut and paste hooks.
2222 2265
2223 (defvar interprogram-cut-function nil 2266 (defvar interprogram-cut-function nil
2224 "Function to call to make a killed region available to other programs. 2267 "Function to call to make a killed region available to other programs.
2225 2268
2392 In Lisp code, optional third arg YANK-HANDLER, if non-nil, 2435 In Lisp code, optional third arg YANK-HANDLER, if non-nil,
2393 specifies the yank-handler text property to be set on the killed 2436 specifies the yank-handler text property to be set on the killed
2394 text. See `insert-for-yank'." 2437 text. See `insert-for-yank'."
2395 (interactive "r") 2438 (interactive "r")
2396 (condition-case nil 2439 (condition-case nil
2397 (let ((string (delete-and-extract-region beg end))) 2440 (let ((string (filter-buffer-substring beg end t)))
2398 (when string ;STRING is nil if BEG = END 2441 (when string ;STRING is nil if BEG = END
2399 ;; Add that string to the kill ring, one way or another. 2442 ;; Add that string to the kill ring, one way or another.
2400 (if (eq last-command 'kill-region) 2443 (if (eq last-command 'kill-region)
2401 (kill-append string (< end beg) yank-handler) 2444 (kill-append string (< end beg) yank-handler)
2402 (kill-new string nil yank-handler))) 2445 (kill-new string nil yank-handler)))
2428 In Transient Mark mode, deactivate the mark. 2471 In Transient Mark mode, deactivate the mark.
2429 If `interprogram-cut-function' is non-nil, also save the text for a window 2472 If `interprogram-cut-function' is non-nil, also save the text for a window
2430 system cut and paste." 2473 system cut and paste."
2431 (interactive "r") 2474 (interactive "r")
2432 (if (eq last-command 'kill-region) 2475 (if (eq last-command 'kill-region)
2433 (kill-append (buffer-substring beg end) (< end beg)) 2476 (kill-append (filter-buffer-substring beg end) (< end beg))
2434 (kill-new (buffer-substring beg end))) 2477 (kill-new (filter-buffer-substring beg end)))
2435 (if transient-mark-mode 2478 (if transient-mark-mode
2436 (setq deactivate-mark t)) 2479 (setq deactivate-mark t))
2437 nil) 2480 nil)
2438 2481
2439 (defun kill-ring-save (beg end) 2482 (defun kill-ring-save (beg end)
5182 (run-hooks 'normal-erase-is-backspace-hook) 5225 (run-hooks 'normal-erase-is-backspace-hook)
5183 (if (interactive-p) 5226 (if (interactive-p)
5184 (message "Delete key deletes %s" 5227 (message "Delete key deletes %s"
5185 (if normal-erase-is-backspace "forward" "backward")))) 5228 (if normal-erase-is-backspace "forward" "backward"))))
5186 5229
5187 (defcustom idle-update-delay 0.5
5188 "*Idle time delay before updating various things on the screen.
5189 Various Emacs features that update auxiliary information when point moves
5190 wait this many seconds after Emacs becomes idle before doing an update."
5191 :type 'number
5192 :group 'display
5193 :version "22.1")
5194
5195 (defvar vis-mode-saved-buffer-invisibility-spec nil 5230 (defvar vis-mode-saved-buffer-invisibility-spec nil
5196 "Saved value of `buffer-invisibility-spec' when Visible mode is on.") 5231 "Saved value of `buffer-invisibility-spec' when Visible mode is on.")
5197 5232
5198 (define-minor-mode visible-mode 5233 (define-minor-mode visible-mode
5199 "Toggle Visible mode. 5234 "Toggle Visible mode.