mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-04 19:29:37 +00:00
Allow multiple :delight arguments, or omitting the mode. ()
This allows using forms such as (use-package foo :delight) ;; => (delight 'foo-mode) (use-package foo :delight " f") ;; => (delight 'foo-mode " f") (use-package foo :delight (a-mode) (b-mode " b") ;; => (delight 'a-mode) (delight 'b-mode " b") This brings support for `:delight` in line with `:diminish`. GitHub-reference: https://github.com/jwiegley/use-package/issues/477
This commit is contained in:
parent
99e4045122
commit
4b8b850cf0
2 changed files with 57 additions and 13 deletions
|
@ -330,6 +330,14 @@ convert it to a string and return that."
|
|||
(if (stringp string-or-symbol) string-or-symbol
|
||||
(symbol-name string-or-symbol)))
|
||||
|
||||
(defun use-package-as-mode (string-or-symbol)
|
||||
"If STRING-OR-SYMBOL ends in `-mode' (or its name does), return
|
||||
it as a symbol. Otherwise, return it as a symbol with `-mode'
|
||||
appended."
|
||||
(let ((string (use-package-as-string string-or-symbol)))
|
||||
(intern (if (string-match "-mode\\'" string) string
|
||||
(concat string "-mode")))))
|
||||
|
||||
(defun use-package-load-name (name &optional noerror)
|
||||
"Return a form which will load or require NAME depending on
|
||||
whether it's a string or symbol."
|
||||
|
@ -1435,26 +1443,43 @@ deferred until the prefix key sequence is pressed."
|
|||
;;; :delight
|
||||
;;
|
||||
|
||||
(defun use-package--normalize-delight-1 (name args)
|
||||
"Normalize ARGS for a single call to `delight'."
|
||||
(when (eq :eval (car args))
|
||||
;; Handle likely common mistake.
|
||||
(use-package-error ":delight mode line constructs must be quoted"))
|
||||
(cond ((and (= (length args) 1) (symbolp (car args)))
|
||||
`(,(nth 0 args) nil ,name))
|
||||
((= (length args) 2)
|
||||
`(,(nth 0 args) ,(nth 1 args) ,name))
|
||||
((= (length args) 3)
|
||||
args)
|
||||
(t
|
||||
(use-package-error
|
||||
":delight expects `delight' arguments or a list of them"))))
|
||||
|
||||
(defun use-package-normalize/:delight (name keyword args)
|
||||
"Normalize arguments to delight."
|
||||
(cond
|
||||
((and (= (length args) 1)
|
||||
(symbolp (car args)))
|
||||
(list (car args) nil name))
|
||||
((and (= (length args) 2)
|
||||
(symbolp (car args)))
|
||||
(list (car args) (cadr args) (use-package-as-symbol name)))
|
||||
((and (= (length args) 3)
|
||||
(symbolp (car args)))
|
||||
args)
|
||||
(t
|
||||
(use-package-error ":delight expects same args as delight function"))))
|
||||
(cond ((null args)
|
||||
`((,(use-package-as-mode name) nil ,name)))
|
||||
((and (= (length args) 1)
|
||||
(symbolp (car args)))
|
||||
`((,(car args) nil ,name)))
|
||||
((and (= (length args) 1)
|
||||
(or (not (listp (car args)))
|
||||
(eq 'quote (caar args))))
|
||||
`((,(use-package-as-mode name) ,(car args) ,name)))
|
||||
(t (mapcar
|
||||
(apply-partially #'use-package--normalize-delight-1 name)
|
||||
(if (symbolp (car args)) (list args) args)))))
|
||||
|
||||
(defun use-package-handler/:delight (name keyword args rest state)
|
||||
(let ((body (use-package-process-keywords name rest state)))
|
||||
(use-package-concat
|
||||
body
|
||||
`((delight (quote ,(nth 0 args)) ,(nth 1 args) (quote ,(nth 2 args))) t))))
|
||||
(mapcar (lambda (arg)
|
||||
`(delight ',(nth 0 arg) ,(nth 1 arg) ',(nth 2 arg)))
|
||||
args))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
|
|
|
@ -51,6 +51,25 @@
|
|||
(should (equal (use-package-normalize-mode 'foopkg :mode '((".foo" . foo) (".bar" . bar)))
|
||||
'((".foo" . foo) (".bar" . bar)))))
|
||||
|
||||
(ert-deftest use-package-normalize-delight ()
|
||||
(should (equal `((foo-mode nil foo))
|
||||
(use-package-normalize/:delight 'foo :delight nil)))
|
||||
(should (equal `((foo-mode nil foo-mode))
|
||||
(use-package-normalize/:delight 'foo-mode :delight nil)))
|
||||
(should (equal `((bar-mode nil foo))
|
||||
(use-package-normalize/:delight 'foo :delight '(bar-mode))))
|
||||
(should (equal `((foo-mode "abc" foo))
|
||||
(use-package-normalize/:delight 'foo :delight '("abc"))))
|
||||
(should (equal `((foo-mode '(:eval 1) foo))
|
||||
(use-package-normalize/:delight 'foo :delight '('(:eval 1)))))
|
||||
(should (equal `((a-mode nil foo)
|
||||
(b-mode " b" foo))
|
||||
(use-package-normalize/:delight 'foo :delight '((a-mode)
|
||||
(b-mode " b")))))
|
||||
(should-error (use-package-normalize/:delight 'foo :delight '((:eval 1))))
|
||||
|
||||
)
|
||||
|
||||
;; Local Variables:
|
||||
;; indent-tabs-mode: nil
|
||||
;; no-byte-compile: t
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue