Created
January 3, 2026 22:27
-
-
Save vherrmann/98bce5ef54243df1c5057ea2d256be84 to your computer and use it in GitHub Desktop.
Editing org-attach attachments at point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (cl-defun iko/run-process-async (name program &key stdin args on-exit) | |
| "Run PROGRAM asynchronously with ARGS, outputting to BUFFER-NAME." | |
| (with-current-buffer (get-buffer-create (concat "*" name "*")) | |
| (let ((b (current-buffer)) | |
| (p (apply #'start-process name (current-buffer) program args))) | |
| (set-process-sentinel | |
| p | |
| (lambda (proc event) | |
| (when (eq (process-status proc) 'exit) | |
| (when on-exit | |
| (funcall on-exit | |
| (process-exit-status proc) | |
| (with-current-buffer b (buffer-string)) | |
| proc | |
| event)) | |
| (kill-buffer b)))) | |
| (when stdin | |
| (process-send-string p (if (string-suffix-p "\n" stdin) | |
| stdin | |
| (concat stdin "\n"))) | |
| (process-send-eof p)) | |
| p))) | |
| (defun iko/org-attach-get-absolute-path-at-point () | |
| (let* ((ctx (org-element-context))) | |
| (if (and (eq (org-element-type ctx) 'link) | |
| (string= (org-element-property :type ctx) "attachment")) | |
| (let* ((raw (org-element-property :raw-link ctx)) | |
| (file (string-remove-prefix "attachment:" raw)) | |
| (abs (org-attach-expand file))) | |
| (message "%s" abs) | |
| abs) | |
| (user-error "Not on an attachment link.")))) | |
| (defun iko/edit-attachment-at-point () | |
| (interactive) | |
| (let ((file (iko/org-attach-get-absolute-path-at-point))) | |
| (iko/run-process-async "ksnip" "ksnip" | |
| :args `(,file) | |
| :on-exit | |
| (lambda (status-code _output _proc _event) | |
| (if (= status-code 0) | |
| (progn | |
| (org-redisplay-inline-images) | |
| (message "Successfully edited %s" file)) | |
| (user-error "ksnip failed with code %s" status-code)))))) |
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Today I added the following config and in particular
iko/edit-attachment-at-pointto my config to easily edit inline images withksnip.You can use it by calling
iko/edit-attachment-at-pointwhile having the point on anattachment:link. Thenksnipis opened and you can edit your image. To end theksnipprocess on closing theksnipwindow you probably want to disable the tray in the settings, unless you already haveksniprunning in the tray.