Skip to content

Commit

Permalink
Toggle evil supporting minor modes via lifecycle hooks
Browse files Browse the repository at this point in the history
This streamlines these actions so they're taken at the appropriate
points in the mode transition lifecycle. Currently, some of these are
no longer functioning correctly (e.g. keybindings no longer active in
Symex state, #9), but we'll hopefully restore their functioning in a
proper way as we go.
  • Loading branch information
countvajhula committed Aug 7, 2024
1 parent 1046964 commit 8f2ff66
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
4 changes: 2 additions & 2 deletions rigpa-char-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@
(defvar chimera-char-mode-exit-hook nil
"Exit hook for rigpa char mode.")

(defun rigpa--enable-char-minor-mode ()
(defun rigpa--on-char-mode-pre-entry ()
"Enable char minor mode."
(rigpa-char-mode 1))

(defun rigpa--disable-char-minor-mode ()
(defun rigpa--on-char-mode-post-exit ()
"Disable char minor mode."
(rigpa-char-mode -1))

Expand Down
13 changes: 5 additions & 8 deletions rigpa-line-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,18 @@ From: https://emacs.stackexchange.com/questions/17846/calculating-the-length-of-
(defvar chimera-line-mode-exit-hook nil
"Exit hook for rigpa line mode.")

(defun rigpa--enable-line-minor-mode ()
(defun rigpa--on-line-mode-pre-entry ()
"Enable line minor mode."
;; probably want to rename this function to reflect
;; its broader scope of line mode entry actions
(rigpa-line-mode 1)
(setq rigpa-line--column (current-column))
(beginning-of-line)
(hl-line-mode 1))

(defun rigpa--disable-line-minor-mode ()
(defun rigpa--on-line-mode-post-exit ()
"Disable line minor mode."
(when rigpa-line-mode
(rigpa-line-mode -1)
(hl-line-mode -1)
(evil-goto-column rigpa-line--column)))
(rigpa-line-mode -1)
(hl-line-mode -1)
(evil-goto-column rigpa-line--column))

(defvar chimera-line-mode
(make-chimera-mode :name "line"
Expand Down
27 changes: 9 additions & 18 deletions rigpa-mode-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ to parametrize the hook function but still be able to remove it."
(concat "rigpa--enable-" name "-minor-mode"))))
enable-mode))

(defun rigpa--on-mode-pre-entry (name)
"Return the function that takes actions upon mode pre-entry."
(intern
(concat "rigpa--on-" name "-mode-pre-entry")))

(defun rigpa--on-mode-entry (name)
"Return the function that takes actions upon mode entry."
(intern
Expand All @@ -77,18 +82,6 @@ to parametrize the hook function but still be able to remove it."
(intern
(concat "rigpa--on-" name "-mode-post-exit")))

(defun rigpa--disable-other-minor-modes ()
"Disable all rigpa mode minor modes.
This is called on state transitions to ensure that all minor modes are
first disabled prior to the minor mode for new state being enabled."
(dolist (name (ht-keys rigpa-modes))
(let ((disable-mode
(intern
(concat "rigpa--disable-" name "-minor-mode"))))
(when (fboundp disable-mode)
(funcall disable-mode)))))

(defun rigpa-register-mode (mode)
"Register MODE for use with rigpa.
Expand All @@ -103,20 +96,19 @@ to ensure, upon state transitions, that:
(exit-hook (chimera-mode-exit-hook mode))
(post-exit-hook (chimera-mode-post-exit-hook mode)))
(ht-set! rigpa-modes name mode)
(let ((minor-mode-entry (rigpa--minor-mode-enabler name)))
(when (fboundp minor-mode-entry)
(add-hook pre-entry-hook minor-mode-entry)))
(let ((fn (rigpa--on-mode-entry name)))
(let ((fn (rigpa--on-mode-pre-entry name)))
(when (fboundp fn)
(add-hook pre-entry-hook fn)))
(let ((fn (rigpa--on-mode-entry name)))
(when (fboundp fn)
(add-hook entry-hook fn)))
(let ((fn (rigpa--on-mode-exit name)))
(when (fboundp fn)
(add-hook exit-hook fn)))
(let ((fn (rigpa--on-mode-post-exit name)))
(when (fboundp fn)
(add-hook post-exit-hook fn)))
(add-hook entry-hook #'rigpa-reconcile-level)
(add-hook pre-entry-hook #'rigpa--disable-other-minor-modes)
(add-hook exit-hook #'rigpa-remember-for-recall)))

(defun rigpa-unregister-mode (mode)
Expand All @@ -140,7 +132,6 @@ to ensure, upon state transitions, that:
(when (fboundp fn)
(remove-hook post-exit-hook fn)))
(remove-hook entry-hook #'rigpa-reconcile-level)
(remove-hook pre-entry-hook #'rigpa--disable-other-minor-modes)
(remove-hook exit-hook #'rigpa-remember-for-recall)))

(defun rigpa-enter-mode (mode-name)
Expand Down
4 changes: 2 additions & 2 deletions rigpa-symex-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
(defvar chimera-symex-mode-exit-hook nil
"Exit hook for rigpa symex mode.")

(defun rigpa--enable-symex-minor-mode ()
(defun rigpa--on-symex-mode-pre-entry ()
"Enable symex minor mode."
(symex-enable-editing-minor-mode))

(defun rigpa--disable-symex-minor-mode ()
(defun rigpa--on-symex-mode-post-exit ()
"Disable symex minor mode."
(symex-disable-editing-minor-mode))

Expand Down
4 changes: 2 additions & 2 deletions rigpa-word-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@
(defvar chimera-word-mode-exit-hook nil
"Exit hook for rigpa word mode.")

(defun rigpa--enable-word-minor-mode ()
(defun rigpa--on-word-mode-pre-entry ()
"Enable word minor mode."
(rigpa-word-mode 1))

(defun rigpa--disable-word-minor-mode ()
(defun rigpa--on-word-mode-post-exit ()
"Disable word minor mode."
(rigpa-word-mode -1))

Expand Down

0 comments on commit 8f2ff66

Please sign in to comment.