diff --git a/Makefile b/Makefile index 7508409..28d4726 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -#! /bin/bash # Fg42 - Emacs Editor for advance users # # Copyright (c) 2010-2022 Sameer Rahmani diff --git a/core/cubes/graph.el b/core/cubes/graph.el index fd13d9c..e1c5204 100644 --- a/core/cubes/graph.el +++ b/core/cubes/graph.el @@ -41,12 +41,19 @@ If =company= flag is enabled then =dot= autocomplete will be enabled as well." :modes 'graphviz-dot-mode) (let ((indent-size (or (plist-get fg42/graphviz-cube-params :indent-size) 4))) - (when-flag 'company - (fpkg/use company-graphviz-dot)) + (fg42/after-cubes + (when-flag org + (add-hook 'org-mode-hook + (lambda () + (org-babel-do-load-languages + 'org-babel-load-languages + '((dot . t) + (graphviz-dot . t))))))) (fpkg/use graphviz-dot-mode :config (setq graphviz-dot-indent-width indent-size)))) + (provide 'cubes/graph) ;;; graph.el ends here diff --git a/core/cubes/modeline/statusbar-default.el b/core/cubes/modeline/statusbar-default.el index 8d6e7f6..4e08ae8 100644 --- a/core/cubes/modeline/statusbar-default.el +++ b/core/cubes/modeline/statusbar-default.el @@ -86,6 +86,10 @@ thresholds ERR adn WARN" ;; (defun fg42/statusbar-setup-git-branch-updater () ;; ;;(add-function :after after-focus-change-function #'fg42/statusbar-update-git-branch) + +;; (add-hook 'window-configuration-change-hook (lambda () (message "window-configuration-change-hook"))) +;; (add-hook 'window-state-change-hook (lambda () (message "window-state-change-hook"))) + ;; (advice-add :after 'ace-select-window #'fg42/statusbar-update-git-branch) ;; 'fg42/statusbar-git-branch) diff --git a/core/fg42/cube.el b/core/fg42/cube.el index 26cd3fd..29875a9 100644 --- a/core/fg42/cube.el +++ b/core/fg42/cube.el @@ -28,6 +28,14 @@ (require 'seq) (require 'fg42/utils) +(defvar fg42/after-cubes-setup-hook nil + "A hook that will be run after all the active cubes got setup. This hook +is dedicated for the codes that needs to do stuff based on other cubes +presence. With this hook we eliminate the need for cube ordering. + +It will be called in the `fg42-config' and the proper way to use +it is to use `fg42/after-cubes' macro. ") + (defvar fg42/available-cubes '() "A list of all the registered cubes.") @@ -70,7 +78,7 @@ ;; Create a new flag for each cube to control the cubes systemwide. (when (not ,no-flag?) - (defflag ,flag-var ,flag-docstring-var ,flag-default)) + (defflag ,flag-var ,flag-docstring-var ,flag-default)) ;; Params variable contains the list of params the is passed to ;; the current cube call @@ -150,5 +158,13 @@ (setplist ',cube-name ',complete-props)))) +(defmacro fg42/after-cubes (&rest body) + "Add the BODY to `fg42/after-cubes-setup-hook' hook." + (declare (indent defun)) + `(add-hook 'fg42/after-cubes-setup-hook + (lambda () + ,@body))) + + (provide 'fg42/cube) ;;; cube.el ends here diff --git a/core/ob-graphviz-dot.el b/core/ob-graphviz-dot.el new file mode 100644 index 0000000..cef04f8 --- /dev/null +++ b/core/ob-graphviz-dot.el @@ -0,0 +1,85 @@ +;;; ob-gharphviz --- org-babel functions for gharphviz evaluation of FG42 +;; +;; 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: + +;; This file location is important and can't be under `fg42/' dir even +;; though it is part of the FG42. That's due to the `org-babel' mechanism +;; to automatically load the language backend. SO DO NOT MOVE IT. + +;;; Code: +(require 'ob) +(require 'ob-ref) +(require 'ob-comint) +(require 'ob-eval) +(require 'ob-dot) + + +(add-to-list 'org-babel-tangle-lang-exts '("graphviz-dot" . "dot")) + +(defvar org-babel-default-header-args:graphviz-dot + '((:results . "file") (:exports . "results"))) + +(defun org-babel-expand-body:ghraphviz-dot (body params &optional processed-params) + "Expand BODY according to PARAMS, return the expanded body." + (let ((vars (org-babel--get-vars params))) + (mapc + (lambda (pair) + (let ((name (symbol-name (car pair))) + (value (cdr pair))) + (setq body + (replace-regexp-in-string + (concat "$" (regexp-quote name)) + (if (stringp value) value (format "%S" value)) + body + t + t)))) + vars) + body)) + +(defun org-babel-execute:graphviz-dot (body params) + "Execute a block of Template code with org-babel. +This function is called by `org-babel-execute-src-block'" + (let* ((out-file (cdr (or (assq :file params) + (error "You need to specify a :file parameter")))) + (cmdline (or (cdr (assq :cmdline params)) + (format "-T%s" (file-name-extension out-file)))) + (cmd (or (cdr (assq :cmd params)) "dot")) + (coding-system-for-read 'utf-8) ;use utf-8 with sub-processes + (coding-system-for-write 'utf-8) + (in-file (org-babel-temp-file "dot-"))) + (with-temp-file in-file + (insert (org-babel-expand-body:dot body params))) + (org-babel-eval + (concat cmd + " " (org-babel-process-file-name in-file) + " " cmdline + " -o " (org-babel-process-file-name out-file)) "") + ;; signal that output has already been written to file + nil)) + + +(defun org-babel-prep-session:graphviz-dot (session params) + "Prepare SESSION according to the header arguments specified in PARAMS." + (error "Dot does not support sessions")) + +(provide 'ob-graphviz-dot) +;;; ob-graphviz-dot.el ends here diff --git a/fg42-config.el b/fg42-config.el index f6880f6..c6e4bb7 100644 --- a/fg42-config.el +++ b/fg42-config.el @@ -49,6 +49,7 @@ (fg42/before-initialize) (fg42/initialize) +(run-hooks 'fg42/after-cubes-setup-hook) (run-hooks 'fg42-after-init-hook) (provide 'fg42-config)