File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -205,4 +205,33 @@ Only parenthesized nodes are supported at the moment."
205205 (shm-insert-string " qualified" )
206206 (just-one-space 1 ))))))))
207207
208+ (defun shm/bind-toggle ()
209+ " Swap the monadicness of a bind."
210+ (interactive )
211+ (let ((node (shm-get-binding-parent (shm-current-node-pair))))
212+ (case (shm-node-cons node)
213+ (Generator (progn (goto-char (shm-node-start node))
214+ (search-forward " <- " )
215+ (delete-region (- (point ) (length " <- " ))
216+ (point ))
217+ (insert " = " )
218+ (goto-char (shm-node-start node))
219+ (shm-insert-string " let " )))
220+ (LetStmt (progn (goto-char (shm-node-start node))
221+ (delete-region (point ) (+ (point ) (length " let " )))
222+ (search-forward " = " )
223+ (delete-region (- (point ) (length " = " ))
224+ (point ))
225+ (insert " <- " ))))))
226+
227+ (defun shm-get-binding-parent (node-pair )
228+ " Get the binding parent of the node."
229+ (if (or (eq 'Generator (shm-node-cons (cdr node-pair)))
230+ (eq 'LetStmt (shm-node-cons (cdr node-pair))))
231+ (cdr node-pair)
232+ (let ((parent-pair (shm-node-parent node-pair)))
233+ (if parent-pair
234+ (shm-get-binding-parent parent-pair)
235+ (error " Couldn't find a let/generator statement in the node's parents. " )))))
236+
208237(provide 'shm-manipulation )
You can’t perform that action at this time.
0 commit comments