Skip to content

Commit

Permalink
Merge pull request #587 from keram/update-pr-465-v2
Browse files Browse the repository at this point in the history
Restore position after case split
  • Loading branch information
jfdm committed Dec 8, 2022
2 parents 744f773 + cc09857 commit 1c62469
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions idris-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -567,19 +567,20 @@ Useful for writing papers or slides."


(defun idris-case-split ()
"Case split the pattern variable at point"
"Case split the pattern variable at point."
(interactive)
(let ((what (idris-thing-at-point)))
(when (car what)
(save-excursion (idris-load-file-sync))
(let ((result (car (idris-eval `(:case-split ,(cdr what) ,(car what))))))
(let ((result (car (idris-eval `(:case-split ,(cdr what) ,(car what)))))
(initial-position (point)))
(if (<= (length result) 2)
(message "Can't case split %s" (car what))
(delete-region (line-beginning-position) (line-end-position))
(if (> idris-protocol-version 1)
(insert (substring result 0 (length result)))
(insert (substring result 0 (1- (length result))))
))))))
(insert (substring result 0 (1- (length result)))))
(goto-char initial-position))))))

(defun idris-make-cases-from-hole ()
"Make a case expression from the metavariable at point."
Expand All @@ -593,8 +594,8 @@ Useful for writing papers or slides."
(delete-region (line-beginning-position) (line-end-position))
(if (> idris-protocol-version 1)
(insert (substring result 0 (length result)))
(insert (substring result 0 (1- (length result))))
))))))
(insert (substring result 0 (1- (length result)))))
(search-backward "_ of\n"))))))

(defun idris-case-dwim ()
"If point is on a hole name, make it into a case expression.
Expand Down

0 comments on commit 1c62469

Please sign in to comment.