diff --git a/core/cubes/autocompletion.el b/core/cubes/autocompletion.el index 1b7be73..498c5fe 100644 --- a/core/cubes/autocompletion.el +++ b/core/cubes/autocompletion.el @@ -25,30 +25,36 @@ (require 'fg42/cube) (defcube fg42/flycheck-cube - (:docs "cubes/fg42/flycheck-cube.org") + (:docs "cubes/fg42/flycheck-cube.org" + :flag flycheck) (fpkg/use flycheck :defer () :init (global-flycheck-mode))) (defcube fg42/yaml-cube - (:docs "cubes/fg42/prog-cubes.org") + (:docs "cubes/fg42/prog-cubes.org" + :no-flag t) (fpkg/use yaml-mode)) (defcube fg42/lsp-cube - (:docs "cubes/fg42/lsp-cube.org") + (:docs "cubes/fg42/lsp-cube.org" + :flag lsp) (fpkg/use lsp-mode :commands lsp :init (setq lsp-headerline-breadcrumb-enable nil)) + ;; TODO: Create a flag for lsp-ui or move it + ;; to a new cube (fpkg/use lsp-ui :config (add-hook 'lsp-mode-hook 'lsp-ui-mode))) (defcube fg42/c++-cube - (:docs "cubes/fg42/cpp-cube.org") + (:docs "cubes/fg42/cpp-cube.org" + :no-flag t) (add-hook 'c++-mode-hook (lambda () (lsp) @@ -60,7 +66,8 @@ (defcube fg42/company-cube - (:docs "cubes/fg42/company-cube.org") + (:docs "cubes/fg42/company-cube.org" + :flag company) (fpkg/use company :init (global-company-mode) @@ -74,6 +81,7 @@ company-show-numbers t) (setq company-dabbrev-downcase nil))) + ;; TODO: Move company box to a new cube (fpkg/use company-box :after company :config @@ -81,4 +89,4 @@ (provide 'cubes/autocompletion) -;;; editor.el ends here +;;; autocompletion.el ends here diff --git a/core/cubes/editor.el b/core/cubes/editor.el index 7e234c8..7cf023e 100644 --- a/core/cubes/editor.el +++ b/core/cubes/editor.el @@ -29,21 +29,24 @@ (defcube fg42/buffer-navigation-cube - (:docs "cubes/fg42/buffer-navigation-cube.org") + (:docs "cubes/fg42/buffer-navigation-cube.org" + :flag buffer-navigation) (fpkg/use avy :bind ("M-1" . avy-goto-word-1))) (defcube fg42/window-navigation-cube - (:docs "cubes/fg42/window-navigation-cube.org") + (:docs "cubes/fg42/window-navigation-cube.org" + :flag window-navigation) (fpkg/use ace-window :bind ("C-" . ace-window))) (defcube fg42/font-cube - (:docs "cubes/fg42/font-cube.org") + (:docs "cubes/fg42/font-cube.org" + :no-flag t) (let ((font (or (plist-get fg42/font-cube-params :font-name) "Fira Mono")) @@ -56,7 +59,8 @@ (set-face-attribute 'default t :font font))) (defcube fg42/dracula-theme-cube - (:docs "cubes/fg42/dracula-theme-cube.org") + (:docs "cubes/fg42/dracula-theme-cube.org" + :no-flag t) (fpkg/use dracula-theme :init (progn @@ -65,7 +69,8 @@ (defcube fg42/selectrum-cube - (:docs "cubes/fg42/editor-cube.org") + (:docs "cubes/fg42/editor-cube.org" + :flag selectrum) (fpkg/use selectrum :defer nil :init @@ -87,7 +92,8 @@ (defcube fg42/editor-cube - (:docs "cubes/fg42/editor-cube.org") + (:docs "cubes/fg42/editor-cube.org" + :no-flag t) (fpkg/use rainbow-delimiters ;; It doesn't work due to a problem/conflict in rainbow-delimiters diff --git a/core/cubes/elisp.el b/core/cubes/elisp.el index 65f768c..dcddb30 100644 --- a/core/cubes/elisp.el +++ b/core/cubes/elisp.el @@ -26,7 +26,8 @@ (defcube fg42/elisp-cube - (:docs "cubes/fg42/elisp-cube.org") + (:docs "cubes/fg42/elisp-cube.org" + :no-flag t) (fpkg/use rainbow-delimiters ;; It doesn't work due to a problem/conflict in rainbow-delimiters diff --git a/core/cubes/modeline.el b/core/cubes/modeline.el index f8830dd..3e78b81 100644 --- a/core/cubes/modeline.el +++ b/core/cubes/modeline.el @@ -24,9 +24,10 @@ (require 'fpkg) (require 'fg42/cube) - +;; TODO: Break this into two cubes (defcube fg42/modeline-cube - (:docs "cubes/fg42/modeline-cube.org") + (:docs "cubes/fg42/modeline-cube.org" + :flag smart-mode-line) (fpkg/use smart-mode-line :straight (smart-mode-line :source melpa) diff --git a/core/cubes/wm.el b/core/cubes/wm.el index a2d2fbe..da31591 100644 --- a/core/cubes/wm.el +++ b/core/cubes/wm.el @@ -40,14 +40,15 @@ (defcube fg42/wm-cube - (:docs "cubes/fg42/wm-cube.org") + (:docs "cubes/fg42/wm-cube.org" + :no-flag t) (if-flag wm (when-wm (message "[WM] Initilizing...") (fpkg/use exwm) (fg42/initialize-wm)) - (error "[SKIP] WM flag is not active."))) + (error "[SKIP] WM flag is not active"))) (provide 'cubes/wm) diff --git a/core/fg42/cube.el b/core/fg42/cube.el index 1d18ee7..8ed5609 100644 --- a/core/fg42/cube.el +++ b/core/fg42/cube.el @@ -38,16 +38,28 @@ (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 ((cube-name-internal (intern (format "%s-internal" cube-name))) + (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))) (post-lang-server-up-hook (intern (format "%s-post-lang-server-up-hook" cube-name))) (pre-lang-server-down-hook (intern (format "%s-pre-lang-server-down-hook" cube-name))) (post-lang-server-down-hook (intern (format "%s-post-lang-server-down-hook" cube-name))) (pre-init-hook (intern (format "%s-pre-init-hook" cube-name))) - (post-init-hook (intern (format "%s-post-init-hook" cube-name)))) + (post-init-hook (intern (format "%s-post-init-hook" cube-name))) + (post-init-hook (intern (format "%s-post-init-hook" cube-name))) + + (flag-var (or (plist-get props :flag) cube-name)) + (flag-docstring-var (or (plist-get props :flag-doc) + (format "The flag to enable/disable the '%s' cube." cube-name))) + (no-flag? (or (plist-get props :no-flag) ()))) `(progn + + ;; Create a new flag for each cube to control the cubes systemwide. + (when (not ,no-flag?) + (defflag ,flag-var ,flag-docstring-var)) + ;; Params variable contains the list of params the is passed to ;; the current cube call (defvar ,params-var nil @@ -89,26 +101,36 @@ (defvar ,post-lang-server-down-hook nil ,(format "The hook that runs after the '%s' cube's language server shuts down." cube-name)) + ;; This way we can bypass the flag system if we really really want to. + (defun ,cube-name-internal (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 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)))) (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 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))))))) + (interactive) + (if ,no-flag? + ;; If no flag is need to control this cube + (,cube-name-internal params) + ;; Otherwise check for the flag to be active + (if-flag ,flag-var + (,cube-name-internal params) + (message "The flag for '%s' cube is disabled. Skiping." ,(symbol-name cube-name)))))))) (provide 'fg42/cube)