Matt Price <mopto...@gmail.com> writes: > On Tue, Jul 14, 2015 at 7:27 AM, Eric Abrahamsen <e...@ericabrahamsen.net> > wrote: > > > Matt Price <mopto...@gmail.com> writes: > > > On Tue, Jul 14, 2015 at 6:51 AM, Eric Abrahamsen <e...@ericabrahamsen.net> > wrote: > > [...] > > I'll include a shameless-plug-cum-general-recommendation: I use > org-attach a lot to keep files associated with Org headings, and to me > this feels like a natural use-case for that. > > > Yes, it sounds like a pretty good idea. I am trying to figure out a couple of > attachment issues; to start with, I was hoping to set a dnd-handler, anmd > have drag-and-dropping local files create an > attachment. I am close, but the actual attachment isn't being created. This > is what I have: > > (setq dnd-protocol-alist > `(("^\\(file\\)://" . mwp-file-dnd) ,@dnd-protocol-alist)) > > (defun mwp-file-dnd (uri action) > (cond ((eq major-mode 'org-mode) > ;; (message uri) > (insert "[[%s][Description Property") > (org-attach-attach uri nil "lns" ) ;; this appears to work, but doesn't > create the link > ) > (t > (let ((dnd-protocol-alist > (rassq-delete-all > 'mwp-file-dnd > (copy-alist dnd-protocol-alist)))) > (dnd-handle-one-url nil action uri))) > ))
Unfortunately I've never used drag-and-drop anything, so won't really be able to help there. [...] > It sounds like you're digesting quite a bit all at once, so you probably > don't want to install all of Gnorb. If you're interested in some of the > bits, I might be able to peel those off into separate functions: > specifically, taking files from the org-attach directory and attaching > them to outgoing emails being sent from an Org heading. I can't promise > I could do it cleanly, but I'd be happy to look into it. > > > If you could do that, that would be just super. Right now my lone mailing > function sends me to message-mode: > > (defun mime-send-mail () > "org-mime-subtree and HTMLize" > (interactive) > (org-mark-subtree) > (let ((subject (nth 4 (org-heading-components)))) > (org-mime-subtree) > (insert "\nBest,\nMP.\n") > (org-mime-htmlize) > (command-execute 'mml-attach-file) > (message-goto-to) > ) > ) > > mml-attach-file asks a whole bunch of questions about mime type, etc. I don't > know how to fill those values in automatically, but I guess it would be, in > pseudo code > > (dolist (thisfile org-attach-all-attachments) (mml-attach-file thisfile FILL > IN OTHER ARGUMENTS) > > If you have something like that in gnorb that'd be awesome. Thanks once again, I've extracted some code that ought to be useful. (defun org-attachment-list (&optional id) "Get a list of files (absolute filenames) attached to the current heading, or the heading indicated by optional argument ID." (when (featurep 'org-attach) (let* ((attach-dir (save-excursion (when id (org-id-goto id)) (org-attach-dir t))) (files (mapcar (lambda (f) (expand-file-name f attach-dir)) (org-attach-file-list attach-dir)))) files))) (defun query-attach-files (files) (map-y-or-n-p (lambda (a) (format "Attach %s to outgoing message? " (file-name-nondirectory a))) (lambda (a) (mml-attach-file a (mm-default-file-encoding a) nil "attachment")) files '("file" "files" "attach"))) Then your entry point function could use those functions: (defun mime-send-mail () "org-mime-subtree and HTMLize" (interactive) (org-mark-subtree) (let ((subject (nth 4 (org-heading-components))) (files (org-attachment-list))) (org-mime-subtree) (insert "\nBest,\nMP.\n") (org-mime-htmlize) (query-attach-files files) (message-goto-to))) See how that works for now -- there will be plenty of adjustments you might want to make. One thing that occurred to me is, because `org-mime-subtree' uses the export process, you can use property substitution in the body of the subtree/email. So if you have a property like "GRADE" or something, you can insert that into the body at export time using {{{property(GRADE)}}}. You didn't really ask for that, but I'll bet it might come in handy. Eric