Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce mode rings #19

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chimera-hydra.el
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,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
64 changes: 49 additions & 15 deletions rigpa-mode-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
(require 'chimera)
(require 'rigpa-text-parsers)
(require 'rigpa-meta)
(require 'dynaring)

(evil-define-state mode
"Mode state."
Expand Down Expand Up @@ -151,24 +152,57 @@ to ensure, upon state transitions, that:
"Enter mode MODE-NAME."
(chimera-enter-mode (ht-get rigpa-modes mode-name)))

(defun rigpa--rotate-mode-ring (direction)
"Rotate the current mode ring in DIRECTION."
(interactive)
(let* ((tower (rigpa--local-tower))
(tower-height (rigpa-ensemble-size tower))
(level-number (max (min rigpa--current-level
(1- tower-height))
0))
(ring (rigpa-ensemble-member-at-position tower
level-number)))
(funcall direction ring)
(rigpa-enter-mode
(rigpa-editing-entity-name
(dynaring-value ring)))))

(defun rigpa-rotate-mode-ring-left ()
"Rotate the current mode ring to the left."
(interactive)
(rigpa--rotate-mode-ring #'dynaring-rotate-left))

(defun rigpa-rotate-mode-ring-right ()
"Rotate the current mode ring to the right."
(interactive)
(rigpa--rotate-mode-ring #'dynaring-rotate-right))

(defun rigpa--enter-level (level-number)
"Enter level LEVEL-NUMBER"
(let* ((tower (rigpa--local-tower))
(tower-height (rigpa-ensemble-size tower))
(level-number (max (min level-number
(1- tower-height))
0)))
(let ((mode-name (rigpa-editing-entity-name
(rigpa-ensemble-member-at-position tower level-number))))
0))
(level (rigpa-ensemble-member-at-position tower
level-number))
(mode (if (dynaringp level)
(dynaring-value level)
level)))
(let ((mode-name (rigpa-editing-entity-name mode)))
;; so, we're expecting the tower to be a list containing
;; _modes_. Instead, we want to change it to contain
;; _mode rings_. Let's first convert it into a mode ring
;; containing a single element.
(rigpa-enter-mode mode-name)
(setq rigpa--current-level level-number))))

(defun rigpa-enter-lower-level ()
"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 @@ -196,8 +230,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 @@ -216,8 +250,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 @@ -300,11 +334,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 All @@ -313,7 +347,7 @@ is precisely the thing to be done."

(defun rigpa-serialize-mode (mode tower level-number)
"A string representation of a mode."
(let ((name (rigpa-editing-entity-name mode)))
(let ((name (rigpa-editing-entity-name (if (dynaringp mode) (dynaring-value mode) mode))))
(concat "|―――"
(number-to-string level-number)
"―――|"
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
14 changes: 9 additions & 5 deletions rigpa-types.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

(require 'cl-lib)
(require 'chimera)
(require 'dynaring)

(cl-defstruct editing-ensemble
"Specification for an editing ensemble."
Expand All @@ -48,10 +49,17 @@ entity, such as modes, towers or complexes.")

(defun rigpa-ensemble-member-position-by-name (ensemble name)
"The position of a member in an ensemble, by name."
(seq-position (seq-map #'rigpa-editing-entity-name
(seq-position (seq-map (lambda (m) (rigpa-editing-entity-name (if (dynaringp m) (dynaring-value m) m)))
(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 @@ -60,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
14 changes: 10 additions & 4 deletions rigpa.el
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,15 @@ and simply toggles whether the menu is visible or not."
(let ((keymap (symbol-value
(intern
(concat "evil-" state "-state-map")))))
(define-key keymap [escape] #'rigpa-enter-higher-level)
(unless (member state chimera-insertion-states)
(if (member state chimera-insertion-states)
(define-key keymap [escape] #'rigpa-enter-higher-level)
(define-key keymap [escape] (lambda ()
(interactive)
(if (equal "lisp"
(rigpa-editing-entity-name
(rigpa--local-tower)))
(rigpa-rotate-mode-ring-left)
(rigpa-enter-higher-level))))
(define-key keymap [return] #'rigpa--enter-lower-or-pass-through))))
;; exit visual state gracefully
(define-key evil-visual-state-map [escape] (lambda ()
Expand Down Expand Up @@ -333,8 +340,7 @@ and simply toggles whether the menu is visible or not."
(make-editing-ensemble :name "lisp"
:default "symex"
:members (list chimera-insert-mode
chimera-symex-mode
chimera-normal-mode)))
(dynaring chimera-normal-mode chimera-symex-mode))))

;; complexes for base editing levels
(setq rigpa-general-complex
Expand Down
Loading