From 55f0a3dab02bba99efc3c74896a4ad5758357e88 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 18 Apr 2021 16:10:02 +0100 Subject: [PATCH] Upgrade the defcube macro with some hooks --- core/cubes/editor.el | 2 ++ core/cubes/elisp.el | 2 ++ core/cubes/region-expansion.el | 35 ++++++++++++++++++++++++++++++++++ core/fg42/cube.el | 24 ++++++++++++++++++++--- core/fpkg.el | 7 ++++--- core/fpkg/core.el | 8 +++++--- dev.org | 4 ++-- 7 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 core/cubes/region-expansion.el diff --git a/core/cubes/editor.el b/core/cubes/editor.el index 0b52f40..56ee4b8 100644 --- a/core/cubes/editor.el +++ b/core/cubes/editor.el @@ -30,6 +30,8 @@ (defcube fg42/editor-cube + (:docs "cubes/fg42/editor-cube.org") + (fpkg/use rainbow-delimiters ;; It doesn't work due to a problem/conflict in rainbow-delimiters ;; But we use it any way they might fix it diff --git a/core/cubes/elisp.el b/core/cubes/elisp.el index 051e7ac..65f768c 100644 --- a/core/cubes/elisp.el +++ b/core/cubes/elisp.el @@ -26,6 +26,8 @@ (defcube fg42/elisp-cube + (:docs "cubes/fg42/elisp-cube.org") + (fpkg/use rainbow-delimiters ;; It doesn't work due to a problem/conflict in rainbow-delimiters ;; But we use it any way they might fix it diff --git a/core/cubes/region-expansion.el b/core/cubes/region-expansion.el new file mode 100644 index 0000000..dc1a15e --- /dev/null +++ b/core/cubes/region-expansion.el @@ -0,0 +1,35 @@ +;;; RegionExpansionCube --- 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: +;;; Code: +(require 'fpkg) +(require 'fg42/cube) + + +(defcube fg42/region-expansion-cube + (:docs "cubes/fg42/region-expansion.org") + + (fpkg/use expand-region + :bind ("C-=" . er/expand-region))) + +(provide 'cubes/region-expansion) +;;; region-expansion.el ends here diff --git a/core/fg42/cube.el b/core/fg42/cube.el index fa4e841..1d18ee7 100644 --- a/core/fg42/cube.el +++ b/core/fg42/cube.el @@ -31,6 +31,13 @@ (defmacro defcube (cube-name props &rest body) "Define a cube with the given CUBE-NAME, a list of PROPS and a BODY." + (declare (indent defun)) + + ;; Make sure that props is a plist and contains the `:docs' key + ;; TODO: Maybe use `cl-check-type' here + (when (not (plist-get props :docs)) + (error "Missing docs key for '%s' cube" cube-name)) + (let ((params-var (intern (format "%s-params" cube-name))) (active-var (intern (format "%s-active-p" cube-name))) (pre-lang-server-up-hook (intern (format "%s-pre-lang-server-up-hook" cube-name))) @@ -86,11 +93,22 @@ (defun ,cube-name (&rest params) (when (not (boundp (quote ,active-var))) (progn + ;; Mark this cube as active (setq ,active-var t) + + ;; Set the parameters in CUBE-NAME-params to be accessable + ;; in the body (setq ,params-var params) - (run-hook (quote ,pre-init-hook)) - ,@body - (run-hook (quote ,post-init-hook)))))))) + + ;; Run the pre init hook + (run-hooks (quote ,pre-init-hook)) + + (message "Initializing '%s' cube." (quote ,cube-name)) + ;; Run the body + (let ((result (progn ,@body))) + ;; Run the post init hook + (run-hooks (quote ,post-init-hook)) + result))))))) (provide 'fg42/cube) diff --git a/core/fpkg.el b/core/fpkg.el index a45ad7c..fa43f3d 100644 --- a/core/fpkg.el +++ b/core/fpkg.el @@ -29,11 +29,12 @@ ;;(require 'use-package) -(defmacro fpkg/use (&rest pkg) +(defmacro fpkg/use (pkg &rest details) "Install the given package details PKG via use-package and straight." (declare (indent defun)) - (if (listp pkg) - `(use-package ,@pkg :straight t :defer t) + (message "heeeeeeeeeeeeeeeeeeeeer %s" pkg) + (if (listp details) + `(use-package ,pkg :straight ,@details :defer t) `(use-package ,pkg :straight t :defer t))) diff --git a/core/fpkg/core.el b/core/fpkg/core.el index bac8858..22ac7c9 100644 --- a/core/fpkg/core.el +++ b/core/fpkg/core.el @@ -37,9 +37,11 @@ (defun fpkg/install-and-load-use-package () "Install and load the use-package in compile time." - (eval-when-compile - (straight-use-package 'use-package) - (require 'use-package))) + ;; TODO Enable use-package on compile time + ;;(eval-when-compile) + (straight-use-package 'use-package) + (setq use-package-always-ensure t) + (require 'use-package)) diff --git a/dev.org b/dev.org index 7d9029d..4704d4f 100644 --- a/dev.org +++ b/dev.org @@ -38,8 +38,8 @@ On the first level, I should feel comfortable with it. * Tasks ** TODO Reformat the modeline -** TODO Create a macro similar to `with-ability` to run a block of code only if the given cube was active - +** TODO Create a macro similar to =with-ability= to run a block of code only if the given cube was active +** TODO Enable =straight= and =use-package= integration on compile time. Checout out =fpkg/core.el= * Things that didn't work out - rbenv - helm