From 941c1d44ee5527bd5a037993c6f7c0ee939d53ad Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Tue, 4 Jan 2022 12:03:45 +0300 Subject: [PATCH] feat(emacs): targeting refile & hledger --- .config/guix/manifests/emacs.scm | 1 + .emacs.d/init.el | 39 ++++++++++++++++++++++-- Emacs.org | 51 ++++++++++++++++++++++++++++++-- 3 files changed, 85 insertions(+), 6 deletions(-) diff --git a/.config/guix/manifests/emacs.scm b/.config/guix/manifests/emacs.scm index 5a29131..517614d 100644 --- a/.config/guix/manifests/emacs.scm +++ b/.config/guix/manifests/emacs.scm @@ -3,6 +3,7 @@ "the-silver-searcher" "ripgrep" "emacs-vterm" + "hledger" "imagemagick" "yt-dlp" "mpv" diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 4665a40..b44831a 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -850,6 +850,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." :background ,(doom-color 'bg) :foreground ,(doom-color 'yellow) :underline ,(doom-color 'yellow))))) + `(tab-bar ((t (:background nil :foreground nil)))) `(org-block ((t (:background ,(color-darken-name (doom-color 'bg) 3))))) `(org-block-begin-line ((t ( :background ,(color-darken-name (doom-color 'bg) 3) @@ -2647,8 +2648,7 @@ Returns ( . ) or nil." "c" 'org-capture "a" 'org-agenda) -(setq org-refile-targets - '()) +(setq org-refile-targets '()) (setq org-refile-use-outline-path 'file) (setq org-outline-path-complete-in-steps nil) @@ -2900,7 +2900,9 @@ Returns ( . ) or nil." ,@project-files))) (dolist (file project-files) (add-to-list 'org-refile-targets - `(,file :maxlevel . 2))))) + `(,file :tag . "refile")) + (add-to-list 'org-refile-targets + `(,file :regexp . ,(rx (or "Tasks"))))))) (with-eval-after-load 'org-roam (my/org-roam-refresh-agenda-list)) @@ -2914,6 +2916,23 @@ Returns ( . ) or nil." :templates `(,my/org-roam-project-template))) +(defun my/org-target-refile (&optional arg) + (interactive "P") + (let* ((selected-file + (completing-read + "Refile to: " + (seq-uniq (mapcar #'car org-refile-targets)))) + (org-refile-targets + (cl-loop for target in org-refile-targets + if (string-equal (car target) selected-file) + collect target))) + (org-refile-cache-clear) + (org-refile arg))) + +(general-define-key + :keymaps 'org-mode-map + "C-c C-w" #'my/org-target-refile) + (defun my/org-roam-daily-extract-target-links () (save-excursion (goto-char (point-min)) @@ -4482,6 +4501,20 @@ Returns ( . ) or nil." (add-hook 'pomm-on-tick-hook 'pomm-update-mode-line-string) (add-hook 'pomm-on-status-changed-hook 'pomm-update-mode-line-string)) +(use-package hledger-mode + :straight t + :mode (rx ".journal" eos) + :config + (setq hledger-jfile (concat org-directory "/ledger/ledger.journal")) + (add-hook 'hledger-mode-hook + (lambda () + (make-local-variable 'company-backends) + (add-to-list 'company-backends 'hledger-company)))) + +(use-package flycheck-hledger + :straight t + :after (hledger-mode)) + (setq calendar-date-style 'iso) ;; YYYY/mm/dd (setq calendar-week-start-day 1) (setq calendar-time-display-form '(24-hours ":" minutes)) diff --git a/Emacs.org b/Emacs.org index c3c4520..830f063 100644 --- a/Emacs.org +++ b/Emacs.org @@ -1674,6 +1674,7 @@ Also, a hook allows me to change doom-theme more or less at will, although I do :background ,(doom-color 'bg) :foreground ,(doom-color 'yellow) :underline ,(doom-color 'yellow))))) + `(tab-bar ((t (:background nil :foreground nil)))) `(org-block ((t (:background ,(color-darken-name (doom-color 'bg) 3))))) `(org-block-begin-line ((t ( :background ,(color-darken-name (doom-color 'bg) 3) @@ -3869,8 +3870,7 @@ Hotkeys Refile targets #+begin_src emacs-lisp -(setq org-refile-targets - '()) +(setq org-refile-targets '()) (setq org-refile-use-outline-path 'file) (setq org-outline-path-complete-in-steps nil) #+end_src @@ -4216,7 +4216,9 @@ Now, let's integrate the found project notes to the rest of Org Mode. Besides =o ,@project-files))) (dolist (file project-files) (add-to-list 'org-refile-targets - `(,file :maxlevel . 2))))) + `(,file :tag . "refile")) + (add-to-list 'org-refile-targets + `(,file :regexp . ,(rx (or "Tasks"))))))) (with-eval-after-load 'org-roam (my/org-roam-refresh-agenda-list)) @@ -4236,6 +4238,27 @@ Find or capture a project. :templates `(,my/org-roam-project-template))) #+end_src +***** Targeting refile +Because in the previous section I've added a lot of stuff to the =org-refile-targets=, the list given by =org-refile= becomes a bit too large. So let's make a function that performs a sort of two-step refile: + +#+begin_src emacs-lisp +(defun my/org-target-refile (&optional arg) + (interactive "P") + (let* ((selected-file + (completing-read + "Refile to: " + (seq-uniq (mapcar #'car org-refile-targets)))) + (org-refile-targets + (cl-loop for target in org-refile-targets + if (string-equal (car target) selected-file) + collect target))) + (org-refile-cache-clear) + (org-refile arg))) + +(general-define-key + :keymaps 'org-mode-map + "C-c C-w" #'my/org-target-refile) +#+end_src **** Automatic transclusion for Dailies I've been using org-journal for quite some time, and while it's great, I don't like its linear structure too much. I have all kinds of stuff written there - things related to my job, various personal projects, etc, and it's pretty hard to query a specific thing. @@ -6516,6 +6539,28 @@ My package for doing Pomodoro timer. (add-hook 'pomm-on-tick-hook 'pomm-update-mode-line-string) (add-hook 'pomm-on-status-changed-hook 'pomm-update-mode-line-string)) #+end_src +*** hledger +Trying out hledger. + +| Guix dependency | +|-----------------| +| hledger | + +#+begin_src emacs-lisp +(use-package hledger-mode + :straight t + :mode (rx ".journal" eos) + :config + (setq hledger-jfile (concat org-directory "/ledger/ledger.journal")) + (add-hook 'hledger-mode-hook + (lambda () + (make-local-variable 'company-backends) + (add-to-list 'company-backends 'hledger-company)))) + +(use-package flycheck-hledger + :straight t + :after (hledger-mode)) +#+end_src *** Calendar Emacs' built-in calendar. Can even calculate sunrise and sunset times.