diff options
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-org.el')
| -rw-r--r-- | emacs/.emacs.d/lisp/my/my-org.el | 56 | 
1 files changed, 44 insertions, 12 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-org.el b/emacs/.emacs.d/lisp/my/my-org.el index b189b78..00a8a0f 100644 --- a/emacs/.emacs.d/lisp/my/my-org.el +++ b/emacs/.emacs.d/lisp/my/my-org.el @@ -822,22 +822,54 @@ When BLOCK-REGEXP is non-nil, use this regexp to find blocks."             my-org-attach-copy-attached-doc-exts "\\|")))  (defun my-org-attach-copy-attached-docs () +  "Copy docs to a mount point. + +Use `my-org-attach-copy-attached-targets', which is an list +of (name to-dir staging). Try copying to to-dir. + +On failure, hard link to staging. +On success, also move everything from staging to to-dir."    (interactive) -  (let* ((name -          (completing-read "Copy attached docs to: " -                           my-org-attach-copy-attached-targets)) -         (path (alist-get name my-org-attach-copy-attached-targets -                          nil nil #'equal))) -    (let ((basedir (org-attach-dir))) +  (pcase-let* ((name +                (completing-read "Copy attached docs to: " +                                 my-org-attach-copy-attached-targets +                                 nil t)) +               (`(,to ,staging) (alist-get name my-org-attach-copy-attached-targets +                                           nil nil #'equal))) +    (let ((basedir (org-attach-dir)) +          (failed nil))        (dolist (attached (org-attach-file-list basedir))          (when (string-match my-org-attach-copy-attached-doc-re attached) -	        (message "Copying %s to %s (%s)..." attached name path) -	        (copy-file (file-name-concat basedir attached) +	        (message "Copying %s to %s (%s)..." attached name to) +          (condition-case nil +	            (copy-file (file-name-concat basedir attached) +		                     (file-name-concat +                          to +			                    (replace-regexp-in-string ":" "_" attached)) +                         t) +            (error +             (message "Hardlinking %s to %s staging area (%s)" +                      attached name staging) +             (setq failed t) +             (add-name-to-file +              (file-name-concat basedir attached) +              (file-name-concat +               staging +			         (replace-regexp-in-string ":" "_" attached)) +              t))) +	        (message "Done!"))) +      (unless failed +        (dolist (staged +                 (directory-files staging nil +                                  my-org-attach-copy-attached-doc-re)) +          (message "Moving staged %s to %s (%s)..." staged name to) +          (copy-file (file-name-concat staging staged)  		                 (file-name-concat -                      path -			                (replace-regexp-in-string ":" "_" attached))) -	        (message "Done!"))))) -  ) +                      to +			                (replace-regexp-in-string ":" "_" staged)) +                     t) +          (delete-file (file-name-concat staging staged)) +          (message "Done!"))))))  (defun my-org-attach-all-url-plaintext (arg)    (interactive "P")  | 
