[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A way for interactive to modify a let-bound variable?
From: |
Kaushal Modi |
Subject: |
Re: A way for interactive to modify a let-bound variable? |
Date: |
Fri, 12 Feb 2016 13:18:02 -0500 |
This is the actual function I want to optimize (Reference:
http://thread.gmane.org/gmane.emacs.help/109025/focus=109137 ).
(defun modi/advice-region-or-whole (orig-fun &rest args)
(interactive (if (use-region-p)
(list (region-beginning) (region-end))
(list (point-min) (point-max))))
(prog1
(apply orig-fun args) ; this defun NEEDS to return this form's value
(when (and (called-interactively-p 'interactive) ; duplication of
condition
(not (use-region-p))) ;
(message "Executed %s on the whole buffer."
(propertize (symbol-name this-command)
'face 'font-lock-function-name-face)))))
This is an :around advice function and it needs to return the (apply
orig-fun args) value.
> You can of course use `let' _inside_ `interactive'
If I move the let form inside interactive, the let form needs to return the
list required for interactive. Then how would I return the (apply ..) value?
Eventually I want something like below that actually works:
(defun modi/advice-region-or-whole (orig-fun &rest args)
(let (msg)
(interactive (if (use-region-p)
(list (region-beginning) (region-end))
(setq msg (format "Executed %s on the whole buffer."
(propertize (symbol-name this-command)
'face
'font-lock-function-name-face)))
(list (point-min) (point-max))))
(prog1
(apply orig-fun args)
(when msg
(message msg)))))