From bbd8f11719d15580da2e2bb0d98ea7afe97cf601 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 30 Jul 2022 21:35:24 +0100 Subject: [PATCH] feat(utils): add siren-prepend and siren-append macros These macros work more or less like add-to-list, except they will always leave ELEMENT as the first/last element in the list, while add-to-list does not modify the list if ELEMENT is already present anywhere in the list. --- core/siren-core-utils.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/siren-core-utils.el b/core/siren-core-utils.el index e5a17d1..45b0622 100644 --- a/core/siren-core-utils.el +++ b/core/siren-core-utils.el @@ -7,6 +7,14 @@ ;;; Code: +(defmacro siren-prepend (list-var element) + "Add ELEMENT to beginning of LIST-VAR, removing duplicates." + `(setq ,list-var (cons ,element (remove ,element ,list-var)))) + +(defmacro siren-append (list-var element) + "Add ELEMENT to end of LIST-VAR, removing duplicates." + `(setq ,list-var (append (remove ,element ,list-var) (list ,element)))) + (defun siren-recursive-add-to-load-path (dir) "Add DIR and all its sub-directories to `load-path'." (add-to-list 'load-path dir)