Skip to content

Commit

Permalink
Basic working mode rings
Browse files Browse the repository at this point in the history
Rings are a natural structure to use for modes. This has been planned
for a long time and this is a basic working version that we can
iterate on. It replaces modes with mode rings at a particular level in
a specific tower (lisp tower, so that we can rotate normal → symex →
normal), and stays behind black box interfaces.
  • Loading branch information
countvajhula committed Mar 26, 2024
1 parent 915712f commit 59140e9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
38 changes: 34 additions & 4 deletions rigpa-mode-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
(require 'evil)
(require 'rigpa-text-parsers)
(require 'rigpa-meta)
(require 'dynaring)

(evil-define-state mode
"Mode state."
Expand Down Expand Up @@ -150,15 +151,44 @@ 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
Expand Down Expand Up @@ -316,7 +346,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
3 changes: 2 additions & 1 deletion 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,7 +49,7 @@ 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))

Expand Down
3 changes: 1 addition & 2 deletions rigpa.el
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,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

0 comments on commit 59140e9

Please sign in to comment.