Add auto-modes and hooks supports to cubes

This commit is contained in:
Sameer Rahmani 2021-01-30 18:52:04 +00:00
parent b2a7f1ce27
commit 01e38717f1
3 changed files with 66 additions and 2 deletions

View File

@ -28,9 +28,13 @@
(require 'fg42/cube)
(defcube fg42/elisp-cube ()
:keys nil
:requires '()
;;:hooks (list (lambda (system) '(emacs-lisp-mode-hook . fssd)))
;;:auto-modes (list (lambda (system) '("\\.el\\'" . fg42/elisp-cube-mmm)))
:dependencies '((:name rainbow-delimiters :version :latest)))

34
core/cubes/elisp/core.el Normal file
View File

@ -0,0 +1,34 @@
;;; ElispCube --- The elisp cube for 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:
;; Cubes are the building blocks of any `FG42' editor. Each `cube' is a
;; unit which defines different abilities in a deterministic and idempotent
;; way. Cubes are composable and a composition of cubes creates an editor.
;;
;;; Code:
(provide 'cubes/elisp/core)
;;; core.el ends here

View File

@ -49,7 +49,7 @@
(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))
(if (eq t (fg42/system-get-cube-property system cube-name :setup-finished))
system
(let ((cube (fg42/system-get-cube system cube-name)))
@ -64,7 +64,19 @@
(plist-get cube :requires)
system)))
(fg42/system-set-cube-property updated-system cube-name :dependencies-processed t)))))
;; Run the init function the cube.
;; The init function is just for setup, the return value of it
;; and the changes that it might make to the system will be discarded.
(funcall (or (plist-get cube :init) (lambda (x) ()))
system)
;; Setup the automods
(fg42/system-cube-auto-modes system cube)
;; Setup the hooks
(fg42/system-cube-hooks system cube)
(fg42/system-set-cube-property updated-system cube-name :setup-finished t)))))
(defun fg42/system-setup-cubes (system)
@ -77,6 +89,20 @@
system)))
(defun fg42/system-cube-auto-modes (system cube)
"Setup the auto modes of the given CUBE using the given SYSTEM."
(dolist (automod (mapcar (lambda (pred) (funcall pred system)) (plist-get cube :auto-modes)))
(when automod
(add-to-list 'auto-mode-alist automod))))
(defun fg42/system-cube-hooks (system cube)
"Setup the auto modes of the given CUBE using the given SYSTEM."
(dolist (hook (mapcar (lambda (pred) (funcall pred system)) (plist-get cube :hooks)))
(when hook
(message "Settting up hook: %s === %s" (car hook) (cdr hook))
(add-hook (car hook) (cdr hook)))))
(provide 'fg42/system/cubes)
;;; cubes.el ends here