83 lines
2.8 KiB
EmacsLisp
83 lines
2.8 KiB
EmacsLisp
;;; system --- System 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:
|
|
;; `System' is just a state monad which holds the state of the editor.
|
|
;; Each system has to have a `start' function to start the setup process.
|
|
;;
|
|
;;; Code:
|
|
(require 'seq)
|
|
(require 'fg42/system/core)
|
|
|
|
(defun fg42/system-get-cube (system cube-name)
|
|
"Return the cube with CUBE-NAME ins the SYSTEM."
|
|
;; car is the name cdr is the cube itself
|
|
(cdr (assoc cube-name (fg42/system-get system :cubes))))
|
|
|
|
|
|
(defun fg42/system-get-cube-property (system cube-name prop)
|
|
"Return the value of the given property PROP of CUBE-NAME in SYSTEM."
|
|
(let ((cube (fg42/system-get-cube system cube-name)))
|
|
(plist-get cube prop)))
|
|
|
|
|
|
(defun fg42/system-set-cube-property (system cube-name prop v)
|
|
"Set the given property PROP of CUBE-NAME to V in SYSTEM."
|
|
(let ((cube (append (list prop v)
|
|
(fg42/system-get-cube system cube-name))))
|
|
|
|
(fg42/system-register-cube system cube-name cube)))
|
|
|
|
|
|
(defun fg42/system-setup-cube (system cube-name)
|
|
"Setup the given CUBE-NAME using the given SYSTEM."
|
|
(if (eq t (fg42/system-get-cube-property system cube-name :dependencies-processed))
|
|
system
|
|
(let ((cube (fg42/system-get-cube system cube-name)))
|
|
|
|
(when (null cube)
|
|
(error "Can't find cube '%s' in the system" cube-name))
|
|
|
|
(message "Setting up '%s' cube..." cube-name)
|
|
(let ((updated-system
|
|
(seq-reduce
|
|
(lambda (sys requirement)
|
|
(fg42/system-setup-cube sys requirement))
|
|
(plist-get cube :requires)
|
|
system)))
|
|
|
|
(fg42/system-set-cube-property updated-system cube-name :dependencies-processed t)))))
|
|
|
|
|
|
(defun fg42/system-setup-cubes (system)
|
|
"Setup the cubes in the given SYSTEM by creating a dependency tree."
|
|
(let ((cubes (fg42/system-get system :cubes)))
|
|
(seq-reduce
|
|
(lambda (sys cube-pair)
|
|
(fg42/system-setup-cube sys (car cube-pair)))
|
|
cubes
|
|
system)))
|
|
|
|
|
|
|
|
(provide 'fg42/system/cubes)
|
|
;;; cubes.el ends here
|