From 08e9826818ff46a3a25cb80ec060d1b6e5339ac2 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Fri, 7 May 2021 15:04:14 +0100 Subject: [PATCH] Add the :flag-default to cubes to activate them by default --- core/cubes/project.el | 6 +++++- core/fg42/cube.el | 4 +++- core/fg42/flags.el | 15 +++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/core/cubes/project.el b/core/cubes/project.el index 74edde3..f295099 100644 --- a/core/cubes/project.el +++ b/core/cubes/project.el @@ -25,9 +25,11 @@ (require 'fg42/cube) + (defcube fg42/projectile-cube (:docs "cubes/fg42/projectile-cube.org" - :flag projectile) + :flag projectile + :flag-default t) (let ((project-dirs (or (plist-get fg42/projectile-cube-params :project-dirs) ()))) @@ -48,5 +50,7 @@ :after projectile))) + + (provide 'cubes/project) ;;; project.el ends here diff --git a/core/fg42/cube.el b/core/fg42/cube.el index 8ed5609..b702d6e 100644 --- a/core/fg42/cube.el +++ b/core/fg42/cube.el @@ -52,13 +52,15 @@ (flag-var (or (plist-get props :flag) cube-name)) (flag-docstring-var (or (plist-get props :flag-doc) (format "The flag to enable/disable the '%s' cube." cube-name))) + (flag-default (plist-get props :flag-default)) + (flag-conflict (plist-get props :conflicts-with)) (no-flag? (or (plist-get props :no-flag) ()))) `(progn ;; Create a new flag for each cube to control the cubes systemwide. (when (not ,no-flag?) - (defflag ,flag-var ,flag-docstring-var)) + (defflag ,flag-var ,flag-docstring-var ,flag-default)) ;; Params variable contains the list of params the is passed to ;; the current cube call diff --git a/core/fg42/flags.el b/core/fg42/flags.el index 593f2b4..0d46810 100644 --- a/core/fg42/flags.el +++ b/core/fg42/flags.el @@ -22,6 +22,7 @@ ;;; Commentary: ;;; Code: +(require 'cl-lib) (require 'seq) (require 'fg42/core) @@ -44,15 +45,16 @@ the documentation of each flag simply use \\[describe-flag]." :tag "FG42 Flags") -(defmacro use-flags (&rest flags) +(defmacro use-flags (flags) "Set the given FLAGS to activate their functionalities in FG42." - (setq fg42/flags flags) - t) + `(progn + (setq fg42/flags ,flags) + t)) (defun fg42/-merge-flags (flags-set &rest new-flags) "Merge the given NEW-FLAGS into the FLAGS-SET and return the result." - (remove-duplicates + (cl-remove-duplicates (seq-reduce (lambda (result flag) (let ((flag-str (symbol-name flag))) @@ -80,6 +82,11 @@ For example, `(fg42/merge-flags (list f1 f2 f3) f4 -f2)' will return `(f1 f3 f4) `(fg42/-merge-flags ,flags-set ,@(mapcar (lambda (x) `',x) new-flags))) +(defmacro fg42/merge-with-default-flags (&rest new-flags) + "Merge the given list of NEW-FLAGS with default flags of FG42 and return the new set." + `(fg42/merge-flags fg42/flags ,@new-flags)) + + (defmacro defflag (flag-name docstring &optional default-value) "Define a new flag FLAG-NAME with the given DOCSTRING. If the DEFAULT-VALUE is a non nil value, then the flag will be