Files
dotfiles/thoom-emacs/modules/thoom-org.el
2024-07-19 00:04:59 -07:00

71 lines
2.7 KiB
EmacsLisp

(provide 'thoom-org)
(use-package org
:bind (("C-c o ," . thoom/org-clear-all)
("C-c o s" . org-screenshot)
("C-c SPC" . org-table-blank-field)
;; Unbind to make room for avy
:map org-mode-map
("C-j" . nil))
:hook ((org-mode . visual-line-mode))
:custom
(org-todo-keywords '((sequence "TODO(t)" "BLOCKED(b)" "|" "DONE(d)")))
(org-image-actual-width '(800)))
(use-package org-bullets
:ensure t
:config
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
;; Eagerly load org-mode
(with-temp-buffer (org-mode))
(defun thoom/org-clear-all ()
(interactive)
(goto-char 0)
(org-map-entries
(lambda ()
(org-todo "")))
;;(flush-lines "CLOSED")
(message "Entries cleared."))
;; Steps to set up:
;; 1. Install ShareX, add ShareX folder to PATH
;; 2. Create hotkey named GameNotes with settings:
;; Capture preconfigured window
;; Capture -> Pre configured window title: <game name>
;; Override after capture tasks to "Save image to file"
;; Override screenshots folder to org-screenshot-import-path
;; Override Upload settings -> File naming -> Name pattern
;; "GameNotes_%t_%y-%mo-%d-%h-%mi-%s.%ms"
;; 3. Put the following at the top of the org file:
;; #+STARTUP: inlineimages
;; #+ATTR_HTML: :width 500px
(defvar org-screenshot-import-path "/mnt/c/Users/thoom/Seafile/Games/Screenshots/")
(defvar org-screenshot-export-path org-screenshot-import-path)
(defvar org-screenshot-exec-path "ShareX.exe")
(defvar org-screenshot-exec-args "-s -workflow GameNotes")
(defun org-screenshot ()
(interactive)
(let* ((heading-name (org-get-heading t t t t))
;; Strip out the font information from the heading name
(_ (set-text-properties 0 (length heading-name) nil heading-name))
(_ (shell-command (concat org-screenshot-exec-path " " org-screenshot-exec-args)))
;; shell-command returns immediately, so wait until the screenshot is likely to have been taken
(_ (sit-for 0.25))
(in-file (car (nreverse (directory-files org-screenshot-import-path 'full "GameNotes.*.png"))))
(out-dir-name (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
(out-dir (file-name-as-directory (concat (file-name-as-directory org-screenshot-export-path) out-dir-name)))
(out-file (concat out-dir heading-name "-" (org-id-uuid) ".png")))
(if (stringp in-file)
(save-excursion
(unless (file-exists-p out-dir)
(make-directory out-dir))
(rename-file in-file out-file)
(message (format "Saved %S to %S" in-file out-file))
(org-next-visible-heading 1)
(org-open-line 1)
(org-insert-link nil out-file))
(message "Failed to find saved screenshot."))))