From 9c5b422c7340713d4fbf914555b573124ab6173c Mon Sep 17 00:00:00 2001 From: Siddhartha Date: Tue, 26 Mar 2024 16:18:17 -0700 Subject: [PATCH] improve a predicate --- chimera-hydra.el | 4 ++-- rigpa-mode-mode.el | 22 +++++++++++----------- rigpa-tower-mode.el | 4 ++-- rigpa-types.el | 11 +++++++---- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/chimera-hydra.el b/chimera-hydra.el index 76d3f79..46b7259 100644 --- a/chimera-hydra.el +++ b/chimera-hydra.el @@ -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))) diff --git a/rigpa-mode-mode.el b/rigpa-mode-mode.el index ebf6f41..c12361b 100644 --- a/rigpa-mode-mode.el +++ b/rigpa-mode-mode.el @@ -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" @@ -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 @@ -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))) @@ -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) diff --git a/rigpa-tower-mode.el b/rigpa-tower-mode.el index 3e720de..cdb067a 100644 --- a/rigpa-tower-mode.el +++ b/rigpa-tower-mode.el @@ -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)))) diff --git a/rigpa-types.el b/rigpa-types.el index 635047c..1b37d7a 100644 --- a/rigpa-types.el +++ b/rigpa-types.el @@ -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))) @@ -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