2218 |
(let* ((ad-pReDiCaTe predicate) |
(let* ((ad-pReDiCaTe predicate) |
2219 |
(function |
(function |
2220 |
(completing-read |
(completing-read |
2221 |
(format "%s(default %s) " (or prompt "Function: ") default) |
(format "%s (default %s): " (or prompt "Function") default) |
2222 |
ad-advised-functions |
ad-advised-functions |
2223 |
(if predicate |
(if predicate |
2224 |
(function |
(function |
2250 |
(ad-do-return class))) |
(ad-do-return class))) |
2251 |
(error "ad-read-advice-class: `%s' has no advices" function))) |
(error "ad-read-advice-class: `%s' has no advices" function))) |
2252 |
(let ((class (completing-read |
(let ((class (completing-read |
2253 |
(format "%s(default %s) " (or prompt "Class: ") default) |
(format "%s (default %s): " (or prompt "Class") default) |
2254 |
ad-advice-class-completion-table nil t))) |
ad-advice-class-completion-table nil t))) |
2255 |
(if (equal class "") |
(if (equal class "") |
2256 |
default |
default |
2268 |
(error "ad-read-advice-name: `%s' has no %s advice" |
(error "ad-read-advice-name: `%s' has no %s advice" |
2269 |
function class) |
function class) |
2270 |
(car (car name-completion-table)))) |
(car (car name-completion-table)))) |
2271 |
(prompt (format "%s(default %s) " (or prompt "Name: ") default)) |
(prompt (format "%s (default %s): " (or prompt "Name") default)) |
2272 |
(name (completing-read prompt name-completion-table nil t))) |
(name (completing-read prompt name-completion-table nil t))) |
2273 |
(if (equal name "") |
(if (equal name "") |
2274 |
(intern default) |
(intern default) |
2289 |
(defun ad-read-regexp (&optional prompt) |
(defun ad-read-regexp (&optional prompt) |
2290 |
"Read a regular expression from the minibuffer." |
"Read a regular expression from the minibuffer." |
2291 |
(let ((regexp (read-from-minibuffer |
(let ((regexp (read-from-minibuffer |
2292 |
(concat (or prompt "Regular expression: ") |
(concat (or prompt "Regular expression") |
2293 |
(if (equal ad-last-regexp "") "" |
(if (equal ad-last-regexp "") ": " |
2294 |
(format "(default \"%s\") " ad-last-regexp)))))) |
(format " (default %s): " ad-last-regexp)))))) |
2295 |
(setq ad-last-regexp |
(setq ad-last-regexp |
2296 |
(if (equal regexp "") ad-last-regexp regexp)))) |
(if (equal regexp "") ad-last-regexp regexp)))) |
2297 |
|
|
2352 |
|
|
2353 |
(defun ad-enable-advice (function class name) |
(defun ad-enable-advice (function class name) |
2354 |
"Enables the advice of FUNCTION with CLASS and NAME." |
"Enables the advice of FUNCTION with CLASS and NAME." |
2355 |
(interactive (ad-read-advice-specification "Enable advice of: ")) |
(interactive (ad-read-advice-specification "Enable advice of")) |
2356 |
(if (ad-is-advised function) |
(if (ad-is-advised function) |
2357 |
(if (eq (ad-enable-advice-internal function class name t) 0) |
(if (eq (ad-enable-advice-internal function class name t) 0) |
2358 |
(error "ad-enable-advice: `%s' has no %s advice matching `%s'" |
(error "ad-enable-advice: `%s' has no %s advice matching `%s'" |
2361 |
|
|
2362 |
(defun ad-disable-advice (function class name) |
(defun ad-disable-advice (function class name) |
2363 |
"Disable the advice of FUNCTION with CLASS and NAME." |
"Disable the advice of FUNCTION with CLASS and NAME." |
2364 |
(interactive (ad-read-advice-specification "Disable advice of: ")) |
(interactive (ad-read-advice-specification "Disable advice of")) |
2365 |
(if (ad-is-advised function) |
(if (ad-is-advised function) |
2366 |
(if (eq (ad-enable-advice-internal function class name nil) 0) |
(if (eq (ad-enable-advice-internal function class name nil) 0) |
2367 |
(error "ad-disable-advice: `%s' has no %s advice matching `%s'" |
(error "ad-disable-advice: `%s' has no %s advice matching `%s'" |
2385 |
"Enables all advices with names that contain a match for REGEXP. |
"Enables all advices with names that contain a match for REGEXP. |
2386 |
All currently advised functions will be considered." |
All currently advised functions will be considered." |
2387 |
(interactive |
(interactive |
2388 |
(list (ad-read-regexp "Enable advices via regexp: "))) |
(list (ad-read-regexp "Enable advices via regexp"))) |
2389 |
(let ((matched-advices (ad-enable-regexp-internal regexp 'any t))) |
(let ((matched-advices (ad-enable-regexp-internal regexp 'any t))) |
2390 |
(if (interactive-p) |
(if (interactive-p) |
2391 |
(message "%d matching advices enabled" matched-advices)) |
(message "%d matching advices enabled" matched-advices)) |
2395 |
"Disable all advices with names that contain a match for REGEXP. |
"Disable all advices with names that contain a match for REGEXP. |
2396 |
All currently advised functions will be considered." |
All currently advised functions will be considered." |
2397 |
(interactive |
(interactive |
2398 |
(list (ad-read-regexp "Disable advices via regexp: "))) |
(list (ad-read-regexp "Disable advices via regexp"))) |
2399 |
(let ((matched-advices (ad-enable-regexp-internal regexp 'any nil))) |
(let ((matched-advices (ad-enable-regexp-internal regexp 'any nil))) |
2400 |
(if (interactive-p) |
(if (interactive-p) |
2401 |
(message "%d matching advices disabled" matched-advices)) |
(message "%d matching advices disabled" matched-advices)) |
2405 |
"Remove FUNCTION's advice with NAME from its advices in CLASS. |
"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 |
If such an advice was found it will be removed from the list of advices |
2407 |
in that CLASS." |
in that CLASS." |
2408 |
(interactive (ad-read-advice-specification "Remove advice of: ")) |
(interactive (ad-read-advice-specification "Remove advice of")) |
2409 |
(if (ad-is-advised function) |
(if (ad-is-advised function) |
2410 |
(let* ((advice-to-remove (ad-find-advice function class name))) |
(let* ((advice-to-remove (ad-find-advice function class name))) |
2411 |
(if advice-to-remove |
(if advice-to-remove |
3285 |
Clear the cache if you want to force `ad-activate' to construct a new |
Clear the cache if you want to force `ad-activate' to construct a new |
3286 |
advised definition from scratch." |
advised definition from scratch." |
3287 |
(interactive |
(interactive |
3288 |
(list (ad-read-advised-function "Clear cached definition of: "))) |
(list (ad-read-advised-function "Clear cached definition of"))) |
3289 |
(ad-set-advice-info-field function 'cache nil)) |
(ad-set-advice-info-field function 'cache nil)) |
3290 |
|
|
3291 |
(defun ad-make-cache-id (function) |
(defun ad-make-cache-id (function) |
3602 |
enabled is equivalent to a call to `ad-deactivate'. The current advised |
enabled is equivalent to a call to `ad-deactivate'. The current advised |
3603 |
definition will always be cached for later usage." |
definition will always be cached for later usage." |
3604 |
(interactive |
(interactive |
3605 |
(list (ad-read-advised-function "Activate advice of: ") |
(list (ad-read-advised-function "Activate advice of") |
3606 |
current-prefix-arg)) |
current-prefix-arg)) |
3607 |
(if ad-activate-on-top-level |
(if ad-activate-on-top-level |
3608 |
;; avoid recursive calls to `ad-activate': |
;; avoid recursive calls to `ad-activate': |
3632 |
information will still be available so it can be activated again with |
information will still be available so it can be activated again with |
3633 |
a call to `ad-activate'." |
a call to `ad-activate'." |
3634 |
(interactive |
(interactive |
3635 |
(list (ad-read-advised-function "Deactivate advice of: " 'ad-is-active))) |
(list (ad-read-advised-function "Deactivate advice of" 'ad-is-active))) |
3636 |
(if (not (ad-is-advised function)) |
(if (not (ad-is-advised function)) |
3637 |
(error "ad-deactivate: `%s' is not advised" function) |
(error "ad-deactivate: `%s' is not advised" function) |
3638 |
(cond ((ad-is-active function) |
(cond ((ad-is-active function) |
3650 |
See `ad-activate' for documentation on the optional COMPILE argument." |
See `ad-activate' for documentation on the optional COMPILE argument." |
3651 |
(interactive |
(interactive |
3652 |
(list (ad-read-advised-function |
(list (ad-read-advised-function |
3653 |
"Update advised definition of: " 'ad-is-active))) |
"Update advised definition of" 'ad-is-active))) |
3654 |
(if (ad-is-active function) |
(if (ad-is-active function) |
3655 |
(ad-activate function compile))) |
(ad-activate function compile))) |
3656 |
|
|
3658 |
"Deactivate FUNCTION and then remove all its advice information. |
"Deactivate FUNCTION and then remove all its advice information. |
3659 |
If FUNCTION was not advised this will be a noop." |
If FUNCTION was not advised this will be a noop." |
3660 |
(interactive |
(interactive |
3661 |
(list (ad-read-advised-function "Unadvise function: "))) |
(list (ad-read-advised-function "Unadvise function"))) |
3662 |
(cond ((ad-is-advised function) |
(cond ((ad-is-advised function) |
3663 |
(if (ad-is-active function) |
(if (ad-is-active function) |
3664 |
(ad-deactivate function)) |
(ad-deactivate function)) |
3689 |
that has at least one piece of advice whose name includes a match for REGEXP. |
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." |
See `ad-activate' for documentation on the optional COMPILE argument." |
3691 |
(interactive |
(interactive |
3692 |
(list (ad-read-regexp "Activate via advice regexp: ") |
(list (ad-read-regexp "Activate via advice regexp") |
3693 |
current-prefix-arg)) |
current-prefix-arg)) |
3694 |
(ad-do-advised-functions (function) |
(ad-do-advised-functions (function) |
3695 |
(if (ad-find-some-advice function 'any regexp) |
(if (ad-find-some-advice function 'any regexp) |
3700 |
This deactivates the advice for each function |
This deactivates the advice for each function |
3701 |
that has at least one piece of advice whose name includes a match for REGEXP." |
that has at least one piece of advice whose name includes a match for REGEXP." |
3702 |
(interactive |
(interactive |
3703 |
(list (ad-read-regexp "Deactivate via advice regexp: "))) |
(list (ad-read-regexp "Deactivate via advice regexp"))) |
3704 |
(ad-do-advised-functions (function) |
(ad-do-advised-functions (function) |
3705 |
(if (ad-find-some-advice function 'any regexp) |
(if (ad-find-some-advice function 'any regexp) |
3706 |
(ad-deactivate function)))) |
(ad-deactivate function)))) |
3711 |
that has at least one piece of advice whose name includes a match for REGEXP. |
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." |
See `ad-activate' for documentation on the optional COMPILE argument." |
3713 |
(interactive |
(interactive |
3714 |
(list (ad-read-regexp "Update via advice regexp: ") |
(list (ad-read-regexp "Update via advice regexp") |
3715 |
current-prefix-arg)) |
current-prefix-arg)) |
3716 |
(ad-do-advised-functions (function) |
(ad-do-advised-functions (function) |
3717 |
(if (ad-find-some-advice function 'any regexp) |
(if (ad-find-some-advice function 'any regexp) |