Skip to content

Commit

Permalink
improve a predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
countvajhula committed Jun 13, 2024
1 parent 73dfed9 commit 9c5b422
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions chimera-hydra.el
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ If no VALUE is provided, this clears the flag."
;; already in the tower?
;; [doing this for now to fix symex margins issue, but
;; not sure exactly what is happening there]
(unless (rigpa-ensemble-member-position-by-name (rigpa--local-tower)
(symbol-name evil-state))
(unless (rigpa--member-of-ensemble-p (rigpa--local-tower)
(symbol-name evil-state))
(rigpa--enter-appropriate-mode)))
(let* ((hydra (chimera--hydra-for-state mode-name))
(entry-buffer (hydra-get-property hydra :entry-buffer)))
Expand Down
22 changes: 11 additions & 11 deletions rigpa-mode-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ to ensure, upon state transitions, that:
"Enter lower level."
(interactive)
(let ((mode-name (symbol-name evil-state)))
(if (rigpa-ensemble-member-position-by-name (rigpa--local-tower)
mode-name)
(if (rigpa--member-of-ensemble-p (rigpa--local-tower)
mode-name)
(when (> rigpa--current-level 0)
(rigpa--enter-level (1- rigpa--current-level)))
;; "not my tower, not my problem"
Expand Down Expand Up @@ -229,8 +229,8 @@ Priority: (1) provided mode if admissible (i.e. present in tower) [TODO]
(current-mode-name (chimera-mode-name current-mode))
(recall-mode-name (rigpa--local-recall-mode))
(default-mode-name (editing-ensemble-default (rigpa--local-tower))))
(cond ((rigpa--member-of-ensemble-p current-mode
(rigpa--local-tower))
(cond ((rigpa--member-of-ensemble-p (rigpa--local-tower)
current-mode-name)
;; we don't want to do anything in this case,
;; but re-enter the current mode to ensure
;; that it reconciles state with the new tower
Expand All @@ -249,8 +249,8 @@ Priority: (1) provided mode if admissible (i.e. present in tower) [TODO]
;; TODO: using evil-state doesn't work in buffer mode
;; since the other buffer is in a local (e.g. Insert) state
;; rather than buffer state
(if (rigpa-ensemble-member-position-by-name (rigpa--local-tower)
mode-name)
(if (rigpa--member-of-ensemble-p (rigpa--local-tower)
mode-name)
(when (< rigpa--current-level
(1- (rigpa-ensemble-size (rigpa--local-tower))))
(rigpa--enter-level (1+ rigpa--current-level)))
Expand Down Expand Up @@ -333,11 +333,11 @@ is precisely the thing to be done."
(recall rigpa-recall))
;; only set recall here if it is currently in the tower AND
;; going to a state outside the tower
(when (and (rigpa-ensemble-member-position-by-name (rigpa--local-tower)
mode-name)
(not (rigpa-ensemble-member-position-by-name
(rigpa--local-tower)
(symbol-name evil-next-state))))
(when (and (rigpa--member-of-ensemble-p (rigpa--local-tower)
mode-name)
(not
(rigpa--member-of-ensemble-p (rigpa--local-tower)
(symbol-name evil-next-state))))
(rigpa-set-mode-recall mode-name)))))

(defun rigpa-set-mode-recall (mode-name)
Expand Down
4 changes: 2 additions & 2 deletions rigpa-tower-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
(ground-recall (with-current-buffer ground-buffer
rigpa-recall))
(level (or (rigpa-ensemble-member-position-by-name tower
ground-mode-name)
ground-mode-name)
(and ground-recall
(rigpa-ensemble-member-position-by-name tower
ground-recall))
ground-recall))
0))
(tower-height (rigpa-ensemble-size tower)))
(evil-goto-line (- tower-height level))))
Expand Down
11 changes: 7 additions & 4 deletions rigpa-types.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ entity, such as modes, towers or complexes.")
(editing-ensemble-members ensemble))
name))

(defun rigpa--member-of-ensemble-p (ensemble entity-name)
"A predicate asserting whether ENTITY-NAME is a member of ENSEMBLE."
(not
(not
(rigpa-ensemble-member-position-by-name ensemble
entity-name))))

(defun rigpa-ensemble-size (ensemble)
"Size of ensemble (e.g. height of a tower)."
(length (editing-ensemble-members ensemble)))
Expand All @@ -61,10 +68,6 @@ entity, such as modes, towers or complexes.")
"Mode at LEVEL in the TOWER."
(nth position (editing-ensemble-members tower)))

(defun rigpa--member-of-ensemble-p (entity ensemble)
"A predicate asserting whether ENTITY is a member of ENSEMBLE."
(memq entity (editing-ensemble-members ensemble)))


(provide 'rigpa-types)
;;; rigpa-types.el ends here

0 comments on commit 9c5b422

Please sign in to comment.