FG42/lib/fg42/extension.el

51 lines
1.5 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))
2015-07-09 00:00:45 +01:00
;; Macros ---------------------------------
2015-07-08 17:59:42 +01:00
(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-09 00:00:45 +01:00
(when (null (delq t (mapcar 'active-ability? (quote ,deps))))
,@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))))
2015-07-09 00:00:45 +01:00
(defmacro with-ability (name &rest body)
"Run the block of code if an ability with the given name was not disable."
`(when (active-ability? (intern ,(symbol-name name)))
,@body))
(provide 'fg42/extension)