refactor(lib): use cl-callf instead of plist-{put,delete}!

I rediscovered cl-callf and decided to cut down on redundancies.
This commit is contained in:
Henrik Lissner 2022-06-14 20:25:39 +02:00
parent d0cdf8f5c6
commit fd12794930
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
3 changed files with 21 additions and 21 deletions

View file

@ -21,6 +21,7 @@ list, the pair is destructured into (CAR . CDR)."
,@body)) ,@body))
,retval))) ,retval)))
;;; DEPRECATED In favor of `cl-callf'
;;;###autoload ;;;###autoload
(defmacro plist-put! (plist &rest rest) (defmacro plist-put! (plist &rest rest)
"Set each PROP VALUE pair in REST to PLIST in-place." "Set each PROP VALUE pair in REST to PLIST in-place."
@ -51,7 +52,7 @@ list, the pair is destructured into (CAR . CDR)."
"Non-destructively merge FROM-PLIST onto TO-PLIST" "Non-destructively merge FROM-PLIST onto TO-PLIST"
(let ((plist (copy-sequence from-plist))) (let ((plist (copy-sequence from-plist)))
(while plist (while plist
(plist-put! to-plist (pop plist) (pop plist))) (cl-callf plist-put to-plist (pop plist) (pop plist)))
to-plist)) to-plist))
;;;###autoload ;;;###autoload
@ -60,7 +61,7 @@ list, the pair is destructured into (CAR . CDR)."
(let (p) (let (p)
(while plist (while plist
(if (car plist) (if (car plist)
(plist-put! p (car plist) (nth 1 plist))) (cl-callf plist-put p (car plist) (nth 1 plist)))
(setq plist (cddr plist))) (setq plist (cddr plist)))
p)) p))
@ -70,7 +71,7 @@ list, the pair is destructured into (CAR . CDR)."
(let (p) (let (p)
(while plist (while plist
(if (not (memq (car plist) props)) (if (not (memq (car plist) props))
(plist-put! p (car plist) (nth 1 plist))) (cl-callf plist-put p (car plist) (nth 1 plist)))
(setq plist (cddr plist))) (setq plist (cddr plist)))
p)) p))

View file

@ -500,21 +500,21 @@ Returns t if package is successfully registered, and nil if it was disabled
elsewhere." elsewhere."
(declare (indent defun)) (declare (indent defun))
(when (and recipe (keywordp (car-safe recipe))) (when (and recipe (keywordp (car-safe recipe)))
(plist-put! plist :recipe `(quote ,recipe))) (cl-callf plist-put plist :recipe `(quote ,recipe)))
;; :built-in t is basically an alias for :ignore (locate-library NAME) ;; :built-in t is basically an alias for :ignore (locate-library NAME)
(when built-in (when built-in
(when (and (not ignore) (when (and (not ignore)
(equal built-in '(quote prefer))) (equal built-in '(quote prefer)))
(setq built-in `(locate-library ,(symbol-name name) nil (get 'load-path 'initial-value)))) (setq built-in `(locate-library ,(symbol-name name) nil (get 'load-path 'initial-value))))
(plist-delete! plist :built-in) (cl-callf doom-plist-delete plist :built-in)
(plist-put! plist :ignore built-in)) (cl-callf plist-put plist :ignore built-in))
`(let* ((name ',name) `(let* ((name ',name)
(plist (cdr (assq name doom-packages)))) (plist (cdr (assq name doom-packages))))
;; Record what module this declaration was found in ;; Record what module this declaration was found in
(let ((module-list (plist-get plist :modules)) (let ((module-list (plist-get plist :modules))
(module ',(doom-module-from-path))) (module ',(doom-module-from-path)))
(unless (member module module-list) (unless (member module module-list)
(plist-put! plist :modules (cl-callf plist-put plist :modules
(append module-list (append module-list
(list module) (list module)
(when (file-in-directory-p ,(dir!) doom-private-dir) (when (file-in-directory-p ,(dir!) doom-private-dir)
@ -523,7 +523,7 @@ elsewhere."
;; Merge given plist with pre-existing one ;; Merge given plist with pre-existing one
(doplist! ((prop val) (list ,@plist) plist) (doplist! ((prop val) (list ,@plist) plist)
(unless (null val) (unless (null val)
(plist-put! plist prop val))) (cl-callf plist-put plist prop val)))
;; Some basic key validation; throws an error on invalid properties ;; Some basic key validation; throws an error on invalid properties
(condition-case e (condition-case e
(when-let (recipe (plist-get plist :recipe)) (when-let (recipe (plist-get plist :recipe))
@ -535,8 +535,7 @@ elsewhere."
recipe recipe
;; Expand :local-repo from current directory ;; Expand :local-repo from current directory
(when local-repo (when local-repo
(plist-put! (cl-callf plist-put plist :recipe
plist :recipe
(plist-put recipe :local-repo (plist-put recipe :local-repo
(let ((local-path (expand-file-name local-repo ,(dir!)))) (let ((local-path (expand-file-name local-repo ,(dir!))))
(if (file-directory-p local-path) (if (file-directory-p local-path)

View file

@ -12,7 +12,7 @@ See `circe-network-options' for details."
(declare (indent 1)) (declare (indent 1))
(after! circe (after! circe
(unless (plist-member plist :host) (unless (plist-member plist :host)
(plist-put! plist :host server)) (cl-callf plist-put plist :host server))
(setf (alist-get server circe-network-options (setf (alist-get server circe-network-options
nil nil #'equal) nil nil #'equal)
plist))) plist)))