Upgrade the defcube macro with some hooks

This commit is contained in:
Sameer Rahmani 2021-04-18 16:10:02 +01:00
parent bd0e09391e
commit 55f0a3dab0
7 changed files with 71 additions and 11 deletions

View File

@ -30,6 +30,8 @@
(defcube fg42/editor-cube (defcube fg42/editor-cube
(:docs "cubes/fg42/editor-cube.org")
(fpkg/use rainbow-delimiters (fpkg/use rainbow-delimiters
;; It doesn't work due to a problem/conflict in rainbow-delimiters ;; It doesn't work due to a problem/conflict in rainbow-delimiters
;; But we use it any way they might fix it ;; But we use it any way they might fix it

View File

@ -26,6 +26,8 @@
(defcube fg42/elisp-cube (defcube fg42/elisp-cube
(:docs "cubes/fg42/elisp-cube.org")
(fpkg/use rainbow-delimiters (fpkg/use rainbow-delimiters
;; It doesn't work due to a problem/conflict in rainbow-delimiters ;; It doesn't work due to a problem/conflict in rainbow-delimiters
;; But we use it any way they might fix it ;; But we use it any way they might fix it

View File

@ -0,0 +1,35 @@
;;; RegionExpansionCube --- 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:
;;; 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

View File

@ -31,6 +31,13 @@
(defmacro defcube (cube-name props &rest body) (defmacro defcube (cube-name props &rest body)
"Define a cube with the given CUBE-NAME, a list of PROPS and a 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))) (let ((params-var (intern (format "%s-params" cube-name)))
(active-var (intern (format "%s-active-p" 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))) (pre-lang-server-up-hook (intern (format "%s-pre-lang-server-up-hook" cube-name)))
@ -86,11 +93,22 @@
(defun ,cube-name (&rest params) (defun ,cube-name (&rest params)
(when (not (boundp (quote ,active-var))) (when (not (boundp (quote ,active-var)))
(progn (progn
;; Mark this cube as active
(setq ,active-var t) (setq ,active-var t)
;; Set the parameters in CUBE-NAME-params to be accessable
;; in the body
(setq ,params-var params) (setq ,params-var params)
(run-hook (quote ,pre-init-hook))
,@body ;; Run the pre init hook
(run-hook (quote ,post-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) (provide 'fg42/cube)

View File

@ -29,11 +29,12 @@
;;(require 'use-package) ;;(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." "Install the given package details PKG via use-package and straight."
(declare (indent defun)) (declare (indent defun))
(if (listp pkg) (message "heeeeeeeeeeeeeeeeeeeeer %s" pkg)
`(use-package ,@pkg :straight t :defer t) (if (listp details)
`(use-package ,pkg :straight ,@details :defer t)
`(use-package ,pkg :straight t :defer t))) `(use-package ,pkg :straight t :defer t)))

View File

@ -37,9 +37,11 @@
(defun fpkg/install-and-load-use-package () (defun fpkg/install-and-load-use-package ()
"Install and load the use-package in compile time." "Install and load the use-package in compile time."
(eval-when-compile ;; TODO Enable use-package on compile time
(straight-use-package 'use-package) ;;(eval-when-compile)
(require 'use-package))) (straight-use-package 'use-package)
(setq use-package-always-ensure t)
(require 'use-package))

View File

@ -38,8 +38,8 @@ On the first level, I should feel comfortable with it.
* Tasks * Tasks
** TODO Reformat the modeline ** 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 * Things that didn't work out
- rbenv - rbenv
- helm - helm