core/autoload/mplist: document
This commit is contained in:
parent
978e121ed0
commit
d4e25d3f0d
1 changed files with 29 additions and 26 deletions
|
@ -2,18 +2,18 @@
|
||||||
(provide 'doom-lib-mplist)
|
(provide 'doom-lib-mplist)
|
||||||
|
|
||||||
;; The built-in plist library won't work when the list is a malformed plist,
|
;; The built-in plist library won't work when the list is a malformed plist,
|
||||||
;; which is a plist who has multiple (or no) forms following its properties. For
|
;; which is a plist that has multiple (or no) forms following its properties.
|
||||||
;; example: (:x 5 :y 1 2 3 :z).
|
;; For example: (:x 5 :y 1 2 3 :z).
|
||||||
;;
|
;;
|
||||||
;; This library was made for mplists, so use the standard plist-* functions for
|
;; This library was written for mplists, but use the standard plist-* functions
|
||||||
;; regular plists.
|
;; for regular plists -- they're faster.
|
||||||
;;
|
;;
|
||||||
;; (let ((a '(abc :commands 1 :config 3 4 5)))
|
;; (let ((a '(abc :commands 1 :config 3 4 5)))
|
||||||
;; (mplist! a &delete :commands :config))
|
;; (mplist! a &delete :commands :config))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defmacro mplist! (var action &rest args)
|
(defmacro mplist! (var action &rest args)
|
||||||
"A helper macro that makes dealing with doom-mplist-* functions a little more concise.
|
"A convenience macro for dealing with doom-mplist-* functions.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
(mplist! plist &delete :x :y)
|
(mplist! plist &delete :x :y)
|
||||||
|
@ -26,40 +26,43 @@ Examples:
|
||||||
`(,fn-sym ,var ,@args)))))
|
`(,fn-sym ,var ,@args)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-mplist-delete (plist &rest keys)
|
(defun doom-mplist-delete (mplist &rest keys)
|
||||||
"TODO"
|
"Thoroughly removes a property and its values from an mplist."
|
||||||
(if (apply 'doom-mplist-member plist keys)
|
(if (apply 'doom-mplist-member mplist keys)
|
||||||
(let (forms)
|
(let (forms)
|
||||||
(while plist
|
(while mplist
|
||||||
(if (not (and (keywordp (car plist)) (memq (car plist) keys)))
|
(if (not (and (keywordp (car mplist)) (memq (car mplist) keys)))
|
||||||
(setq forms (append forms (list (pop plist))))
|
(setq forms (append forms (list (pop mplist))))
|
||||||
(pop plist)
|
(pop mplist)
|
||||||
(while (and plist (not (keywordp (car plist))))
|
(while (and mplist (not (keywordp (car mplist))))
|
||||||
(pop plist))))
|
(pop mplist))))
|
||||||
forms)
|
forms)
|
||||||
plist))
|
mplist))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-mplist-put (plist key value)
|
(defun doom-mplist-put (mplist key value)
|
||||||
"TODO"
|
"Like `plist-put', but for mplists."
|
||||||
(when (doom-mplist-member plist key)
|
(when (doom-mplist-member mplist key)
|
||||||
(doom-mplist-delete plist key))
|
(doom-mplist-delete mplist key))
|
||||||
(setq plist (append plist (list key value))))
|
(setq mplist (append mplist (list key value))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-mplist-get (plist &rest keys)
|
(defun doom-mplist-get (mplist &rest keys)
|
||||||
"TODO"
|
"Like `plist-get', but for mplists. If KEYS is only one keyword, return the
|
||||||
|
mplist associated with it. If KEYS is multiple, return a list of associated
|
||||||
|
mplists."
|
||||||
(if (cdr keys)
|
(if (cdr keys)
|
||||||
(let ((keys (mapcar (lambda (key) (memq key plist)) keys))
|
(let ((keys (mapcar (lambda (key) (memq key mplist)) keys))
|
||||||
values)
|
values)
|
||||||
(dolist (forms keys)
|
(dolist (forms keys)
|
||||||
(when forms
|
(when forms
|
||||||
(push (cdr forms) values)))
|
(push (cdr forms) values)))
|
||||||
values)
|
values)
|
||||||
(cdr (memq (car keys) plist))))
|
(cdr (memq (car keys) mplist))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-mplist-member (plist &rest keys)
|
(defun doom-mplist-member (mplist &rest keys)
|
||||||
(cl-some (lambda (key) (memq key plist)) keys))
|
"Return t if any of KEYS (keywords) are in MPLIST."
|
||||||
|
(cl-some (lambda (key) (memq key mplist)) keys))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue