Add :flag and :no-flag to cube macro

This way we can define flags to control the cubes
automatically. Then we can just call cubes inside
of each other and control the behavior via flags.
if :no-flag set to true then the cube won't be needing
a flag to get activated.
This commit is contained in:
Sameer Rahmani 2021-05-03 01:42:57 +01:00
parent a62c529605
commit 6c4b304afe
6 changed files with 76 additions and 37 deletions

View File

@ -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

View File

@ -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-<tab>" . 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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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,8 +101,8 @@
(defvar ,post-lang-server-down-hook nil
,(format "The hook that runs after the '%s' cube's language server shuts down." cube-name))
(defun ,cube-name (&rest params)
;; 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
@ -108,7 +120,17 @@
(let ((result (progn ,@body)))
;; Run the post init hook
(run-hooks (quote ,post-init-hook))
result)))))))
result))))
(defun ,cube-name (&rest params)
(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)