Skip to content

Commit

Permalink
Fix bugs in change tracking implementation
Browse files Browse the repository at this point in the history
Remove call at beginning of execute

There should only be one entry point to change tracking and that entry
point triggers execute

Unregister change tracker

Make things local
  • Loading branch information
justinbarclay committed May 1, 2024
1 parent 4d82af7 commit 572ee9d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions parinfer-rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,6 @@ CHANGES."

(defun parinfer-rust--execute (&rest _args)
"Run parinfer in the current buffer."
(when parinfer-rust--change-tracker
(parinfer-rust--fetch-changes parinfer-rust--change-tracker))
(if (or parinfer-rust--disable
undo-in-progress
parinfer-rust--ignore-post-command-hook)
Expand Down Expand Up @@ -485,9 +483,16 @@ Disable `parinfer-rust-mode' if the user does not want to have
parinfer autofix them, or if there is no reasonable way for
`parinfer-rust-mode' to automatically fix them."
(setq-local parinfer-rust--disable nil)
;; Disable change tracker for now or we have to deal with sync issues
(track-changes-unregister parinfer-rust--change-tracker)
(setq-local parinfer-rust--change-tracker nil)
(if-let (issue (or (parinfer-rust--check-for-tabs)
(parinfer-rust--check-for-indentation)))
(parinfer-rust-mode -1))
(parinfer-rust-mode -1)
;; Re-enable change trackers now that we've succeeded in our tasks
(setq-local parinfer-rust--change-tracker
(track-changes-register #'parinfer-rust--changes-signal
:disjoint t)))
(remove-hook 'before-change-functions #'parinfer-rust--check-for-issues t))

(defun parinfer-rust--switch-mode (&optional mode)
Expand Down Expand Up @@ -517,8 +522,8 @@ Checks if MODE is a valid Parinfer mode, and uses
(progn
(when parinfer-rust--change-tracker
(track-changes-unregister parinfer-rust--change-tracker)
(setq parinfer-rust--change-tracker nil))
(setq parinfer-rust--change-tracker
(setq-local parinfer-rust--change-tracker nil))
(setq-local parinfer-rust--change-tracker
(track-changes-register #'parinfer-rust--changes-signal
:disjoint t))))
(parinfer-rust--dim-parens))
Expand All @@ -528,7 +533,11 @@ Checks if MODE is a valid Parinfer mode, and uses
(advice-remove 'undo #'parinfer-rust--track-undo)
(when (fboundp 'undo-tree-undo)
(advice-remove 'undo-tree-undo #'parinfer-rust--track-undo))
(when parinfer-rust--change-tracker
(track-changes-unregister parinfer-rust--change-tracker)
(setq-local parinfer-rust--change-tracker nil))
(setq-local parinfer-rust-enabled nil)
(remove-hook 'before-change-functions #'parinfer-rust--check-for-issues t)
(parinfer-rust--dim-parens))

(defun parinfer-rust-toggle-disable ()
Expand Down Expand Up @@ -566,7 +575,6 @@ This includes stopping tracking of all changes."
((eq 'immediate parinfer-rust-check-before-enable)
(setq-local parinfer-rust--disable t)
(parinfer-rust--check-for-issues))

(t (let ((parinfer-rust--mode "paren"))
(parinfer-rust--execute)))))
(progn
Expand Down

0 comments on commit 572ee9d

Please sign in to comment.