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:
parent
a62c529605
commit
6c4b304afe
|
@ -25,30 +25,36 @@
|
||||||
(require 'fg42/cube)
|
(require 'fg42/cube)
|
||||||
|
|
||||||
(defcube fg42/flycheck-cube
|
(defcube fg42/flycheck-cube
|
||||||
(:docs "cubes/fg42/flycheck-cube.org")
|
(:docs "cubes/fg42/flycheck-cube.org"
|
||||||
|
:flag flycheck)
|
||||||
(fpkg/use flycheck
|
(fpkg/use flycheck
|
||||||
:defer ()
|
:defer ()
|
||||||
:init
|
:init
|
||||||
(global-flycheck-mode)))
|
(global-flycheck-mode)))
|
||||||
|
|
||||||
(defcube fg42/yaml-cube
|
(defcube fg42/yaml-cube
|
||||||
(:docs "cubes/fg42/prog-cubes.org")
|
(:docs "cubes/fg42/prog-cubes.org"
|
||||||
|
:no-flag t)
|
||||||
(fpkg/use yaml-mode))
|
(fpkg/use yaml-mode))
|
||||||
|
|
||||||
(defcube fg42/lsp-cube
|
(defcube fg42/lsp-cube
|
||||||
(:docs "cubes/fg42/lsp-cube.org")
|
(:docs "cubes/fg42/lsp-cube.org"
|
||||||
|
:flag lsp)
|
||||||
|
|
||||||
(fpkg/use lsp-mode
|
(fpkg/use lsp-mode
|
||||||
:commands lsp
|
:commands lsp
|
||||||
:init
|
:init
|
||||||
(setq lsp-headerline-breadcrumb-enable nil))
|
(setq lsp-headerline-breadcrumb-enable nil))
|
||||||
|
|
||||||
|
;; TODO: Create a flag for lsp-ui or move it
|
||||||
|
;; to a new cube
|
||||||
(fpkg/use lsp-ui
|
(fpkg/use lsp-ui
|
||||||
:config
|
:config
|
||||||
(add-hook 'lsp-mode-hook 'lsp-ui-mode)))
|
(add-hook 'lsp-mode-hook 'lsp-ui-mode)))
|
||||||
|
|
||||||
(defcube fg42/c++-cube
|
(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 ()
|
(add-hook 'c++-mode-hook (lambda ()
|
||||||
(lsp)
|
(lsp)
|
||||||
|
@ -60,7 +66,8 @@
|
||||||
|
|
||||||
|
|
||||||
(defcube fg42/company-cube
|
(defcube fg42/company-cube
|
||||||
(:docs "cubes/fg42/company-cube.org")
|
(:docs "cubes/fg42/company-cube.org"
|
||||||
|
:flag company)
|
||||||
|
|
||||||
(fpkg/use company
|
(fpkg/use company
|
||||||
:init (global-company-mode)
|
:init (global-company-mode)
|
||||||
|
@ -74,6 +81,7 @@
|
||||||
company-show-numbers t)
|
company-show-numbers t)
|
||||||
(setq company-dabbrev-downcase nil)))
|
(setq company-dabbrev-downcase nil)))
|
||||||
|
|
||||||
|
;; TODO: Move company box to a new cube
|
||||||
(fpkg/use company-box
|
(fpkg/use company-box
|
||||||
:after company
|
:after company
|
||||||
:config
|
:config
|
||||||
|
@ -81,4 +89,4 @@
|
||||||
|
|
||||||
|
|
||||||
(provide 'cubes/autocompletion)
|
(provide 'cubes/autocompletion)
|
||||||
;;; editor.el ends here
|
;;; autocompletion.el ends here
|
||||||
|
|
|
@ -29,21 +29,24 @@
|
||||||
|
|
||||||
|
|
||||||
(defcube fg42/buffer-navigation-cube
|
(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
|
(fpkg/use avy
|
||||||
:bind ("M-1" . avy-goto-word-1)))
|
:bind ("M-1" . avy-goto-word-1)))
|
||||||
|
|
||||||
|
|
||||||
(defcube fg42/window-navigation-cube
|
(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
|
(fpkg/use ace-window
|
||||||
:bind ("C-<tab>" . ace-window)))
|
:bind ("C-<tab>" . ace-window)))
|
||||||
|
|
||||||
|
|
||||||
(defcube fg42/font-cube
|
(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)
|
(let ((font (or (plist-get fg42/font-cube-params :font-name)
|
||||||
"Fira Mono"))
|
"Fira Mono"))
|
||||||
|
@ -56,7 +59,8 @@
|
||||||
(set-face-attribute 'default t :font font)))
|
(set-face-attribute 'default t :font font)))
|
||||||
|
|
||||||
(defcube fg42/dracula-theme-cube
|
(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
|
(fpkg/use dracula-theme
|
||||||
:init
|
:init
|
||||||
(progn
|
(progn
|
||||||
|
@ -65,7 +69,8 @@
|
||||||
|
|
||||||
|
|
||||||
(defcube fg42/selectrum-cube
|
(defcube fg42/selectrum-cube
|
||||||
(:docs "cubes/fg42/editor-cube.org")
|
(:docs "cubes/fg42/editor-cube.org"
|
||||||
|
:flag selectrum)
|
||||||
(fpkg/use selectrum
|
(fpkg/use selectrum
|
||||||
:defer nil
|
:defer nil
|
||||||
:init
|
:init
|
||||||
|
@ -87,7 +92,8 @@
|
||||||
|
|
||||||
|
|
||||||
(defcube fg42/editor-cube
|
(defcube fg42/editor-cube
|
||||||
(:docs "cubes/fg42/editor-cube.org")
|
(:docs "cubes/fg42/editor-cube.org"
|
||||||
|
:no-flag t)
|
||||||
|
|
||||||
(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
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
|
|
||||||
|
|
||||||
(defcube fg42/elisp-cube
|
(defcube fg42/elisp-cube
|
||||||
(:docs "cubes/fg42/elisp-cube.org")
|
(:docs "cubes/fg42/elisp-cube.org"
|
||||||
|
:no-flag t)
|
||||||
|
|
||||||
(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
|
||||||
|
|
|
@ -24,9 +24,10 @@
|
||||||
(require 'fpkg)
|
(require 'fpkg)
|
||||||
(require 'fg42/cube)
|
(require 'fg42/cube)
|
||||||
|
|
||||||
|
;; TODO: Break this into two cubes
|
||||||
(defcube fg42/modeline-cube
|
(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
|
(fpkg/use smart-mode-line
|
||||||
:straight (smart-mode-line :source melpa)
|
:straight (smart-mode-line :source melpa)
|
||||||
|
|
|
@ -40,14 +40,15 @@
|
||||||
|
|
||||||
|
|
||||||
(defcube fg42/wm-cube
|
(defcube fg42/wm-cube
|
||||||
(:docs "cubes/fg42/wm-cube.org")
|
(:docs "cubes/fg42/wm-cube.org"
|
||||||
|
:no-flag t)
|
||||||
|
|
||||||
(if-flag wm
|
(if-flag wm
|
||||||
(when-wm
|
(when-wm
|
||||||
(message "[WM] Initilizing...")
|
(message "[WM] Initilizing...")
|
||||||
(fpkg/use exwm)
|
(fpkg/use exwm)
|
||||||
(fg42/initialize-wm))
|
(fg42/initialize-wm))
|
||||||
(error "[SKIP] WM flag is not active.")))
|
(error "[SKIP] WM flag is not active")))
|
||||||
|
|
||||||
|
|
||||||
(provide 'cubes/wm)
|
(provide 'cubes/wm)
|
||||||
|
|
|
@ -38,16 +38,28 @@
|
||||||
(when (not (plist-get props :docs))
|
(when (not (plist-get props :docs))
|
||||||
(error "Missing docs key for '%s' cube" cube-name))
|
(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)))
|
(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)))
|
||||||
(post-lang-server-up-hook (intern (format "%s-post-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)))
|
(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)))
|
(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)))
|
(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
|
`(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
|
;; Params variable contains the list of params the is passed to
|
||||||
;; the current cube call
|
;; the current cube call
|
||||||
(defvar ,params-var nil
|
(defvar ,params-var nil
|
||||||
|
@ -89,26 +101,36 @@
|
||||||
(defvar ,post-lang-server-down-hook nil
|
(defvar ,post-lang-server-down-hook nil
|
||||||
,(format "The hook that runs after the '%s' cube's language server shuts down." cube-name))
|
,(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)
|
(defun ,cube-name (&rest params)
|
||||||
(when (not (boundp (quote ,active-var)))
|
(interactive)
|
||||||
(progn
|
(if ,no-flag?
|
||||||
;; Mark this cube as active
|
;; If no flag is need to control this cube
|
||||||
(setq ,active-var t)
|
(,cube-name-internal params)
|
||||||
|
;; Otherwise check for the flag to be active
|
||||||
;; Set the parameters in CUBE-NAME-params to be accessable
|
(if-flag ,flag-var
|
||||||
;; in the body
|
(,cube-name-internal params)
|
||||||
(setq ,params-var params)
|
(message "The flag for '%s' cube is disabled. Skiping." ,(symbol-name cube-name))))))))
|
||||||
|
|
||||||
;; 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)
|
(provide 'fg42/cube)
|
||||||
|
|
Loading…
Reference in New Issue