From 594fdc8f05debb8920fbfcf8bd8a64735cf4680c Mon Sep 17 00:00:00 2001 From: Benjamin Reynolds Date: Thu, 7 Jun 2018 05:13:06 -0500 Subject: [PATCH] Rename spacemacs/mplist-get functions to be more descriptive * spacemacs/mplist-get -> spacemacs/mplist-get-values * spacemacs/plist-get -> spacemacs/mplist-get-value * refactor spacemacs/mplist-get-value to be defined in terms of mplist-get-values Ref #10803 See [comment] [comment]: https://github.com/syl20bnr/spacemacs/pull/10803#issuecomment-395292606 --- core/core-configuration-layer.el | 12 ++-- core/core-dotspacemacs.el | 4 +- core/core-funcs.el | 24 +++----- core/core-micro-state.el | 14 ++--- core/core-toggle.el | 6 +- core/core-transient-state.el | 4 +- core/core-use-package-ext.el | 2 +- layers/+completion/auto-completion/funcs.el | 12 ++-- layers/+spacemacs/spacemacs-defaults/funcs.el | 10 ++-- layers/+spacemacs/spacemacs-layouts/funcs.el | 4 +- tests/core/core-funcs-utest.el | 60 +++++++++---------- 11 files changed, 72 insertions(+), 80 deletions(-) diff --git a/core/core-configuration-layer.el b/core/core-configuration-layer.el index 70229b65f..3416e0bfa 100644 --- a/core/core-configuration-layer.el +++ b/core/core-configuration-layer.el @@ -728,7 +728,7 @@ layer directory." (defun configuration-layer//select-packages (layer-specs packages) "Return the selected packages of LAYER-SPECS from given PACKAGES list." (let* ((value (when (listp layer-specs) - (spacemacs/mplist-get layer-specs :packages))) + (spacemacs/mplist-get-values layer-specs :packages))) (selected-packages (if (and (not (null (car value))) (listp (car value))) (car value) @@ -769,17 +769,17 @@ If USEDP or `configuration-layer--load-packages-files' is non-nil then the layer-name) (let* ((dir (file-name-as-directory dir)) (disabled (when (listp layer-specs) - (spacemacs/mplist-get layer-specs :disabled-for))) + (spacemacs/mplist-get-values layer-specs :disabled-for))) (enabled (if (and (listp layer-specs) (memq :enabled-for layer-specs)) - (spacemacs/mplist-get layer-specs :enabled-for) + (spacemacs/mplist-get-values layer-specs :enabled-for) 'unspecified)) (variables (when (listp layer-specs) - (spacemacs/mplist-get layer-specs :variables))) + (spacemacs/mplist-get-values layer-specs :variables))) (shadow (if (and (listp layer-specs) (memq :can-shadow layer-specs)) - (spacemacs/mplist-get layer-specs :can-shadow) + (spacemacs/mplist-get-values layer-specs :can-shadow) 'unspecified)) (packages-file (concat dir "packages.el")) (packages (when (and (null packages) @@ -1239,7 +1239,7 @@ USEDP if non-nil indicates that made packages are used packages." "Configure auto-installation of layer with name LAYER-NAME." (declare (indent 1)) (when (configuration-layer//lazy-install-p layer-name) - (let ((extensions (spacemacs/mplist-get props :extensions)) + (let ((extensions (spacemacs/mplist-get-values props :extensions)) (interpreter (plist-get props :interpreter))) (when (configuration-layer/layer-used-p layer-name) (let* ((layer (configuration-layer/get-layer layer-name)) diff --git a/core/core-dotspacemacs.el b/core/core-dotspacemacs.el index 0434edd84..9f020f6bc 100644 --- a/core/core-dotspacemacs.el +++ b/core/core-dotspacemacs.el @@ -445,7 +445,7 @@ the symbol of an editing style and the cdr is a list of keyword arguments like (cond ((symbolp config) config) ((listp config) - (let ((variables (spacemacs/mplist-get config :variables))) + (let ((variables (spacemacs/mplist-get-values config :variables))) (while variables (let ((var (pop variables))) (if (consp variables) @@ -764,7 +764,7 @@ error recovery." hybrid)) (and (listp x) (member (car x) '(vim emacs hybrid)) - (spacemacs/mplist-get x :variables)))) + (spacemacs/mplist-get-values x :variables)))) 'dotspacemacs-editing-style "is \'vim, \'emacs or \'hybrid or and list with `:variables' keyword") (spacemacs//test-var diff --git a/core/core-funcs.el b/core/core-funcs.el index 91ed3aae0..fa3ae9bff 100644 --- a/core/core-funcs.el +++ b/core/core-funcs.el @@ -30,7 +30,7 @@ values." ;; ns is returned instead of mac on Emacs 25+ (memq (window-system) '(mac ns))) -(defun spacemacs/mplist-get (plist prop) +(defun spacemacs/mplist-get-values (plist prop) "Get the values associated to PROP in PLIST, a modified plist. A modified plist is one where keys are keywords and values are @@ -50,8 +50,8 @@ Currently this function infloops when the list is circular." (push (pop tail) result)) (nreverse result))) -(defun spacemacs/plist-get (plist prop) - "Get the value associated to PROP in PLIST, a modified plist. +(defun spacemacs/mplist-get-value (plist prop) + "Get a single value associated to PROP in PLIST, a modified plist. You should always use this function instead of builtin `plist-get' in Spacemacs. @@ -63,15 +63,7 @@ If there are multiple properties with the same keyword, only the first property and its values is returned. Currently this function infloops when the list is circular." - (let ((tail plist) - result) - (while (and (consp tail) (not (eq prop (car tail)))) - (pop tail)) - ;; pop the found keyword - (pop tail) - (when (and (consp tail) (not (keywordp (car tail)))) - (setq result (pop tail))) - result)) + (car (spacemacs/mplist-get-values plist prop))) (defun spacemacs/mplist-remove (plist prop) "Return a copy of a modified PLIST without PROP and its values. @@ -130,10 +122,10 @@ Supported properties: `:define-key CONS CELL' One or several cons cells (MAP . KEY) where MAP is a mode map and KEY is a key sequence string to be set with `define-key'. " - (let ((evil-leader (spacemacs/mplist-get props :evil-leader)) - (evil-leader-for-mode (spacemacs/mplist-get props :evil-leader-for-mode)) - (global-key (spacemacs/mplist-get props :global-key)) - (def-key (spacemacs/mplist-get props :define-key))) + (let ((evil-leader (spacemacs/mplist-get-values props :evil-leader)) + (evil-leader-for-mode (spacemacs/mplist-get-values props :evil-leader-for-mode)) + (global-key (spacemacs/mplist-get-values props :global-key)) + (def-key (spacemacs/mplist-get-values props :define-key))) (append (when evil-leader `((dolist (key ',evil-leader) diff --git a/core/core-micro-state.el b/core/core-micro-state.el index 13fb6472f..200302ad9 100644 --- a/core/core-micro-state.el +++ b/core/core-micro-state.el @@ -98,16 +98,16 @@ All properties supported by `spacemacs//create-key-binding-form' can be used." (declare (indent 1)) (let* ((func (spacemacs//micro-state-func-name name)) - (doc (spacemacs/mplist-get props :doc)) + (doc (spacemacs/mplist-get-values props :doc)) (persistent (plist-get props :persistent)) (disable-leader (plist-get props :disable-evil-leader)) (msg-func (if (plist-get props :use-minibuffer) 'message 'lv-message)) (exec-binding (plist-get props :execute-binding-on-enter)) - (on-enter (spacemacs/mplist-get props :on-enter)) - (on-exit (spacemacs/mplist-get props :on-exit)) - (bindings (spacemacs/mplist-get props :bindings)) + (on-enter (spacemacs/mplist-get-values props :on-enter)) + (on-exit (spacemacs/mplist-get-values props :on-exit)) + (bindings (spacemacs/mplist-get-values props :bindings)) (wrappers (spacemacs//micro-state-create-wrappers name doc msg-func disable-leader bindings)) (keymap-body (spacemacs//micro-state-fill-map-sexps wrappers)) @@ -159,9 +159,9 @@ used." "Create a wrapper of FUNC and return a tuple (key wrapper BINDING)." (let* ((key (car binding)) (wrapped (cadr binding)) - (binding-doc (spacemacs/mplist-get binding :doc)) - (binding-pre (spacemacs/mplist-get binding :pre)) - (binding-post (spacemacs/mplist-get binding :post)) + (binding-doc (spacemacs/mplist-get-values binding :doc)) + (binding-pre (spacemacs/mplist-get-values binding :pre)) + (binding-post (spacemacs/mplist-get-values binding :post)) (wrapper-name (intern (format "spacemacs//%S-%S-%s" name wrapped key))) (doc-body `((let ((bdoc ,@binding-doc) diff --git a/core/core-toggle.el b/core/core-toggle.el index 8a970dca5..370cb8dd3 100644 --- a/core/core-toggle.el +++ b/core/core-toggle.el @@ -74,12 +74,12 @@ used." (status (or mode (plist-get props :status))) (condition (plist-get props :if)) (doc (plist-get props :documentation)) - (on-body (if mode `((,mode)) (spacemacs/mplist-get props :on))) - (off-body (if mode `((,mode -1)) (spacemacs/mplist-get props :off))) + (on-body (if mode `((,mode)) (spacemacs/mplist-get-values props :on))) + (off-body (if mode `((,mode -1)) (spacemacs/mplist-get-values props :off))) (prefix-arg-var (plist-get props :prefix)) (on-message (plist-get props :on-message)) (off-message (plist-get props :off-message)) - (evil-leader-for-mode (spacemacs/mplist-get props :evil-leader-for-mode)) + (evil-leader-for-mode (spacemacs/mplist-get-values props :evil-leader-for-mode)) (supported-modes-string (mapconcat (lambda (x) (symbol-name (car x))) evil-leader-for-mode ", ")) (bindkeys (spacemacs//create-key-binding-form props wrapper-func)) diff --git a/core/core-transient-state.el b/core/core-transient-state.el index ebe560d0b..fecbed8c5 100644 --- a/core/core-transient-state.el +++ b/core/core-transient-state.el @@ -166,7 +166,7 @@ used." (body-func (spacemacs//transient-state-body-func-name name)) (add-bindings (spacemacs//transient-state-add-bindings-name name)) (remove-bindings (spacemacs//transient-state-remove-bindings-name name)) - (bindings (spacemacs/mplist-get props :bindings)) + (bindings (spacemacs/mplist-get-values props :bindings)) (doc (or (plist-get props :doc) "\n")) (title (plist-get props :title)) (hint-var (intern (format "%s/hint" func))) @@ -176,7 +176,7 @@ used." (hint (plist-get props :hint)) (hint-doc-p (plist-get props :hint-is-doc)) (dyn-hint (plist-get props :dynamic-hint)) - (additional-docs (spacemacs/mplist-get props :additional-docs)) + (additional-docs (spacemacs/mplist-get-values props :additional-docs)) (foreign-keys (plist-get props :foreign-keys)) (bindkeys (spacemacs//create-key-binding-form props body-func))) `(progn diff --git a/core/core-use-package-ext.el b/core/core-use-package-ext.el index 978c08a6f..3701c6265 100644 --- a/core/core-use-package-ext.el +++ b/core/core-use-package-ext.el @@ -39,7 +39,7 @@ override lazy-loaded settings." (let ((name-symbol (if (stringp name) (intern name) name)) (expanded-forms '())) (dolist (keyword spacemacs--use-package-add-hook-keywords) - (let ((body (spacemacs/mplist-get plist keyword))) + (let ((body (spacemacs/mplist-get-values plist keyword))) (when body (let ((hook (intern (format "use-package--%S--%s-hook" name-symbol diff --git a/layers/+completion/auto-completion/funcs.el b/layers/+completion/auto-completion/funcs.el index ed4ad02e9..c85debcb9 100644 --- a/layers/+completion/auto-completion/funcs.el +++ b/layers/+completion/auto-completion/funcs.el @@ -66,15 +66,15 @@ Available PROPS: `:call-hooks BOOLEAN' if non-nil then hooked functions are called right away." (declare (indent 0)) - (let* ((backends (spacemacs/mplist-get props :backends)) - (modes (spacemacs/mplist-get props :modes)) - (variables (spacemacs/mplist-get props :variables)) - (from (spacemacs/plist-get props :from)) + (let* ((backends (spacemacs/mplist-get-values props :backends)) + (modes (spacemacs/mplist-get-values props :modes)) + (variables (spacemacs/mplist-get-values props :variables)) + (from (spacemacs/mplist-get-value props :from)) (hooks (if (memq :append-hooks props) - (spacemacs/plist-get props :append-hooks) + (spacemacs/mplist-get-value props :append-hooks) t)) (call-hooks (when (memq :call-hooks props) - (spacemacs/plist-get props :call-hooks))) + (spacemacs/mplist-get-value props :call-hooks))) (result '(progn))) (dolist (mode modes) (let ((backends-var-name (intern (format "company-backends-%S" mode))) diff --git a/layers/+spacemacs/spacemacs-defaults/funcs.el b/layers/+spacemacs/spacemacs-defaults/funcs.el index 469c8c3fc..1d9ea56cc 100644 --- a/layers/+spacemacs/spacemacs-defaults/funcs.el +++ b/layers/+spacemacs/spacemacs-defaults/funcs.el @@ -1301,7 +1301,7 @@ Decision is based on `dotspacemacs-line-numbers'." Decision is based on `dotspacemacs-line-numbers'." (or (eq dotspacemacs-line-numbers 'relative) (and (listp dotspacemacs-line-numbers) - (car (spacemacs/mplist-get dotspacemacs-line-numbers :relative))))) + (car (spacemacs/mplist-get-values dotspacemacs-line-numbers :relative))))) (defun spacemacs//linum-on (origfunc &rest args) "Advice function to improve `linum-on' function." @@ -1335,9 +1335,9 @@ Decision is based on `dotspacemacs-line-numbers'." (defun spacemacs//linum-curent-buffer-is-not-too-big () "Return non-nil if buffer size is not too big." (not (and (listp dotspacemacs-line-numbers) - (spacemacs/mplist-get dotspacemacs-line-numbers :size-limit-kb) + (spacemacs/mplist-get-values dotspacemacs-line-numbers :size-limit-kb) (> (buffer-size) - (* 1000 (car (spacemacs/mplist-get dotspacemacs-line-numbers + (* 1000 (car (spacemacs/mplist-get-values dotspacemacs-line-numbers :size-limit-kb))))))) ;; see tests in tests/layers/+distribution/spacemacs-base/line-numbers-utest.el @@ -1347,10 +1347,10 @@ Decision is based on `dotspacemacs-line-numbers'." ;; default `enabled-for-modes' to '(prog-mode text-mode), because it is a more ;; sensible default than enabling in all buffers - including Magit buffers, ;; terminal buffers, etc. - (let* ((user-enabled-for-modes (spacemacs/mplist-get dotspacemacs-line-numbers + (let* ((user-enabled-for-modes (spacemacs/mplist-get-values dotspacemacs-line-numbers :enabled-for-modes)) (enabled-for-modes (or user-enabled-for-modes '(prog-mode text-mode))) - (disabled-for-modes (spacemacs/mplist-get dotspacemacs-line-numbers + (disabled-for-modes (spacemacs/mplist-get-values dotspacemacs-line-numbers :disabled-for-modes)) (enabled-for-parent (or (and (equal enabled-for-modes '(all)) 'all) (apply #'derived-mode-p enabled-for-modes))) diff --git a/layers/+spacemacs/spacemacs-layouts/funcs.el b/layers/+spacemacs/spacemacs-layouts/funcs.el index 5cae8401b..f5e6b6974 100644 --- a/layers/+spacemacs/spacemacs-layouts/funcs.el +++ b/layers/+spacemacs/spacemacs-layouts/funcs.el @@ -259,11 +259,11 @@ Available PROPS: (symbol-value name) name)) (func (spacemacs//custom-layout-func-name name)) - (binding-prop (car (spacemacs/mplist-get props :binding))) + (binding-prop (car (spacemacs/mplist-get-values props :binding))) (binding (if (symbolp binding-prop) (symbol-value binding-prop) binding-prop)) - (body (spacemacs/mplist-get props :body)) + (body (spacemacs/mplist-get-values props :body)) (already-defined? (cdr (assoc binding spacemacs--custom-layout-alist)))) `(progn diff --git a/tests/core/core-funcs-utest.el b/tests/core/core-funcs-utest.el index dbd3676a3..aacdcb326 100644 --- a/tests/core/core-funcs-utest.el +++ b/tests/core/core-funcs-utest.el @@ -12,81 +12,81 @@ (require 'core-funcs) ;; --------------------------------------------------------------------------- -;; spacemacs/mplist-get +;; spacemacs/mplist-get-values ;; --------------------------------------------------------------------------- -(ert-deftest test-mplist-get--one-property () +(ert-deftest test-mplist-get-values--one-property () (let* ((input '(dummy :property sym1 sym2 sym3)) - (result (spacemacs/mplist-get input :property))) + (result (spacemacs/mplist-get-values input :property))) (should (equal '(sym1 sym2 sym3) result)))) -(ert-deftest test-mplist-get--multiple-properties-get-first () +(ert-deftest test-mplist-get-values--multiple-properties-get-first () (let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 :prop3 sym5 sym6)) - (result (spacemacs/mplist-get input :prop1))) + (result (spacemacs/mplist-get-values input :prop1))) (should (equal '(sym1 sym2 sym3) result)))) -(ert-deftest test-mplist-get--multiple-properties-get-middle () +(ert-deftest test-mplist-get-values--multiple-properties-get-middle () (let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 :prop3 sym5 sym6)) - (result (spacemacs/mplist-get input :prop2))) + (result (spacemacs/mplist-get-values input :prop2))) (should (equal '(sym4) result)))) -(ert-deftest test-mplist-get--multiple-properties-get-last () +(ert-deftest test-mplist-get-values--multiple-properties-get-last () (let* ((input '(dummy :prop1 sym1 sym2 sym3 :prop2 sym4 :prop3 sym5 sym6)) - (result (spacemacs/mplist-get input :prop3))) + (result (spacemacs/mplist-get-values input :prop3))) (should (equal '(sym5 sym6) result)))) -(ert-deftest test-mplist-get--one-property-no-value () +(ert-deftest test-mplist-get-values--one-property-no-value () (let* ((input '(dummy :property)) - (result (spacemacs/mplist-get input :property))) + (result (spacemacs/mplist-get-values input :property))) (should (null result)))) -(ert-deftest test-mplist-get--multiple-same-poperty-ignore-all-but-first () +(ert-deftest test-mplist-get-values--multiple-same-poperty-ignore-all-but-first () (let* ((input '(dummy :property val1 :property val2)) - (result (spacemacs/mplist-get input :property))) + (result (spacemacs/mplist-get-values input :property))) (should (equal '(val1) result)))) ;; --------------------------------------------------------------------------- -;; spacemacs/plist-get +;; spacemacs/mplist-get-value ;; --------------------------------------------------------------------------- -(ert-deftest test-plist-get--one-property () +(ert-deftest test-mplist-get-value--one-property () (let* ((input '(dummy :property sym1)) - (result (spacemacs/plist-get input :property))) + (result (spacemacs/mplist-get-value input :property))) (should (equal 'sym1 result)))) -(ert-deftest test-plist-get--one-property-multiple-values-returns-first () +(ert-deftest test-mplist-get-value--one-property-multiple-values-returns-first () (let* ((input '(dummy :property sym1 sym2 sym3)) - (result (spacemacs/plist-get input :property))) + (result (spacemacs/mplist-get-value input :property))) (should (equal 'sym1 result)))) -(ert-deftest test-plist-get--multiple-properties-get-first () +(ert-deftest test-mplist-get-value--multiple-properties-get-first () (let* ((input '(dummy :prop1 sym1 :prop2 sym4 :prop3 sym5)) - (result (spacemacs/plist-get input :prop1))) + (result (spacemacs/mplist-get-value input :prop1))) (should (equal 'sym1 result)))) -(ert-deftest test-plist-get--multiple-properties-get-middle () +(ert-deftest test-mplist-get-value--multiple-properties-get-middle () (let* ((input '(dummy :prop1 sym1 :prop2 sym4 :prop3 sym5)) - (result (spacemacs/plist-get input :prop2))) + (result (spacemacs/mplist-get-value input :prop2))) (should (equal 'sym4 result)))) -(ert-deftest test-plist-get--multiple-properties-get-last () +(ert-deftest test-mplist-get-value--multiple-properties-get-last () (let* ((input '(dummy :prop1 sym1 :prop2 sym4 :prop3 sym5)) - (result (spacemacs/plist-get input :prop3))) + (result (spacemacs/mplist-get-value input :prop3))) (should (equal 'sym5 result)))) -(ert-deftest test-plist-get--one-property-no-value () +(ert-deftest test-mplist-get-value--one-property-no-value () (let* ((input '(dummy :property)) - (result (spacemacs/plist-get input :property))) + (result (spacemacs/mplist-get-value input :property))) (should (null result)))) -(ert-deftest test-plist-get--one-property-no-value-next-is-another-property () +(ert-deftest test-mplist-get-value--one-property-no-value-next-is-another-property () (let* ((input '(dummy :property :property2 sym2)) - (result (spacemacs/plist-get input :property))) + (result (spacemacs/mplist-get-value input :property))) (should (null result)))) -(ert-deftest test-plist-get--multiple-same-poperty-ignore-all-but-first () +(ert-deftest test-mplist-get-value--multiple-same-poperty-ignore-all-but-first () (let* ((input '(dummy :property val1 :property val2)) - (result (spacemacs/plist-get input :property))) + (result (spacemacs/mplist-get-value input :property))) (should (equal 'val1 result)))) ;; ---------------------------------------------------------------------------