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

Restore location when case split #465

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions idris-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,10 @@ KILLFLAG is set if N was explicitly specified."
(let ((result (car (idris-eval `(:case-split ,(cdr what) ,(car what))))))
(if (<= (length result) 2)
(message "Can't case split %s" (car what))
(setq final-point (point))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is lexically scoped, so final-point isn't around right now. Why not let-bind it here, rather than using setq?

(delete-region (line-beginning-position) (line-end-position))
(insert (substring result 0 (1- (length result)))))))))
(insert (substring result 0 (1- (length result))))
(goto-char final-point))))))

(defun idris-make-cases-from-hole ()
"Make a case expression from the metavariable at point."
Expand All @@ -588,8 +590,10 @@ KILLFLAG is set if N was explicitly specified."
(let ((result (car (idris-eval `(:make-case ,(cdr what) ,(car what))))))
(if (<= (length result) 2)
(message "Can't make cases from %s" (car what))
(setq final-point (point))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is lexically scoped, so final-point isn't around right now. Why not let-bind it here, rather than using setq?

Also, did you test save-excursion rather than using goto-char like this?

(delete-region (line-beginning-position) (line-end-position))
(insert (substring result 0 (1- (length result)))))))))
(insert (substring result 0 (1- (length result))))
(goto-char final-point))))))

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