I'm trying to write a function/macro to wrap arbitrary interactive function with some pre- and post- processing. Those processing does not involve the arguments of the interactive function.
For example, give f =
delete-region, I'd like to write a function/macro that return a new function g =
delete-region-wrapper with the definition like
(defun delete-region-wrapper (begin end) # or maybe (&rest args)... (interactive "r") (read-only-mode -1) # 'pre-processing' (delete-region begin end) # or maybe (apply #'delete-region ...) or maybe (funcall #'delete-region ... ) (read-only-mode 1)) # 'post-processing'
Or the Python equivalent looks like
def wrap(f): def wrapper(*args, **kwargs): read_only_mode(-1) res = f(*args, **kwargs) read_only_mode(1) return res return wrapper delete_region_wrapper = wrap(delete_region)
How can I write this
(defmacro/defun wrap(f) ??? ) (setq delete-region-wrapper (wrap #'delete-region))