comparison lisp/emacs-lisp/advice.el @ 65680:ed770a0a7846

2005-09-24 Emilio C. Lopes <eclig@gmx.net> * woman.el (woman-file-name): * wid-edit.el (widget-file-prompt-value) (widget-coding-system-prompt-value): * w32-fns.el (set-w32-system-coding-system): * vc.el (vc-version-diff, vc-annotate): * textmodes/reftex-auc.el (reftex-arg-cite) (reftex-arg-index-tag): * textmodes/refer.el (refer-get-bib-files): * textmodes/artist.el (artist-figlet-choose-font): * terminal.el (terminal-emulator): * replace.el (occur-read-primary-args): * rect.el (string-rectangle, string-insert-rectangle): * ps-print.el (ps-print-preprint): * progmodes/pascal.el (pascal-goto-defun): * progmodes/etags.el (visit-tags-table, visit-tags-table-buffer): * progmodes/compile.el (compilation-find-file): * printing.el (pr-interactive-n-up): * play/animate.el (animate-birthday-present): * net/rcompile.el (remote-compile): * man.el (man, Man-goto-section, Man-follow-manual-reference): * mail/rmailsum.el (rmail-summary-search-backward) (rmail-summary-search): * mail/rmailout.el (rmail-output-read-rmail-file-name) (rmail-output-read-file-name): * mail/rmail.el (rmail-search, rmail-search-backwards): * mail/mailabbrev.el (merge-mail-abbrevs, rebuild-mail-abbrevs): * locate.el (locate): * international/quail.el (quail-show-keyboard-layout): * international/mule.el (set-buffer-file-coding-system) (revert-buffer-with-coding-system, set-file-name-coding-system) (set-terminal-coding-system, set-keyboard-coding-system) (set-next-selection-coding-system): * international/mule-diag.el (describe-coding-system) (describe-font, describe-fontset): * international/mule-cmds.el (universal-coding-system-argument) (search-unencodable-char, describe-input-method) (set-language-environment, describe-language-environment): * international/codepage.el (codepage-setup): * international/code-pages.el (codepage-setup): * info.el (Info-search, Info-follow-reference) (Info-search-backward): * emacs-lisp/advice.el (ad-read-advised-function) (ad-read-advice-class, ad-clear-cache, ad-activate) (ad-deactivate, ad-update, ad-unadvise, ad-read-advice-name) (ad-enable-advice, ad-disable-advice, ad-remove-advice) (ad-read-regexp): * ediff-util.el (ediff-toggle-regexp-match): * ediff-ptch.el (ediff-prompt-for-patch-file): * dired-aux.el (dired-diff): * diff.el (diff): * cus-edit.el (custom-variable-prompt): * calendar/timeclock.el (timeclock-ask-for-project): * calc/calcalg3.el (calc-get-fit-variables): * calc/calc-store.el (calc-edit-variable) (calc-permanent-variable): * vc-mcvs.el (vc-mcvs-register): * shadowfile.el (shadow-define-literal-group): * woman.el (woman-file-name): * vc.el (vc-version-diff, vc-merge): * textmodes/reftex-index.el (reftex-index-complete-tag): * format.el (format-decode-buffer, format-decode-region): * emulation/viper-cmd.el (viper-read-string-with-history): * emacs-lisp/debug.el (cancel-debug-on-entry): * emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine): * ediff.el (ediff-merge-revisions) (ediff-merge-revisions-with-ancestor, ediff-revision): * completion.el (interactive-completion-string-reader): * calc/calc-prog.el (calc-user-define-formula): Follow convention for reading with the minibuffer.
author Romain Francoise <romain@orebokech.com>
date Sat, 24 Sep 2005 13:44:02 +0000
parents 5b1a238fcbb4
children df04170ba46b ee12d75eb214
comparison
equal deleted inserted replaced
65679:56406afc87de 65680:ed770a0a7846
2216 (error "ad-read-advised-function: %s" 2216 (error "ad-read-advised-function: %s"
2217 "There are no qualifying advised functions"))) 2217 "There are no qualifying advised functions")))
2218 (let* ((ad-pReDiCaTe predicate) 2218 (let* ((ad-pReDiCaTe predicate)
2219 (function 2219 (function
2220 (completing-read 2220 (completing-read
2221 (format "%s(default %s) " (or prompt "Function: ") default) 2221 (format "%s (default %s): " (or prompt "Function") default)
2222 ad-advised-functions 2222 ad-advised-functions
2223 (if predicate 2223 (if predicate
2224 (function 2224 (function
2225 (lambda (function) 2225 (lambda (function)
2226 ;; Oops, no closures - the joys of dynamic scoping: 2226 ;; Oops, no closures - the joys of dynamic scoping:
2248 (ad-dolist (class ad-advice-classes) 2248 (ad-dolist (class ad-advice-classes)
2249 (if (ad-get-advice-info-field function class) 2249 (if (ad-get-advice-info-field function class)
2250 (ad-do-return class))) 2250 (ad-do-return class)))
2251 (error "ad-read-advice-class: `%s' has no advices" function))) 2251 (error "ad-read-advice-class: `%s' has no advices" function)))
2252 (let ((class (completing-read 2252 (let ((class (completing-read
2253 (format "%s(default %s) " (or prompt "Class: ") default) 2253 (format "%s (default %s): " (or prompt "Class") default)
2254 ad-advice-class-completion-table nil t))) 2254 ad-advice-class-completion-table nil t)))
2255 (if (equal class "") 2255 (if (equal class "")
2256 default 2256 default
2257 (intern class)))) 2257 (intern class))))
2258 2258
2266 (default 2266 (default
2267 (if (null name-completion-table) 2267 (if (null name-completion-table)
2268 (error "ad-read-advice-name: `%s' has no %s advice" 2268 (error "ad-read-advice-name: `%s' has no %s advice"
2269 function class) 2269 function class)
2270 (car (car name-completion-table)))) 2270 (car (car name-completion-table))))
2271 (prompt (format "%s(default %s) " (or prompt "Name: ") default)) 2271 (prompt (format "%s (default %s): " (or prompt "Name") default))
2272 (name (completing-read prompt name-completion-table nil t))) 2272 (name (completing-read prompt name-completion-table nil t)))
2273 (if (equal name "") 2273 (if (equal name "")
2274 (intern default) 2274 (intern default)
2275 (intern name)))) 2275 (intern name))))
2276 2276
2287 (defvar ad-last-regexp "") 2287 (defvar ad-last-regexp "")
2288 2288
2289 (defun ad-read-regexp (&optional prompt) 2289 (defun ad-read-regexp (&optional prompt)
2290 "Read a regular expression from the minibuffer." 2290 "Read a regular expression from the minibuffer."
2291 (let ((regexp (read-from-minibuffer 2291 (let ((regexp (read-from-minibuffer
2292 (concat (or prompt "Regular expression: ") 2292 (concat (or prompt "Regular expression")
2293 (if (equal ad-last-regexp "") "" 2293 (if (equal ad-last-regexp "") ": "
2294 (format "(default \"%s\") " ad-last-regexp)))))) 2294 (format " (default %s): " ad-last-regexp))))))
2295 (setq ad-last-regexp 2295 (setq ad-last-regexp
2296 (if (equal regexp "") ad-last-regexp regexp)))) 2296 (if (equal regexp "") ad-last-regexp regexp))))
2297 2297
2298 2298
2299 ;; @@ Finding, enabling, adding and removing pieces of advice: 2299 ;; @@ Finding, enabling, adding and removing pieces of advice:
2350 (ad-advice-set-enabled advice flag)))))) 2350 (ad-advice-set-enabled advice flag))))))
2351 matched-advices))) 2351 matched-advices)))
2352 2352
2353 (defun ad-enable-advice (function class name) 2353 (defun ad-enable-advice (function class name)
2354 "Enables the advice of FUNCTION with CLASS and NAME." 2354 "Enables the advice of FUNCTION with CLASS and NAME."
2355 (interactive (ad-read-advice-specification "Enable advice of: ")) 2355 (interactive (ad-read-advice-specification "Enable advice of"))
2356 (if (ad-is-advised function) 2356 (if (ad-is-advised function)
2357 (if (eq (ad-enable-advice-internal function class name t) 0) 2357 (if (eq (ad-enable-advice-internal function class name t) 0)
2358 (error "ad-enable-advice: `%s' has no %s advice matching `%s'" 2358 (error "ad-enable-advice: `%s' has no %s advice matching `%s'"
2359 function class name)) 2359 function class name))
2360 (error "ad-enable-advice: `%s' is not advised" function))) 2360 (error "ad-enable-advice: `%s' is not advised" function)))
2361 2361
2362 (defun ad-disable-advice (function class name) 2362 (defun ad-disable-advice (function class name)
2363 "Disable the advice of FUNCTION with CLASS and NAME." 2363 "Disable the advice of FUNCTION with CLASS and NAME."
2364 (interactive (ad-read-advice-specification "Disable advice of: ")) 2364 (interactive (ad-read-advice-specification "Disable advice of"))
2365 (if (ad-is-advised function) 2365 (if (ad-is-advised function)
2366 (if (eq (ad-enable-advice-internal function class name nil) 0) 2366 (if (eq (ad-enable-advice-internal function class name nil) 0)
2367 (error "ad-disable-advice: `%s' has no %s advice matching `%s'" 2367 (error "ad-disable-advice: `%s' has no %s advice matching `%s'"
2368 function class name)) 2368 function class name))
2369 (error "ad-disable-advice: `%s' is not advised" function))) 2369 (error "ad-disable-advice: `%s' is not advised" function)))
2383 2383
2384 (defun ad-enable-regexp (regexp) 2384 (defun ad-enable-regexp (regexp)
2385 "Enables all advices with names that contain a match for REGEXP. 2385 "Enables all advices with names that contain a match for REGEXP.
2386 All currently advised functions will be considered." 2386 All currently advised functions will be considered."
2387 (interactive 2387 (interactive
2388 (list (ad-read-regexp "Enable advices via regexp: "))) 2388 (list (ad-read-regexp "Enable advices via regexp")))
2389 (let ((matched-advices (ad-enable-regexp-internal regexp 'any t))) 2389 (let ((matched-advices (ad-enable-regexp-internal regexp 'any t)))
2390 (if (interactive-p) 2390 (if (interactive-p)
2391 (message "%d matching advices enabled" matched-advices)) 2391 (message "%d matching advices enabled" matched-advices))
2392 matched-advices)) 2392 matched-advices))
2393 2393
2394 (defun ad-disable-regexp (regexp) 2394 (defun ad-disable-regexp (regexp)
2395 "Disable all advices with names that contain a match for REGEXP. 2395 "Disable all advices with names that contain a match for REGEXP.
2396 All currently advised functions will be considered." 2396 All currently advised functions will be considered."
2397 (interactive 2397 (interactive
2398 (list (ad-read-regexp "Disable advices via regexp: "))) 2398 (list (ad-read-regexp "Disable advices via regexp")))
2399 (let ((matched-advices (ad-enable-regexp-internal regexp 'any nil))) 2399 (let ((matched-advices (ad-enable-regexp-internal regexp 'any nil)))
2400 (if (interactive-p) 2400 (if (interactive-p)
2401 (message "%d matching advices disabled" matched-advices)) 2401 (message "%d matching advices disabled" matched-advices))
2402 matched-advices)) 2402 matched-advices))
2403 2403
2404 (defun ad-remove-advice (function class name) 2404 (defun ad-remove-advice (function class name)
2405 "Remove FUNCTION's advice with NAME from its advices in CLASS. 2405 "Remove FUNCTION's advice with NAME from its advices in CLASS.
2406 If such an advice was found it will be removed from the list of advices 2406 If such an advice was found it will be removed from the list of advices
2407 in that CLASS." 2407 in that CLASS."
2408 (interactive (ad-read-advice-specification "Remove advice of: ")) 2408 (interactive (ad-read-advice-specification "Remove advice of"))
2409 (if (ad-is-advised function) 2409 (if (ad-is-advised function)
2410 (let* ((advice-to-remove (ad-find-advice function class name))) 2410 (let* ((advice-to-remove (ad-find-advice function class name)))
2411 (if advice-to-remove 2411 (if advice-to-remove
2412 (ad-set-advice-info-field 2412 (ad-set-advice-info-field
2413 function class 2413 function class
3283 (defun ad-clear-cache (function) 3283 (defun ad-clear-cache (function)
3284 "Clears a previously cached advised definition of FUNCTION. 3284 "Clears a previously cached advised definition of FUNCTION.
3285 Clear the cache if you want to force `ad-activate' to construct a new 3285 Clear the cache if you want to force `ad-activate' to construct a new
3286 advised definition from scratch." 3286 advised definition from scratch."
3287 (interactive 3287 (interactive
3288 (list (ad-read-advised-function "Clear cached definition of: "))) 3288 (list (ad-read-advised-function "Clear cached definition of")))
3289 (ad-set-advice-info-field function 'cache nil)) 3289 (ad-set-advice-info-field function 'cache nil))
3290 3290
3291 (defun ad-make-cache-id (function) 3291 (defun ad-make-cache-id (function)
3292 "Generate an identifying image of the current advices of FUNCTION." 3292 "Generate an identifying image of the current advices of FUNCTION."
3293 (let ((original-definition (ad-real-orig-definition function)) 3293 (let ((original-definition (ad-real-orig-definition function))
3600 pieces of advice is equivalent to a call to `ad-unadvise'. Activation of 3600 pieces of advice is equivalent to a call to `ad-unadvise'. Activation of
3601 an advised function that has actual pieces of advice but none of them are 3601 an advised function that has actual pieces of advice but none of them are
3602 enabled is equivalent to a call to `ad-deactivate'. The current advised 3602 enabled is equivalent to a call to `ad-deactivate'. The current advised
3603 definition will always be cached for later usage." 3603 definition will always be cached for later usage."
3604 (interactive 3604 (interactive
3605 (list (ad-read-advised-function "Activate advice of: ") 3605 (list (ad-read-advised-function "Activate advice of")
3606 current-prefix-arg)) 3606 current-prefix-arg))
3607 (if ad-activate-on-top-level 3607 (if ad-activate-on-top-level
3608 ;; avoid recursive calls to `ad-activate': 3608 ;; avoid recursive calls to `ad-activate':
3609 (ad-with-auto-activation-disabled 3609 (ad-with-auto-activation-disabled
3610 (if (not (ad-is-advised function)) 3610 (if (not (ad-is-advised function))
3630 If FUNCTION has a proper original definition, then the current 3630 If FUNCTION has a proper original definition, then the current
3631 definition of FUNCTION will be replaced with it. All the advice 3631 definition of FUNCTION will be replaced with it. All the advice
3632 information will still be available so it can be activated again with 3632 information will still be available so it can be activated again with
3633 a call to `ad-activate'." 3633 a call to `ad-activate'."
3634 (interactive 3634 (interactive
3635 (list (ad-read-advised-function "Deactivate advice of: " 'ad-is-active))) 3635 (list (ad-read-advised-function "Deactivate advice of" 'ad-is-active)))
3636 (if (not (ad-is-advised function)) 3636 (if (not (ad-is-advised function))
3637 (error "ad-deactivate: `%s' is not advised" function) 3637 (error "ad-deactivate: `%s' is not advised" function)
3638 (cond ((ad-is-active function) 3638 (cond ((ad-is-active function)
3639 (ad-handle-definition function) 3639 (ad-handle-definition function)
3640 (if (not (ad-get-orig-definition function)) 3640 (if (not (ad-get-orig-definition function))
3648 (defun ad-update (function &optional compile) 3648 (defun ad-update (function &optional compile)
3649 "Update the advised definition of FUNCTION if its advice is active. 3649 "Update the advised definition of FUNCTION if its advice is active.
3650 See `ad-activate' for documentation on the optional COMPILE argument." 3650 See `ad-activate' for documentation on the optional COMPILE argument."
3651 (interactive 3651 (interactive
3652 (list (ad-read-advised-function 3652 (list (ad-read-advised-function
3653 "Update advised definition of: " 'ad-is-active))) 3653 "Update advised definition of" 'ad-is-active)))
3654 (if (ad-is-active function) 3654 (if (ad-is-active function)
3655 (ad-activate function compile))) 3655 (ad-activate function compile)))
3656 3656
3657 (defun ad-unadvise (function) 3657 (defun ad-unadvise (function)
3658 "Deactivate FUNCTION and then remove all its advice information. 3658 "Deactivate FUNCTION and then remove all its advice information.
3659 If FUNCTION was not advised this will be a noop." 3659 If FUNCTION was not advised this will be a noop."
3660 (interactive 3660 (interactive
3661 (list (ad-read-advised-function "Unadvise function: "))) 3661 (list (ad-read-advised-function "Unadvise function")))
3662 (cond ((ad-is-advised function) 3662 (cond ((ad-is-advised function)
3663 (if (ad-is-active function) 3663 (if (ad-is-active function)
3664 (ad-deactivate function)) 3664 (ad-deactivate function))
3665 (ad-clear-orig-definition function) 3665 (ad-clear-orig-definition function)
3666 (ad-set-advice-info function nil) 3666 (ad-set-advice-info function nil)
3687 "Activate functions with an advice name containing a REGEXP match. 3687 "Activate functions with an advice name containing a REGEXP match.
3688 This activates the advice for each function 3688 This activates the advice for each function
3689 that has at least one piece of advice whose name includes a match for REGEXP. 3689 that has at least one piece of advice whose name includes a match for REGEXP.
3690 See `ad-activate' for documentation on the optional COMPILE argument." 3690 See `ad-activate' for documentation on the optional COMPILE argument."
3691 (interactive 3691 (interactive
3692 (list (ad-read-regexp "Activate via advice regexp: ") 3692 (list (ad-read-regexp "Activate via advice regexp")
3693 current-prefix-arg)) 3693 current-prefix-arg))
3694 (ad-do-advised-functions (function) 3694 (ad-do-advised-functions (function)
3695 (if (ad-find-some-advice function 'any regexp) 3695 (if (ad-find-some-advice function 'any regexp)
3696 (ad-activate function compile)))) 3696 (ad-activate function compile))))
3697 3697
3698 (defun ad-deactivate-regexp (regexp) 3698 (defun ad-deactivate-regexp (regexp)
3699 "Deactivate functions with an advice name containing REGEXP match. 3699 "Deactivate functions with an advice name containing REGEXP match.
3700 This deactivates the advice for each function 3700 This deactivates the advice for each function
3701 that has at least one piece of advice whose name includes a match for REGEXP." 3701 that has at least one piece of advice whose name includes a match for REGEXP."
3702 (interactive 3702 (interactive
3703 (list (ad-read-regexp "Deactivate via advice regexp: "))) 3703 (list (ad-read-regexp "Deactivate via advice regexp")))
3704 (ad-do-advised-functions (function) 3704 (ad-do-advised-functions (function)
3705 (if (ad-find-some-advice function 'any regexp) 3705 (if (ad-find-some-advice function 'any regexp)
3706 (ad-deactivate function)))) 3706 (ad-deactivate function))))
3707 3707
3708 (defun ad-update-regexp (regexp &optional compile) 3708 (defun ad-update-regexp (regexp &optional compile)
3709 "Update functions with an advice name containing a REGEXP match. 3709 "Update functions with an advice name containing a REGEXP match.
3710 This reactivates the advice for each function 3710 This reactivates the advice for each function
3711 that has at least one piece of advice whose name includes a match for REGEXP. 3711 that has at least one piece of advice whose name includes a match for REGEXP.
3712 See `ad-activate' for documentation on the optional COMPILE argument." 3712 See `ad-activate' for documentation on the optional COMPILE argument."
3713 (interactive 3713 (interactive
3714 (list (ad-read-regexp "Update via advice regexp: ") 3714 (list (ad-read-regexp "Update via advice regexp")
3715 current-prefix-arg)) 3715 current-prefix-arg))
3716 (ad-do-advised-functions (function) 3716 (ad-do-advised-functions (function)
3717 (if (ad-find-some-advice function 'any regexp) 3717 (if (ad-find-some-advice function 'any regexp)
3718 (ad-update function compile)))) 3718 (ad-update function compile))))
3719 3719