Commit c51075b5 authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit--format-popup-variable:choices: new function

This function used to be part of Magit-Popup
under the name `magit-popup-format-variable'.
parent e95550cd
......@@ -747,7 +747,8 @@ is used instead. It defaults to `false'."
(defun magit-format-branch*rebase ()
(let ((branch (magit-branch-config-branch)))
(magit-popup-format-variable (format "branch.%s.rebase" branch)
(magit--format-popup-variable:choices
(format "branch.%s.rebase" branch)
'("true" "false")
"false" "pull.rebase"
(+ (length branch) 20))))
......@@ -772,7 +773,8 @@ which by default it is not."
(defun magit-format-branch*pushRemote ()
(let ((branch (magit-branch-config-branch)))
(magit-popup-format-variable (format "branch.%s.pushRemote" branch)
(magit--format-popup-variable:choices
(format "branch.%s.pushRemote" branch)
(magit-list-remotes)
nil "remote.pushDefault"
(+ (length branch) 20))))
......@@ -791,7 +793,8 @@ When `false' (the default) then pulling is done by merging."
(magit--set-popup-variable "pull.rebase" '("true" "false") "false"))
(defun magit-format-pull.rebase ()
(magit-popup-format-variable "pull.rebase" '("true" "false") "false" nil 19))
(magit--format-popup-variable:choices
"pull.rebase" '("true" "false") "false" nil 19))
;;;###autoload
(defun magit-cycle-remote.pushDefault ()
......@@ -804,8 +807,8 @@ using the Git variable `branch.<name>.pushRemote'."
(magit--set-popup-variable "remote.pushDefault" (magit-list-remotes)))
(defun magit-format-remote.pushDefault ()
(magit-popup-format-variable "remote.pushDefault"
(magit-list-remotes) nil nil 19))
(magit--format-popup-variable:choices
"remote.pushDefault" (magit-list-remotes) nil nil 19))
;;;###autoload
(defun magit-cycle-branch*autoSetupMerge ()
......@@ -831,8 +834,8 @@ When `false' then the variables are never set."
'("always" "true" "false") "true"))
(defun magit-format-branch*autoSetupMerge ()
(magit-popup-format-variable "branch.autoSetupMerge"
'("always" "true" "false") "true" nil 23))
(magit--format-popup-variable:choices
"branch.autoSetupMerge" '("always" "true" "false") "true" nil 23))
;;;###autoload
(defun magit-cycle-branch*autoSetupRebase ()
......@@ -857,7 +860,8 @@ When `never' (the default) then the variable is never set."
'("always" "local" "remote" "never") "never"))
(defun magit-format-branch*autoSetupRebase ()
(magit-popup-format-variable "branch.autoSetupRebase"
(magit--format-popup-variable:choices
"branch.autoSetupRebase"
'("always" "local" "remote" "never")
"never" nil 23))
......
......@@ -1837,7 +1837,54 @@ the reference is used. The first regexp submatch becomes the
(magit-with-pre-popup-buffer
(magit-refresh))
(message "%s %s" variable
(magit-popup-format-variable variable choices default other)))
(magit--format-popup-variable:choices*
variable choices default other)))
(defun magit--format-popup-variable:choices
(variable choices &optional default other width)
(concat variable
(if width (make-string (- width (length variable)) ?\s) " ")
(magit--format-popup-variable:choices*
variable choices default other)))
(defun magit--format-popup-variable:choices*
(variable choices &optional default other)
(let ((local (magit-git-string "config" "--local" variable))
(global (magit-git-string "config" "--global" variable)))
(when other
(setq other (--when-let (magit-get other)
(concat other ":" it))))
(concat
(propertize "[" 'face 'magit-popup-disabled-argument)
(mapconcat
(lambda (choice)
(propertize choice 'face (if (equal choice local)
'magit-popup-option-value
'magit-popup-disabled-argument)))
choices
(propertize "|" 'face 'magit-popup-disabled-argument))
(when (or global other default)
(concat
(propertize "|" 'face 'magit-popup-disabled-argument)
(cond (global
(propertize (concat "global:" global)
'face (cond (local
'magit-popup-disabled-argument)
((member global choices)
'magit-popup-option-value)
(t
'font-lock-warning-face))))
(other
(propertize other
'face (if local
'magit-popup-disabled-argument
'magit-popup-option-value)))
(default
(propertize (concat "default:" default)
'face (if local
'magit-popup-disabled-argument
'magit-popup-option-value))))))
(propertize "]" 'face 'magit-popup-disabled-argument))))
(provide 'magit-git)
;;; magit-git.el ends here
......@@ -296,7 +296,8 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"."
(defun magit-format-remote*tagOpt ()
(let ((remote (magit-remote-config--remote)))
(magit-popup-format-variable (format "remote.%s.tagOpts" remote)
(magit--format-popup-variable:choices
(format "remote.%s.tagOpts" remote)
'("--no-tags" "--tags") nil nil
(+ (length remote) 16))))
......@@ -508,8 +509,8 @@ missing. To add them use something like:
:max-action-columns 1)
(defun magit-pull-format-branch*rebase ()
(magit-popup-format-variable (format "branch.%s.rebase"
(or (magit-get-current-branch) "<name>"))
(magit--format-popup-variable:choices
(format "branch.%s.rebase" (or (magit-get-current-branch) "<name>"))
'("true" "false")
"false" "pull.rebase"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment