feat(emacs): targeting refile & hledger

This commit is contained in:
Pavel Korytov 2022-01-04 12:03:45 +03:00
parent 4617e07cfd
commit 941c1d44ee
3 changed files with 85 additions and 6 deletions

View file

@ -3,6 +3,7 @@
"the-silver-searcher"
"ripgrep"
"emacs-vterm"
"hledger"
"imagemagick"
"yt-dlp"
"mpv"

View file

@ -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 (<buffer> . <workspace-index>) 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 (<buffer> . <workspace-index>) 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 (<buffer> . <workspace-index>) 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 (<buffer> . <workspace-index>) 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))

View file

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