forked from FG42/FG42
1
0
Fork 0
FG42/lib/fg42/extension.el

45 lines
1.3 KiB
EmacsLisp
Raw Normal View History

;; This library provides some basic means to create a new FG42 extensions
(require 'cl-lib)
2015-07-07 12:25:06 +01:00
;; Variables -----------------------------
(defvar activated-extensions ()
"A list of all activated extensions.")
2015-07-08 17:59:42 +01:00
(defvar disabled-abilities (make-hash-table)
"A hash of all the disabled abilities")
;; Structures -----------------------------
(cl-defstruct fg42-extension
"Each FG42 extension should implement a copy of this structure."
name
(version nil)
;; Callbacks
(on-initialize nil)
(on-load))
2015-07-08 17:59:42 +01:00
;; Functions ------------------------------
(defun active-ability? (name)
"Return t if ability was not in disabled-abilities."
(if (gethash name disabled-abilities) nil t))
(defmacro ability (name deps &rest body)
"Define an ability with the given name.
*deps* should be a list of abilities with the defined ability dependens
to them.
*body* is a block of code which will run as the ability initializer code."
2015-07-08 18:38:40 +01:00
(declare (doc-string 2) (indent 1))
`(if (active-ability? (intern ,(symbol-name name)))
2015-07-08 17:59:42 +01:00
(if (null (delq t (mapcar 'active-ability? ,deps)))
2015-07-08 18:38:40 +01:00
,@body)))
2015-07-08 17:59:42 +01:00
(defmacro extension (name &rest args)
"A simple DSL to define new fg42 extension."
;(declare (doc-string 1) (indent 1))
`(setq ,name (apply 'make-fg42-extension :name ,(symbol-name name) (quote ,args))))
(provide 'fg42/extension)