From d0ee179dc96a9160975b84542cbee7fa07286a2d Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Thu, 2 May 2024 21:08:37 +0100 Subject: [PATCH] Extract organize into its own module and add org-roam --- nix/modules/default.nix | 1 + nix/modules/editor/default.nix | 7 -- nix/modules/editor/lisp/fg42/editor.el | 7 +- nix/modules/organize/default.nix | 85 +++++++++++++ .../lisp/fg42/organize.el | 113 +++++++++++++----- 5 files changed, 172 insertions(+), 41 deletions(-) create mode 100644 nix/modules/organize/default.nix rename nix/modules/{editor => organize}/lisp/fg42/organize.el (59%) diff --git a/nix/modules/default.nix b/nix/modules/default.nix index 73c910a..462ac6c 100644 --- a/nix/modules/default.nix +++ b/nix/modules/default.nix @@ -37,6 +37,7 @@ let ./verilog ./workspace ./rss + ./organize ]; in modules diff --git a/nix/modules/editor/default.nix b/nix/modules/editor/default.nix index 47f2b82..ee133fd 100644 --- a/nix/modules/editor/default.nix +++ b/nix/modules/editor/default.nix @@ -26,9 +26,6 @@ let deps = (with pkgs.emacsPackages; [ origami - #which-key - # projectile - #projectile-ripgrep pkg-info expand-region direnv @@ -40,11 +37,7 @@ let avy ace-window flycheck - org - org-super-agenda rainbow-delimiters - org-ql - org-modern base16-theme tempel tempel-collection diff --git a/nix/modules/editor/lisp/fg42/editor.el b/nix/modules/editor/lisp/fg42/editor.el index 2a0c302..65d2f1a 100644 --- a/nix/modules/editor/lisp/fg42/editor.el +++ b/nix/modules/editor/lisp/fg42/editor.el @@ -25,12 +25,12 @@ (require 'fpkg) ;; We build this file via the main FG42's Nix derivation. It ;; contains the final Nix configuration of FG42. - (require 'fg42/config) - (require 'fg42/organize)) + (require 'fg42/config)) (require 'server) (require 'fg42/utils) + (defun fg42/setup-font () "Set the default font of `FG42' to FONT-NAME and FONT-SIZE." (let ((name (config-get font-name)) @@ -289,8 +289,7 @@ short extension." (when (not (server-running-p)) (when-wm (setq server-name "fg42-wm")) - (server-start) - (require 'org-protocol)) + (server-start)) (when-wm ;; Activating the WM mode diff --git a/nix/modules/organize/default.nix b/nix/modules/organize/default.nix new file mode 100644 index 0000000..db680a6 --- /dev/null +++ b/nix/modules/organize/default.nix @@ -0,0 +1,85 @@ +# Fg42 - Emacs Editor for advance users +# +# Copyright (c) 2010-2024 Sameer Rahmani +# +# 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, version 2. +# +# 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 . + +# This is the home manager module that exposes FG42. It differs +# from FG42 modules that are structurally the same but used in +# different context + +# A list of default FG42 modules to build FG42 with. +{ lib, config, pkgs, makeFG42Drv, ... }: +with lib; +let + cfg = config.fg42.organize; + + deps = + (with pkgs.emacsPackages; [ + org + org-super-agenda + org-ql + org-modern + ] ++ optionals (cfg.org-roam) [ + org-roam + org-roam-ui + websocket + simple-httpd + f + ]); + + drv = makeFG42Drv { + pname = "organize"; + version = config.fg42.version; + buildInputs = deps; + src = ./.; + }; +in +{ + imports = [ + ../editor + ]; + + options.fg42.organize = { + enable = mkAndEnableOption "organize"; + org-roam = mkAndEnableOption "organize"; + org-dir = mkOption { + type = types.str; + default = "~/.orgs"; + example = literalExpression ''"~/.orgs"''; + description = mdDoc '' + A non-nix `path` (string `path`) of the location your want org-mode + to store you org files. + ''; + + }; + }; + + config = mkIf cfg.enable { + fg42.elispPackages = [ drv ] ++ deps; + + fg42.requires = [ drv.pname ]; + + fg42.vars = [ + (defVar "org-home" cfg.org-dir "Where to store org files.") + (defVar "org-roam" cfg.org-roam "Enable org-roam?") + ]; + + meta = { + maintainers = [ maintainers.lxsameer ]; + doc = ./README.md; + }; + + }; + +} diff --git a/nix/modules/editor/lisp/fg42/organize.el b/nix/modules/organize/lisp/fg42/organize.el similarity index 59% rename from nix/modules/editor/lisp/fg42/organize.el rename to nix/modules/organize/lisp/fg42/organize.el index 2981b0b..73a5ddf 100644 --- a/nix/modules/editor/lisp/fg42/organize.el +++ b/nix/modules/organize/lisp/fg42/organize.el @@ -22,28 +22,43 @@ ;;; Commentary: ;;; Code: (eval-when-compile - (require 'fpkg)) +(require 'fpkg) +(require 'fg42/utils) +(require 'fg42/config) +(require 'hydra)) - -(defvar fg42/org-super-agenda-groups nil) - -(defvar fg42/org-home "~/.orgs" +;;============================================================================= +;; Vars that user meant to set +;;============================================================================= +(defvar org-home "~/.orgs" "The location to the org file repository.") -(defvar fg42/default-org-journal-heder - " -#+TITLE: Yearly Journal -#+STARTUP: folded logdrawer logdone logreschedule indent content align constSI entitiespretty -" - "Org journal header.") - -(defvar fg42/notes-file "notes.org") +(defvar fg42/org-main-file "main.org") +(defvar fg42/org-notes-file "notes.org") +(defvar fg42/org-agenda-files "main.org") (defvar fg42/global-tags nil) -(defvar fg42/agenda-files "main.org") +;;============================================================================= +;; Helper functions +;;============================================================================= +(defun fg42/org-home () + "Return the directory path to store everthing org related." + (config-get-or "org-dir" org-home)) +(defun fg42/create-org-home () + "Create the org-files directory directory." + (make-directory (fg42/org-home) t)) + + +(defun fg42/organize-setup () + "Setup all the necessary files and directories to use `org' and `org-roam'." + (fg42/create-org-home)) + +;;============================================================================= +;; Package defs +;;============================================================================= (use! org-ql "This package provides a query language for Org files. It offers two syntax styles: Lisp-like sexps and search engine-like keywords. @@ -63,7 +78,6 @@ Now you can sort-of do this already with custom agenda commands, but when you do that, you lose the daily/weekly aspect of the agenda: items are no longer shown based on deadline/scheduled timestamps, but are shown no-matter-what. -h For more information checkout `https://github.com/alphapapa/org-super-agenda'" :after org-agenda :config @@ -72,8 +86,7 @@ For more information checkout `https://github.com/alphapapa/org-super-agenda'" org-agenda-include-deadlines t org-agenda-compact-blocks t org-agenda-start-day nil ;; Today - org-agenda-span 1 - org-super-agenda-groups fg42/org-super-agenda-groups) + org-agenda-span 1) (org-super-agenda-mode)) @@ -86,24 +99,27 @@ For more information checkout `https://github.com/alphapapa/org-super-agenda'" org-capture-templates (eval `(list - '("t" "Todo" entry (file+headline ,(expand-file-name "main.org" fg42/org-home) "New Tasks") - (file ,(expand-file-name "templates/todo" fg42/org-home)) + '("t" "Todo" entry (file+headline ,(expand-file-name fg42/org-main-file (fg42/org-home)) "New Tasks") + (file ,(expand-file-name "templates/todo" (fg42/org-home))) :prepend t) - '("l" "Link" entry (file+headline ,(expand-file-name "bookmarks.org" fg42/org-home) "Links") - (file ,(expand-file-name "templates/links" fg42/org-home)) + '("l" "Link" entry (file+headline ,(expand-file-name "bookmarks.org" (fg42/org-home)) "Links") + (file ,(expand-file-name "templates/links" (fg42/org-home))) :prepend t :immediate-finish t :empty-lines 1) - '("h" "Thoughts" entry (file+datetree ,(expand-file-name "journal.org" fg42/org-home)) - (file ,(expand-file-name "templates/thoughts" fg42/org-home))))))) + '("h" "Thoughts" entry (file+datetree ,(expand-file-name "journal.org" (fg42/org-home))) + (file ,(expand-file-name "templates/thoughts" (fg42/org-home)))))))) (use! org-protocol "`org-protocol' intercepts calls from emacsclient to trigger custom actions without external dependencies. Only one protocol has to be configured with your external applications or the operating system, to trigger an arbitrary number of custom actions. Just register -your custom sub-protocol and handler with the variable `org-protocol-protocol-alist'.") +your custom sub-protocol and handler with the variable `org-protocol-protocol-alist'." + :init + (require 'org-protocol)) + (use! org "A GNU Emacs major mode for keeping notes, authoring documents, computational notebooks, @@ -111,7 +127,9 @@ literate programming, maintaining to-do lists, planning projects, and more — i and effective plain text system. For more info on ~org-mode~ check out `https://orgmode.org/'" - :hook (org-mod . flyspell-mode) + :hook + (org-mod . flyspell-mode) + (org-mode . fg42/organize-setup) :init (setq org-auto-align-tags nil @@ -133,12 +151,12 @@ For more info on ~org-mode~ check out `https://orgmode.org/'" " ┄┄┄┄┄ " "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄") org-agenda-current-time-string "<── now ─────────────────────────────────────────────────" - org-agenda-files (concat (file-name-as-directory fg42/org-home) - fg42/agenda-files) + org-agenda-files (concat (file-name-as-directory (fg42/org-home)) + fg42/org-agenda-files) - org-directory fg42/org-home - org-default-notes-file (concat (file-name-as-directory fg42/org-home) - fg42/notes-file) + org-directory (fg42/org-home) + org-default-notes-file (concat (file-name-as-directory (fg42/org-home)) + fg42/org-notes-file) org-refile-targets '((org-agenda-files :maxlevel . 3)) @@ -154,5 +172,40 @@ For more info on ~org-mode~ check out `https://orgmode.org/'" (org-agenda-finalize . org-modern-mode))) +(with-config "org-roam" + (use! org-roam + "Create a second brain for yourself with this great knowledge base tool." + :after org + :commands (org-roam-node-find org-roam-node-insert + org-roam-capture org-roam-ui-mode) + :config + (setq-default org-roam-directory (file-truename (path-join (fg42/org-home) "roam")) + org-roam-db-update-on-save t) + (make-directory org-roam-directory t) + (org-roam-db-autosync-mode)) + + (use! websocket + "Websocket support for Elisp." + :after org-roam) + + (use! org-roam-ui + "A nice web UI for `org-roam'" + :after org-roam + :config + (setq org-roam-ui-sync-theme t + org-roam-ui-follow t + org-roam-ui-update-on-save t + org-roam-ui-open-on-start t)) + + (defhydra hydra-org-roam (:exit t) + "Org Roam" + ("i" org-roam-node-insert "Insert") + ("f" org-roam-node-find "Find") + ("c" org-roam-capture "Capture") + ("u" org-roam-ui-mode "Web UI")) + + (global-set-key (kbd "C-c o") 'hydra-org-roam/body)) + + (provide 'fg42/organize) ;;; organize.el ends here