Skip to content

Commit

Permalink
Restructure code
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbarclay committed Aug 2, 2020
1 parent 6c1e728 commit 9e2e91c
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions parinfer-rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ command should be run in.")
(defvar-local parinfer-rust--ignore-post-command-hook nil
"A hack to not run parinfer-execute after an undo has finished processing")

(defvar parinfer-rust--last-mode nil
"Last active Parinfer mode.
Used for toggling between paren mode and last active mode.")
;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helper functions
;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -360,6 +363,21 @@ If a change is detected in the buffer, prompt the user to see if they still want
(parinfer-rust-mode -1)))
(remove-hook 'before-change-functions #'parinfer-rust--check-for-indentation t))

(defun parinfer-rust--switch-mode (&optional mode)
"Switch to a different Parinfer MODE.
Checks if MODE is a valid Parinfer mode, and uses
`parinfer-rust-preferred-mode' otherwise. Sets
`parinfer-rust--last-mode' variable to current MODE."
(setq-local parinfer-rust--mode
(if (member mode parinfer-rust--mode-types)
mode
parinfer-rust-preferred-mode))
(unless (string= parinfer-rust--mode "paren")
(setq-local parinfer-rust--last-mode parinfer-rust--mode))
(parinfer-rust--set-default-state)
(parinfer-rust--dim-parens))

(defun parinfer-rust-mode-enable ()
"Enable Parinfer."
(setq-local parinfer-rust-enabled t)
Expand Down Expand Up @@ -405,25 +423,6 @@ Either: indent, smart, or paren."
nil
t)))

(defvar parinfer-rust--last-mode nil
"Last active Parinfer mode.
Used for toggling between paren mode and last active mode.")

(defun parinfer-rust--switch-mode (&optional mode)
"Switch to a different Parinfer MODE.
Checks if MODE is a valid Parinfer mode, and uses
`parinfer-rust-preferred-mode' otherwise. Sets
`parinfer-rust--last-mode' variable to current MODE."
(setq-local parinfer-rust--mode
(if (member mode parinfer-rust--mode-types)
mode
parinfer-rust-preferred-mode))
(unless (string= parinfer-rust--mode "paren")
(setq-local parinfer-rust--last-mode parinfer-rust--mode))
(parinfer-rust--set-default-state)
(parinfer-rust--dim-parens))

;;;###autoload
(defun parinfer-rust-toggle-paren-mode ()
"Switch to paren mode if current mode is either smart or indent.
Expand Down

0 comments on commit 9e2e91c

Please sign in to comment.