elisp - Emacs minor mode programming: cancel toggle-off procedure? -
i programming own emacs minor mode using idioms , macros similar minimal example:
(define-minor-mode foo-mode "toggle foo mode." :init-value nil :lighter " foo" :group 'foo (if foo-mode (do-enable-foo) (do-disable-foo)) ) (defun do-enable-foo () "enable foo minor mode" (message "enabling foo...") (if test-something (message "foo enabled after disabling canceled!") (message "foo enabled scratch")) ) (defun do-disable-foo () "disable foo minor mode" (message "disabling foo...") (if (not certain-situation) (message "... done.") ; finish disabling foo ;; else forms: (message "need cancel disabling foo!") (foo-mode 1)) ; turning foo mode on again )
during toggling off of minor mode, 'certain-situation
may arise when have cancel toggling off. currently, thinking since using define-minor-mode
macro, cannot bail out have programmatically turn mode on again using (foo-mode 1)
seen in code.
if go route, have handle differently in enabling function do-enable-foo
-- first question how detect case using placeholder 'test-something
in code above?
or, there cleaner way achieve cancel, example, signaling error instead of (foo-mode 1)
prevent mode toggle going through?
if want cancel "turn off", rather call (foo-mode 1)
, can (setq foo-mode t)
.
if reason want call (foo-mode 1)
recursively (re)enable mode, can in following way:
(defvar foo-mode--reenabling nil) .... (defun do-enable-foo () (if foo-mode--reenabling ... ...)) ... (defun do-disable-foo () ... (let ((foo-mode--reenabling t)) (foo-mode 1)))
Comments
Post a Comment