Skip to content

Commit

Permalink
x-magit: don't override backup variable on double activation
Browse files Browse the repository at this point in the history
  • Loading branch information
bmag committed Mar 4, 2021
1 parent c85dd3c commit 0fd17cd
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions window-purpose-x.el
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,37 @@ invoked.")
"Turn on magit-single purpose configuration."
(interactive)
(with-eval-after-load 'magit
(setq purpose-x-old-magit-display-buffer-function magit-display-buffer-function
magit-display-buffer-function 'purpose-x-magit-display-buffer-function))
;; if `purpose-x-old-magit-display-buffer-function' is non-nil, then it
;; means magit-single-on was activated while magit-single-on or
;; magit-multi-on is already active. Magit's variable is already backed up,
;; so "backing it up" again will actually override it with a wrong value.
(unless purpose-x-old-magit-display-buffer-function
(setq purpose-x-old-magit-display-buffer-function magit-display-buffer-function))
(setq magit-display-buffer-function 'purpose-x-magit-display-buffer-function))
(purpose-set-extension-configuration :magit purpose-x-magit-single-conf))

;;;###autoload
(defun purpose-x-magit-multi-on ()
"Turn on magit-multi purpose configuration."
(interactive)
(with-eval-after-load 'magit
(setq purpose-x-old-magit-display-buffer-function magit-display-buffer-function
magit-display-buffer-function 'purpose-x-magit-display-buffer-function))
;; if `purpose-x-old-magit-display-buffer-function' is non-nil, then it
;; means magit-multi-on was activated while magit-single-on or
;; magit-multi-on is already active. Magit's variable is already backed up,
;; so "backing it up" again will actually override it with a wrong value.
(unless purpose-x-old-magit-display-buffer-function
(setq purpose-x-old-magit-display-buffer-function magit-display-buffer-function))
(setq magit-display-buffer-function 'purpose-x-magit-display-buffer-function))
(purpose-set-extension-configuration :magit purpose-x-magit-multi-conf))

(defun purpose-x-magit-off ()
"Turn off magit purpose configuration (single or multi)."
(interactive)
(purpose-del-extension-configuration :magit)
(with-eval-after-load 'magit
(setq magit-display-buffer-function purpose-x-old-magit-display-buffer-function
purpose-x-old-magit-display-buffer-function nil)))
(when purpose-x-old-magit-display-buffer-function
(setq magit-display-buffer-function purpose-x-old-magit-display-buffer-function))
(setq purpose-x-old-magit-display-buffer-function nil)))

;;; --- purpose-x-magit ends here ---

Expand Down

0 comments on commit 0fd17cd

Please sign in to comment.