From 01e38717f132c84fc6ad53e99309b2d13ef2101f Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sat, 30 Jan 2021 18:52:04 +0000 Subject: [PATCH] Add auto-modes and hooks supports to cubes --- core/cubes/elisp.el | 4 ++++ core/cubes/elisp/core.el | 34 ++++++++++++++++++++++++++++++++++ core/fg42/system/cubes.el | 30 ++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 core/cubes/elisp/core.el diff --git a/core/cubes/elisp.el b/core/cubes/elisp.el index 3c56cb5..8f26a75 100644 --- a/core/cubes/elisp.el +++ b/core/cubes/elisp.el @@ -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))) diff --git a/core/cubes/elisp/core.el b/core/cubes/elisp/core.el new file mode 100644 index 0000000..93bd6dc --- /dev/null +++ b/core/cubes/elisp/core.el @@ -0,0 +1,34 @@ +;;; ElispCube --- The elisp cube for FG42 -*- lexical-binding: t; -*- +;; +;; Copyright (c) 2010-2021 Sameer Rahmani & Contributors +;; +;; Author: Sameer Rahmani +;; 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 . +;; +;;; 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 diff --git a/core/fg42/system/cubes.el b/core/fg42/system/cubes.el index 77d1283..f9435ab 100644 --- a/core/fg42/system/cubes.el +++ b/core/fg42/system/cubes.el @@ -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