Skip to content

Commit

Permalink
define enter and exit functions
Browse files Browse the repository at this point in the history
In some cases, it's convenient to have these as thunks, so we define
these within the mode definition macro expansions in addition to
providing the usual toggle function from the underlying minor mode.
  • Loading branch information
countvajhula committed Sep 2, 2024
1 parent 092d124 commit 431fff9
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions lithium.el
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ enters the mode in all buffers, and any entry hooks are run just once
at this time. Likewise, exiting while in any buffer exits the mode in
all buffers, and the exit hooks are run just once.
This also defines `NAME-enter' and `NAME-exit' functions which accept
no arguments and enter and exit the mode, respectively.
DOCSTRING, KEYMAP-SPEC and BODY are forwarded to
`lithium-define-mode'."
(declare (indent defun))
Expand All @@ -199,7 +202,13 @@ DOCSTRING, KEYMAP-SPEC and BODY are forwarded to
(post-exit (intern (concat (symbol-name name) "-post-exit-hook")))
(local-name (intern (concat "local-" (symbol-name name))))
;; note the keymap is part of the local rather than global mode
(keymap (intern (concat "local-" (symbol-name name) "-map"))))
(keymap (intern (concat "local-" (symbol-name name) "-map")))
(exit-mode (intern
(concat (symbol-name name)
"-exit")))
(enter-mode (intern
(concat (symbol-name name)
"-enter"))))
`(progn

(defvar ,pre-entry nil
Expand Down Expand Up @@ -243,6 +252,14 @@ DOCSTRING, KEYMAP-SPEC and BODY are forwarded to
;; unregister this as a promoted overriding map
(setq lithium-overriding-map nil)))

(defun ,enter-mode ()
"Enter mode."
(lithium-enter-mode ',name))

(defun ,exit-mode ()
"Exit mode."
(lithium-exit-mode ',name))

;; mark this mode as a global mode
;; for use in application-level predicates
(put ',name 'lithium-global t))))
Expand All @@ -254,14 +271,23 @@ DOCSTRING, KEYMAP-SPEC and BODY are forwarded to
body)
"Define a lithium mode named NAME that's local to a buffer.
This also defines `NAME-enter' and `NAME-exit' functions which accept
no arguments and enter and exit the mode, respectively.
DOCSTRING, KEYMAP-SPEC and BODY are forwarded to
`lithium-define-mode'."
(declare (indent defun))
(let ((pre-entry (intern (concat (symbol-name name) "-pre-entry-hook")))
(post-entry (intern (concat (symbol-name name) "-post-entry-hook")))
(pre-exit (intern (concat (symbol-name name) "-pre-exit-hook")))
(post-exit (intern (concat (symbol-name name) "-post-exit-hook")))
(keymap (intern (concat (symbol-name name) "-map"))))
(keymap (intern (concat (symbol-name name) "-map")))
(exit-mode (intern
(concat (symbol-name name)
"-exit")))
(enter-mode (intern
(concat (symbol-name name)
"-enter"))))
`(progn

(defvar ,pre-entry nil
Expand Down Expand Up @@ -294,6 +320,14 @@ DOCSTRING, KEYMAP-SPEC and BODY are forwarded to
;; unregister this as a promoted overriding map
(setq lithium-overriding-map nil)))

(defun ,enter-mode ()
"Enter mode."
(lithium-enter-mode ',name))

(defun ,exit-mode ()
"Exit mode."
(lithium-exit-mode ',name))

;; mark this mode as a local mode - not technically needed
;; since properties default to nil, but for good measure
(put ',name 'lithium-global nil))))
Expand Down

0 comments on commit 431fff9

Please sign in to comment.