> +(defmacro org-test-with-minor-mode (mode state &rest body) > + "Run BODY after setting MODE to STATE. > +Restore MODE to its former state afterward." > + (declare (debug (sexp sexp body)) (indent 2)) > + `(let ((old-state ,mode)) > + (,mode (if ,state 1 0)) > + ,@body > + (,mode (if old-state 1 0))))
This should probably use `unwind-protect` in case `body` exits non-locally. [ And also, for buffer-local minor modes, we should try and be careful to restore the mode in the same buffer, tho this can be pushed as a responsability of `body`. ] Stefan