Skip to content

Commit

Permalink
Always display short options before long ones in help screens, even i…
Browse files Browse the repository at this point in the history
…f specified otherwise when defining.
  • Loading branch information
doublep committed Oct 7, 2023
1 parent eec00be commit 16acc2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion eldev.el
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,9 @@ If COMMAND is nil, list global options instead."
(eldev-output (or title "\nOptions:"))
(dolist (group by-handler)
(let* ((value-mode (eldev-get (car group) :option-value))
(options (cdr group))
;; Sort short options before long ones (but usually they are already sorted).
(options (sort (copy-sequence (cdr group))
(lambda (a b) (and (not (string-prefix-p "--" (symbol-name a))) (string-prefix-p "--" (symbol-name b))))))
(all-strings (mapconcat #'symbol-name options ", ")))
(when (eldev-all-p (string-prefix-p "--" (symbol-name it)) options)
(setf all-strings (concat " " all-strings)))
Expand Down
12 changes: 12 additions & 0 deletions test/help.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@
(should (= exit-code 0))))


(eldev-ert-defargtest eldev-help-sorts-option (short-first)
(nil t)
(eldev--test-run "empty-project" ("--setup" `(eldev-defoption eldev--test-custom-option ()
"Only for testing"
:options ,(if short-first '(-X --custom-option) '(--custom-option -X))
:for-command help)
"help" "help")
;; Should sort short options first, even if (accidentally) specified otherwise when defining.
(should (string-match-p "-X, --custom-option" stdout))
(should (= exit-code 0))))


(provide 'test/help)

0 comments on commit 16acc2f

Please sign in to comment.