emacs-config/helpers.org
2023-04-29 14:12:50 -05:00

2.8 KiB

Separate tasks

  (use-package doct)
  (require 'org)

  (defvar my/custom-task-templates
    (doct `(("convert [p]aycheck"
             :keys "p"
             :file ,(my/agenda-file "puppet.org")
             :template-file ,(my/org-file "templates/puppet/paycheck.org")))))

  (defun my/run-custom-tasks ()
    (interactive)
    (let ((org-capture-templates my/custom-task-templates))
      (call-interactively #'org-capture)))

  (when my/puppet-p
    (global-set-key (kbd "<f1>") #'my/run-custom-tasks))

Some Extra Bindings

  (when my/puppet-p
    (global-set-key (kbd "<f2>")
                    #'org-roam-node-find)
    (global-set-key (kbd "<f3>")
                    #'(lambda ()
                        (interactive)
                        (find-file (my/plaintext-file "org/random/things_puppet_should_remember.org")))))

Add Ledger

  (defun paycheck->ledger (file)
    (interactive
     (list (read-file-name "Paycheck file? ")))
    (unless (string= "ledger.ledger"
                     (file-name-nondirectory
                      (buffer-file-name (current-buffer))))
      (user-error "You're in the wrong file..."))

    (unless (string= "pdf" (file-name-extension file))
      (user-error "Oops, that's not a pdf file..."))

    (let* ((buf (get-buffer-create "*output*"))
           (res
            (save-window-excursion
              (shell-command (format "ledger-convert.el '%s'" file)
                             buf nil))))
      (unless (eq res 0)
        (user-error "Something went wrong with that file... Maybe ask Lambda?"))

      (let ((str (with-current-buffer buf (buffer-string))))
        (goto-char (point-max))
        (insert "\n" str))))

Sending reports to mom

  (defun my/run-report-get-file-name (arg)
    (let* ((default-directory (my/plaintext-file "ledger-finance"))
           (buf
            (save-window-excursion
              (compilation-start (format "./mom_report.sh %s"
                                         (if arg "end" "mid"))
                                 nil (lambda (_) "*ledger-report*")))))
      (save-window-excursion
        (display-buffer-same-window buf nil)
        (when (not (y-or-n-p "Looks good? "))
          (user-error "Fix up ledger.ledger and try again")))
      (let ((str (with-current-buffer buf
                   (buffer-string))))
        (string-match (rx line-start "Filename: " (group (+ nonl))) str)
        (match-string 1 str))))

  (defun my/run-ledger-report (arg)
    (interactive "P")
    (let ((fname (my/run-report-get-file-name arg)))
      (notmuch-mua-mail "benedi.chu@hotmail.com" (if arg "Rent" "Finance Report")
                        '((From . "bensonchu457@fastmail.com")))
      (mml-attach-file fname)))