Flags: Add the flags namespace
This new namespace contains all the necessary functionality to create 'flags' which are the new implementation of the old 'abilities'.
This commit is contained in:
parent
9c0feb18fe
commit
82437cf01b
|
@ -22,11 +22,16 @@
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
|
(defgroup fg42 nil
|
||||||
|
"Customize your FG42 instance via this group of configurations.")
|
||||||
|
|
||||||
|
|
||||||
(defvar fg42-home (getenv "FG42_HOME")
|
(defvar fg42-home (getenv "FG42_HOME")
|
||||||
"The pass to fg42-home.")
|
"The pass to fg42-home.")
|
||||||
|
|
||||||
|
|
||||||
(defvar fg42-tmp (concat fg42-home "/tmp"))
|
(defvar fg42-tmp (concat fg42-home "/tmp"))
|
||||||
|
|
||||||
|
|
||||||
(provide 'fg42/core)
|
(provide 'fg42/core)
|
||||||
;; core.el ends here
|
;;; core.el ends here
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
;;; Flags --- Flags library of FG42 -*- lexical-binding: t; -*-
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2010-2021 Sameer Rahmani & Contributors
|
||||||
|
;;
|
||||||
|
;; Author: Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
;; URL: https://gitlab.com/FG42/FG42
|
||||||
|
;; Version: 3.0.0
|
||||||
|
;;
|
||||||
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
;;
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
;;
|
||||||
|
;;; Commentary:
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'seq)
|
||||||
|
(require 'fg42/core)
|
||||||
|
|
||||||
|
|
||||||
|
(defvar fg42/available-flags nil
|
||||||
|
"A list of defined flags.
|
||||||
|
|
||||||
|
Only use \\[defflag] to add a new flag to this list")
|
||||||
|
|
||||||
|
|
||||||
|
(defcustom fg42/flags nil
|
||||||
|
"A set of flags to mark the functionalities that expected from FG42.
|
||||||
|
Flags are defined using the \\[defflag] through out the source code.
|
||||||
|
|
||||||
|
To see a list of available flags use \\[fg42/show-all-flags] and to see
|
||||||
|
the documentation of each flag simply use \\[describe-flag]."
|
||||||
|
:group fg42
|
||||||
|
:package-version '(FG42 . "3.x")
|
||||||
|
:type '(symbol)
|
||||||
|
:tag "FG42 Flags")
|
||||||
|
|
||||||
|
|
||||||
|
(defmacro use-flags (&rest flags)
|
||||||
|
"Set the given FLAGS to activate their functionalities in FG42."
|
||||||
|
(setq fg42/flags flags))
|
||||||
|
|
||||||
|
|
||||||
|
(defun fg42/-merge-flags (flags-set &rest new-flags)
|
||||||
|
"Merge the given NEW-FLAGS into the FLAGS-SET and return the result."
|
||||||
|
(remove-duplicates
|
||||||
|
(seq-reduce
|
||||||
|
(lambda (result flag)
|
||||||
|
(let ((flag-str (symbol-name flag)))
|
||||||
|
(if (string-prefix-p "-" flag-str)
|
||||||
|
(let ((actual-flag (intern (substring flag-str 1))))
|
||||||
|
(if (member actual-flag result)
|
||||||
|
(remove actual-flag result)
|
||||||
|
result))
|
||||||
|
;; We don't want to check for duplicates here since we remove them
|
||||||
|
;; later
|
||||||
|
(cons flag result))))
|
||||||
|
new-flags
|
||||||
|
flags-set)))
|
||||||
|
|
||||||
|
|
||||||
|
(defmacro fg42/merge-flags (flags-set &rest new-flags)
|
||||||
|
"Merge the given NEW-FLAGS into the FLAGS-SET and return the result.
|
||||||
|
|
||||||
|
If any flag name in NEW-FLAGS list starts with `-' (a dash) it implies that
|
||||||
|
that functionality has to be disabled and removed from FLAGS-SET. For example,
|
||||||
|
`-lsp' implies that we DO NOT want to have `lsp' flag enabled and it should not
|
||||||
|
exist in the return value.
|
||||||
|
|
||||||
|
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 defflag (flag-name docstring)
|
||||||
|
"Define a new flag FLAG-NAME with the given DOCSTRING."
|
||||||
|
(let ((var-name (format "fg42/-flag-%s" flag-name)))
|
||||||
|
`(if (boundp ,var-name)
|
||||||
|
(warn (foramt "Flag name `%s' already defined" ,flag-name))
|
||||||
|
(progn
|
||||||
|
(defvar ,var-name t)
|
||||||
|
(add-to-list 'fg42/available-flags ,flag-name)))))
|
||||||
|
|
||||||
|
|
||||||
|
(defmacro when-flag (flag &rest body)
|
||||||
|
"Evaluate the BODY only if the given FLAG is active."
|
||||||
|
|
||||||
|
;; The `cube-local-flags' variable here is going to be
|
||||||
|
;; defined in cubes to hold the local flags for each cube
|
||||||
|
(if (and (boundp 'cube-local-flags)
|
||||||
|
(member flag cube-local-flags))
|
||||||
|
`,@body
|
||||||
|
(if (member flag fg42/flags)
|
||||||
|
`,@body
|
||||||
|
nil)))
|
||||||
|
|
||||||
|
|
||||||
|
(provide 'fg42/flags)
|
||||||
|
;;; flags.el ends here
|
1
dev.org
1
dev.org
|
@ -38,6 +38,7 @@ On the first level, I should feel comfortable with it.
|
||||||
|
|
||||||
* Tasks
|
* Tasks
|
||||||
** TODO Reformat the modeline
|
** TODO Reformat the modeline
|
||||||
|
** TODO Create a macro similar to `with-ability` to run a block of code only if the given cube was active
|
||||||
|
|
||||||
* Things that didn't work out
|
* Things that didn't work out
|
||||||
- rbenv
|
- rbenv
|
||||||
|
|
Loading…
Reference in New Issue