From fd1279493040ba1c5e2db8728e74c159e16f728c Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 14 Jun 2022 20:25:39 +0200 Subject: [PATCH] refactor(lib): use cl-callf instead of plist-{put,delete}! I rediscovered cl-callf and decided to cut down on redundancies. --- core/autoload/plist.el | 7 +++--- core/core-packages.el | 33 ++++++++++++++-------------- modules/app/irc/autoload/settings.el | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core/autoload/plist.el b/core/autoload/plist.el index 7702d3d56..61ecf2022 100644 --- a/core/autoload/plist.el +++ b/core/autoload/plist.el @@ -21,6 +21,7 @@ list, the pair is destructured into (CAR . CDR)." ,@body)) ,retval))) +;;; DEPRECATED In favor of `cl-callf' ;;;###autoload (defmacro plist-put! (plist &rest rest) "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" (let ((plist (copy-sequence from-plist))) (while plist - (plist-put! to-plist (pop plist) (pop plist))) + (cl-callf plist-put to-plist (pop plist) (pop plist))) to-plist)) ;;;###autoload @@ -60,7 +61,7 @@ list, the pair is destructured into (CAR . CDR)." (let (p) (while 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))) p)) @@ -70,7 +71,7 @@ list, the pair is destructured into (CAR . CDR)." (let (p) (while plist (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))) p)) diff --git a/core/core-packages.el b/core/core-packages.el index a3a2dbd5a..232733bc9 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -500,30 +500,30 @@ Returns t if package is successfully registered, and nil if it was disabled elsewhere." (declare (indent defun)) (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) (when built-in (when (and (not ignore) (equal built-in '(quote prefer))) (setq built-in `(locate-library ,(symbol-name name) nil (get 'load-path 'initial-value)))) - (plist-delete! plist :built-in) - (plist-put! plist :ignore built-in)) + (cl-callf doom-plist-delete plist :built-in) + (cl-callf plist-put plist :ignore built-in)) `(let* ((name ',name) (plist (cdr (assq name doom-packages)))) ;; Record what module this declaration was found in (let ((module-list (plist-get plist :modules)) (module ',(doom-module-from-path))) (unless (member module module-list) - (plist-put! plist :modules - (append module-list - (list module) - (when (file-in-directory-p ,(dir!) doom-private-dir) - '((:private . modules))) - nil)))) + (cl-callf plist-put plist :modules + (append module-list + (list module) + (when (file-in-directory-p ,(dir!) doom-private-dir) + '((:private . modules))) + nil)))) ;; Merge given plist with pre-existing one (doplist! ((prop val) (list ,@plist) plist) (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 (condition-case e (when-let (recipe (plist-get plist :recipe)) @@ -535,13 +535,12 @@ elsewhere." recipe ;; Expand :local-repo from current directory (when local-repo - (plist-put! - plist :recipe - (plist-put recipe :local-repo - (let ((local-path (expand-file-name local-repo ,(dir!)))) - (if (file-directory-p local-path) - local-path - local-repo))))))) + (cl-callf plist-put plist :recipe + (plist-put recipe :local-repo + (let ((local-path (expand-file-name local-repo ,(dir!)))) + (if (file-directory-p local-path) + local-path + local-repo))))))) (error (signal 'doom-package-error (cons ,(symbol-name name) diff --git a/modules/app/irc/autoload/settings.el b/modules/app/irc/autoload/settings.el index 53e4bc0af..57afb815b 100644 --- a/modules/app/irc/autoload/settings.el +++ b/modules/app/irc/autoload/settings.el @@ -12,7 +12,7 @@ See `circe-network-options' for details." (declare (indent 1)) (after! circe (unless (plist-member plist :host) - (plist-put! plist :host server)) + (cl-callf plist-put plist :host server)) (setf (alist-get server circe-network-options nil nil #'equal) plist)))