From 16c1832463ce93005f5b88942b2d0af6495d4b5a Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Thu, 2 May 2024 18:18:58 -0700 Subject: [PATCH] Cleanups for org-screenshot --- thoom-emacs/modules/thoom-org.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/thoom-emacs/modules/thoom-org.el b/thoom-emacs/modules/thoom-org.el index a260336..0101b6a 100644 --- a/thoom-emacs/modules/thoom-org.el +++ b/thoom-emacs/modules/thoom-org.el @@ -48,21 +48,22 @@ (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 (and (stringp in-file) (file-exists-p in-file)) - (progn + (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)) - (save-excursion - (org-next-visible-heading 1) - (org-open-line 1) - (org-insert-link nil out-file))) + (org-next-visible-heading 1) + (org-open-line 1) + (org-insert-link nil out-file)) (message "Failed to find saved screenshot."))))