
* org.el (org-set-tags-to): New command. * org-latex.el (org-export-latex-set-initial-vars): Also check in the plist. * org.el (org-additional-option-like-keywords): Add LATEX_CLASS keyword. * org-exp.el (org-infile-export-plist): Add LATEX_CLASS keyword. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-inlinetask.el (org-inlinetask-export): Option removed. (org-inlinetask-export-handler): Better export. * org-xoxo.el (org-export-xoxo-final-hook): New hook. (org-export-as-xoxo): Run the new hook. * org-html.el (org-export-html-final-hook): New hook. (org-export-as-html): Run the new hook. * org-docbook.el (org-export-docbook-final-hook): New hook. (org-export-as-docbook): Run the new hook. * org-ascii.el (org-export-ascii-final-hook): New hook. (org-export-as-ascii): Run the new hook. * org-latex.el (org-export-latex-treat-sub-super-char): Allow a space character as the character before the ^/_. (org-export-latex-final-hook): New hook. (org-export-as-latex): Run `org-export-latex-final-hook'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-macs.el (org-if-unprotected-at): Fix docstring. * org-agenda.el (org-agenda-change-all-lines): Handle invisible text in the prefix (if category is a link). * org-latex.el (org-export-latex-preprocess): Deal properly with empty lines in verse environments. * org.el (org-format-latex-header): Inline fullpage.sty. * org-footnote.el (org-footnote-create-definition): Reveal context to add a new footnote definition. * org.el (org-ctrl-c-ctrl-c): Pass prefix arg to org-table-recalculate when cursor is in TBLFM line. * org-list.el (org-renumber-ordered-list): Fix cursor position when bullet length has changed. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-format-latex): Mention `org-format-latex-options' in the docstring. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-agenda-get): New function. * org-agenda.el (org-agenda-post-command-hook): No longer move point away from end of line. (org-agenda-add-entry-text, org-agenda-collect-markers) (org-finalize-agenda, org-agenda-mark-clocking-task) (org-agenda-dim-blocked-tasks, org-agenda-entry-text-show-here) (org-agenda-entry-text-show, org-agenda-highlight-todo) (org-agenda-compare-effort, org-agenda-filter-apply) (org-agenda-later, org-agenda-change-time-span) (org-agenda-post-command-hook, org-agenda-show-priority) (org-agenda-show-tags, org-agenda-goto, org-agenda-kill) (org-agenda-archive, org-agenda-archive-to-archive-sibling) (org-remove-subtree-entries-from-agenda, org-agenda-refile) (org-agenda-open-link, org-agenda-copy-local-variable) (org-agenda-switch-to, org-agenda-check-no-diary) (org-agenda-tree-to-indirect-buffer, org-agenda-todo) (org-agenda-add-note, org-agenda-change-all-lines) (org-agenda-priority, org-agenda-set-tags) (org-agenda-set-property, org-agenda-set-effort) (org-agenda-toggle-archive-tag, org-agenda-date-later) (org-agenda-show-new-time, org-agenda-date-prompt) (org-agenda-schedule, org-agenda-deadline, org-agenda-action) (org-agenda-clock-in, org-agenda-bulk-mark) (org-agenda-bulk-unmark, org-agenda-show-the-flagging-note): Use `org-get-at-bol'. * org-colview.el (org-columns-display-here) (org-columns-edit-allowed, org-agenda-columns): Use `org-get-at-bol'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-special-ctrl-a/e): Improve documentation and customize type. (org-end-of-line): Don't jump to after the ellipsis. (org-mode-map): Bind <home> and <end> as well. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-fontify-meta-lines-and-blocks): Treat lines with a space after #+ as comments. (org-open-at-point): Run `org-follow-link-hook' always. * org-latex.el (org-export-latex-emph-format): Use better commands to insert special characters in verbatim snippets. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-faces.el (org-copy-face): New function. Use it to create various faces formerly created by using `copy-face'. * org-agenda.el (org-prepare-agenda): Don't officially mark this window dedicated. (org-agenda-quit): Kill the frame containing the agenda window if that frame was created for the agenda. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-date-prompt): Mark the changed time stamp in the agenda. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-prepare-agenda): Reset `org-drawers-for-agenda'. (org-prepare-agenda): Uniquify list of drawers. * org.el (org-complex-heading-regexp-format): New variable. (org-set-regexps-and-options): Define `org-complex-heading-regexp-format'. (org-drawers-for-agenda): New variable. (org-map-entries): Bind `org-drawers-for-agenda'. (org-prepare-agenda-buffers): Add to `org-drawers-for-agenda'. * org-remember.el (org-go-to-remember-target) (org-remember-handler): Use `org-complex-heading-regexp-format'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-highlight-todo): Fix text property problem. * org.el (org-on-heading-p, org-at-heading-p): Make sure these are always with `invisible-ok'. (org-store-link): No error when there is nothing to link to in the agenda. * org-list.el (org-update-checkbox-count): Insert changed cookie before the old, to avoid problems with invisibility at the end of the line. (org-update-checkbox-count): Insert changed cookie before the old, to avoid problems with invisibility at the end of the line. * org.el (org-sort-entries-or-items): Include the final newline. (org-fontify-meta-lines-and-blocks): Add indented dynamic block lines for fontification. (org-dblock-start-re, org-dblock-end-re): Allow indentation. (org-prepare-dblock): Store the current indentation of the BEGIN line. (org-update-dblock): Apply the indentation of the begin line to the rest of the block. (org-ctrl-c-ctrl-c): Also find indented dblock lines. (org-startup-folded): New allowed value `showeverything'. (org-startup-options): Add STARTUP keyword `showeverything'. (org-set-startup-visibility): Respect value `showeverything' in org-startup-folded. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-closest-date): Fix issue with past preference. * org-archive.el (org-archive-set-tag) (org-archive-subtree-default): New commands. * org-clock.el (org-clock-clocktable-default-properties): New option. (org-clock-report): Use `org-clock-clocktable-default-properties'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-iswitchb-completing-read): Fix typo. * org-crypt.el: New file. * org.el: Add an entry for org-crypt. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-menu): Reorganize the menu for more consistency. (org-batch-store-agenda-views): New function. (org-agenda-title-append): Define variable. (org-write-agenda): New export to Org files. (org-agenda-get-some-entry-text): New arguments INDENT and KEEP. (org-agenda): Allow to keep the restricted file list if a special variable is bound to t. (org-agenda): Define a special agenda view for working on flagged entries. (org-agenda-get-restriction-and-command): List the new agenda view. (org-agenda-show-the-flagging-note): New command. (org-agenda-mode-map): New key `?' for looking at the flagging note. * org.el (org-autoload): Autoload org-mobile.el. (org-org-menu): Add menu commands for MobileOrg in the Org menu. * org-mobile.el: New file. * org-id.el (org-id-get): Fix bug with forcing ID on an item. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-table.el (orgtbl-line-start-regexp): Match also TBLNAME statements. (org-table-get-remote-range): Match indented #+TBLNAME statements. * org.el (org-convert-to-odd-levels) (org-convert-to-oddeven-levels): Work also correctly if the file is in outline-mode. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-store-link): When in agenda buffer, link to referenced entry. (org-add-planning-info): Remove spaces at eol. * org-macs.el (org-with-point-at): Add a `lisp-indent-function' property. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-first-lines): Fix problem with LaTeX export of first line and selected subtree. * org.el (org-shifttab): Interpret arg differently when using only odd levels. 2009-10-01 Bastien Guerry <bzg@altern.org> * org.el (org-check-agenda-file): Use a more explicit message 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-remove-special-table-lines): Don't remove normal lines. 2009-10-01 Bastien Guerry <bzg@altern.org> * org.el (org-offer-links-in-entry): Don't use "Select link" as a prompt in the temporary window. * org-agenda.el (org-agenda-bulk-mark): Use a slightly soberer prefix for marked entries in the agenda view. 2009-10-01 Andreas Burtzlaff <andy13@gmx.net> (tiny change) * org.el (outline-end-of-subtree): Bugfix: advise this function in a way that prevents any trailing character from being displayed. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-menu): Fix bugs in the bulk action menu. * org-exp.el (org-export-remove-special-table-lines): Remove bad slow regexp match. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-preprocess): Do not protect in the LaTeX header. * org-src.el (org-edit-src-save): Save window setup while saving. (org-edit-src-code): Use new buffer name construction scheme. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-entry-text-exclude-regexps): New variable. (org-agenda-entry-text-cleanup-hook): New hook. (org-agenda-get-some-entry-text): Remove matches of `org-agenda-entry-text-exclude-regexps' and run the hook `org-agenda-entry-text-cleanup-hook'. * org.el (org-offer-links-in-entry): New argument ZERO to implement a link with index zero. (org-cycle-show-empty-lines): Not keep empty line under header hidden. (org-iswitchb-completing-read): Bind `switchb-use-virtual-buffers' to nil for special completion. (org-store-link): Don't error before the first heading. * org-agenda.el (org-agenda-open-link): Pass the prefix to `org-offer-links-in-entry'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-quit): Provide the window argument for `window-dedicated-p', Emacs 22 needs it. (org-format-agenda-item): If the category is a link, arrange for invisible text to replaced with spaces. (org-compile-prefix-format): Add the extra space. (org-prefix-category-length): New variable. * org-exp.el (org-export-cleanup-toc-line): Remove footnote references from TOC lines. * org.el (org-selected-window): New variable. * org-table.el (org-table-edit-formulas): Remember the selected window. (org-table-fedit-finish, org-table-fedit-abort): Select the window that was originally selected. * org-exp.el (org-export-preprocess-apply-macros): Scan the expansion of a macro for more macro definitions. * org-agenda.el (org-agenda-dim-blocked-tasks): Make sure the invisibility overlay starts on the newline.
416 lines
16 KiB
EmacsLisp
416 lines
16 KiB
EmacsLisp
;;; org-attach.el --- Manage file attachments to org-mode tasks
|
|
|
|
;; Copyright (C) 2008, 2009 Free Software Foundation, Inc.
|
|
|
|
;; Author: John Wiegley <johnw@newartisans.com>
|
|
;; Keywords: org data task
|
|
;; Version: 6.31a
|
|
|
|
;; This file is part of GNU Emacs.
|
|
;;
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; See the Org-mode manual for information on how to use it.
|
|
;;
|
|
;; Attachments are managed in a special directory called "data", which
|
|
;; lives in the same directory as the org file itself. If this data
|
|
;; directory is initialized as a Git repository, then org-attach will
|
|
;; automatically commit changes when it sees them.
|
|
;;
|
|
;; Attachment directories are identified using a UUID generated for the
|
|
;; task which has the attachments. These are added as property to the
|
|
;; task when necessary, and should not be deleted or changed by the
|
|
;; user, ever. UUIDs are generated by a mechanism defined in the variable
|
|
;; `org-id-method'.
|
|
|
|
;;; Code:
|
|
|
|
(eval-when-compile
|
|
(require 'cl))
|
|
(require 'org-id)
|
|
(require 'org)
|
|
|
|
(defgroup org-attach nil
|
|
"Options concerning entry attachments in Org-mode."
|
|
:tag "Org Attach"
|
|
:group 'org)
|
|
|
|
(defcustom org-attach-directory "data/"
|
|
"The directory where attachments are stored.
|
|
If this is a relative path, it will be interpreted relative to the directory
|
|
where the Org file lives."
|
|
:group 'org-attach
|
|
:type 'directory)
|
|
|
|
(defcustom org-attach-auto-tag "ATTACH"
|
|
"Tag that will be triggered automatically when an entry has an attachment."
|
|
:group 'org-attach
|
|
:type '(choice
|
|
(const :tag "None" nil)
|
|
(string :tag "Tag")))
|
|
|
|
(defcustom org-attach-file-list-property "Attachments"
|
|
"The property used to keep a list of attachment belonging to this entry.
|
|
This is not really needed, so you may set this to nil if you don't want it.
|
|
Also, for entries where children inherit the directory, the list of
|
|
attachments is not kept in this property."
|
|
:group 'org-attach
|
|
:type '(choice
|
|
(const :tag "None" nil)
|
|
(string :tag "Tag")))
|
|
|
|
(defcustom org-attach-method 'cp
|
|
"The preferred method to attach a file.
|
|
Allowed values are:
|
|
|
|
mv rename the file to move it into the attachment directory
|
|
cp copy the file
|
|
ln create a hard link. Note that this is not supported
|
|
on all systems, and then the result is not defined."
|
|
:group 'org-attach
|
|
:type '(choice
|
|
(const :tag "Copy" cp)
|
|
(const :tag "Move/Rename" mv)
|
|
(const :tag "Link" ln)))
|
|
|
|
(defcustom org-attach-expert nil
|
|
"Non-nil means do not show the splash buffer with the attach dispatcher."
|
|
:group 'org-attach
|
|
:type 'boolean)
|
|
|
|
(defcustom org-attach-allow-inheritance t
|
|
"Non-nil means, allow attachment directories be inherited."
|
|
:group 'org-attach
|
|
:type 'boolean)
|
|
|
|
|
|
(defvar org-attach-inherited nil
|
|
"Indicates if the last access to the attachment directory was inherited.")
|
|
|
|
;;;###autoload
|
|
(defun org-attach ()
|
|
"The dispatcher for attachment commands.
|
|
Shows a list of commands and prompts for another key to execute a command."
|
|
(interactive)
|
|
(let (c marker)
|
|
(when (eq major-mode 'org-agenda-mode)
|
|
(setq marker (or (get-text-property (point) 'org-hd-marker)
|
|
(get-text-property (point) 'org-marker)))
|
|
(unless marker
|
|
(error "No task in current line")))
|
|
(save-excursion
|
|
(when marker
|
|
(set-buffer (marker-buffer marker))
|
|
(goto-char marker))
|
|
(org-back-to-heading t)
|
|
(save-excursion
|
|
(save-window-excursion
|
|
(unless org-attach-expert
|
|
(with-output-to-temp-buffer "*Org Attach*"
|
|
(princ "Select an Attachment Command:
|
|
|
|
a Select a file and attach it to the task, using `org-attach-method'.
|
|
c/m/l Attach a file using copy/move/link method.
|
|
n Create a new attachment, as an Emacs buffer.
|
|
z Synchronize the current task with its attachment
|
|
directory, in case you added attachments yourself.
|
|
|
|
o Open current task's attachments.
|
|
O Like \"o\", but force opening in Emacs.
|
|
f Open current task's attachment directory.
|
|
F Like \"f\", but force using dired in Emacs.
|
|
|
|
d Delete one attachment, you will be prompted for a file name.
|
|
D Delete all of a task's attachments. A safer way is
|
|
to open the directory in dired and delete from there.
|
|
|
|
s Set a specific attachment directory for this entry.
|
|
i Make children of the current entry inherit its attachment directory.")))
|
|
(org-fit-window-to-buffer (get-buffer-window "*Org Attach*"))
|
|
(message "Select command: [acmlzoOfFdD]")
|
|
(setq c (read-char-exclusive))
|
|
(and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*"))))
|
|
(cond
|
|
((memq c '(?a ?\C-a)) (call-interactively 'org-attach-attach))
|
|
((memq c '(?c ?\C-c))
|
|
(let ((org-attach-method 'cp)) (call-interactively 'org-attach-attach)))
|
|
((memq c '(?m ?\C-m))
|
|
(let ((org-attach-method 'mv)) (call-interactively 'org-attach-attach)))
|
|
((memq c '(?l ?\C-l))
|
|
(let ((org-attach-method 'ln)) (call-interactively 'org-attach-attach)))
|
|
((memq c '(?n ?\C-n)) (call-interactively 'org-attach-new))
|
|
((memq c '(?z ?\C-z)) (call-interactively 'org-attach-sync))
|
|
((memq c '(?o ?\C-o)) (call-interactively 'org-attach-open))
|
|
((eq c ?O) (call-interactively 'org-attach-open-in-emacs))
|
|
((memq c '(?f ?\C-f)) (call-interactively 'org-attach-reveal))
|
|
((memq c '(?F)) (call-interactively 'org-attach-reveal-in-emacs))
|
|
((memq c '(?d ?\C-d)) (call-interactively
|
|
'org-attach-delete-one))
|
|
((eq c ?D) (call-interactively 'org-attach-delete-all))
|
|
((eq c ?q) (message "Abort"))
|
|
((memq c '(?s ?\C-s)) (call-interactively
|
|
'org-attach-set-directory))
|
|
((memq c '(?i ?\C-i)) (call-interactively
|
|
'org-attach-set-inherit))
|
|
(t (error "No such attachment command %c" c))))))
|
|
|
|
(defun org-attach-dir (&optional create-if-not-exists-p)
|
|
"Return the directory associated with the current entry.
|
|
This first checks for a local property ATTACH_DIR, and then for an inherited
|
|
property ATTACH_DIR_INHERIT. If neither exists, the default mechanism
|
|
using the entry ID will be invoked to access the unique directory for the
|
|
current entry.
|
|
If the directory does not exist and CREATE-IF-NOT-EXISTS-P is non-nil,
|
|
the directory and (if necessary) the corresponding ID will be created."
|
|
(let (attach-dir uuid inherit)
|
|
(setq org-attach-inherited (org-entry-get nil "ATTACH_DIR_INHERIT"))
|
|
(cond
|
|
((setq attach-dir (org-entry-get nil "ATTACH_DIR"))
|
|
(org-attach-check-absolute-path attach-dir))
|
|
((and org-attach-allow-inheritance
|
|
(setq inherit (org-entry-get nil "ATTACH_DIR_INHERIT" t)))
|
|
(setq attach-dir
|
|
(save-excursion
|
|
(save-restriction
|
|
(widen)
|
|
(goto-char org-entry-property-inherited-from)
|
|
(let (org-attach-allow-inheritance)
|
|
(org-attach-dir create-if-not-exists-p)))))
|
|
(org-attach-check-absolute-path attach-dir)
|
|
(setq org-attach-inherited t))
|
|
(t ; use the ID
|
|
(org-attach-check-absolute-path nil)
|
|
(setq uuid (org-id-get (point) create-if-not-exists-p))
|
|
(when (or uuid create-if-not-exists-p)
|
|
(unless uuid (error "ID retrieval/creation failed"))
|
|
(setq attach-dir (expand-file-name
|
|
(format "%s/%s"
|
|
(substring uuid 0 2)
|
|
(substring uuid 2))
|
|
(expand-file-name org-attach-directory))))))
|
|
(when attach-dir
|
|
(if (and create-if-not-exists-p
|
|
(not (file-directory-p attach-dir)))
|
|
(make-directory attach-dir t))
|
|
(and (file-exists-p attach-dir)
|
|
attach-dir))))
|
|
|
|
(defun org-attach-check-absolute-path (dir)
|
|
"Check if we have enough information to root the atachment directory.
|
|
When DIR is given, check also if it is already absolute. Otherwise,
|
|
assume that it will be relative, and check if `org-attach-directory' is
|
|
absolute, or if at least the current buffer has a file name.
|
|
Throw an error if we cannot root the directory."
|
|
(or (and dir (file-name-absolute-p dir))
|
|
(file-name-absolute-p org-attach-directory)
|
|
(buffer-file-name (buffer-base-buffer))
|
|
(error "Need absolute `org-attach-directory' to attach in buffers without filename")))
|
|
|
|
(defun org-attach-set-directory ()
|
|
"Set the ATTACH_DIR property of the current entry.
|
|
The property defines the directory that is used for attachments
|
|
of the entry."
|
|
(interactive)
|
|
(let ((dir (org-entry-get nil "ATTACH_DIR")))
|
|
(setq dir (read-directory-name "Attachment directory: " dir))
|
|
(org-entry-put nil "ATTACH_DIR" dir)))
|
|
|
|
(defun org-attach-set-inherit ()
|
|
"Set the ATTACH_DIR_INHERIT property of the current entry.
|
|
The property defines the directory that is used for attachments
|
|
of the entry and any children that do not explicitly define (by setting
|
|
the ATTACH_DIR property) their own attachment directory."
|
|
(interactive)
|
|
(org-entry-put nil "ATTACH_DIR_INHERIT" "t")
|
|
(message "Children will inherit attachment directory"))
|
|
|
|
(defun org-attach-commit ()
|
|
"Commit changes to git if `org-attach-directory' is properly initialized.
|
|
This checks for the existence of a \".git\" directory in that directory."
|
|
(let ((dir (expand-file-name org-attach-directory)))
|
|
(if (file-exists-p (expand-file-name ".git" dir))
|
|
(shell-command
|
|
(concat "(cd " dir "; "
|
|
" git add .; "
|
|
" git ls-files --deleted -z | xargs -0 git rm; "
|
|
" git commit -m 'Synchronized attachments')")))))
|
|
|
|
(defun org-attach-tag (&optional off)
|
|
"Turn the autotag on or (if OFF is set) off."
|
|
(when org-attach-auto-tag
|
|
(save-excursion
|
|
(org-back-to-heading t)
|
|
(org-toggle-tag org-attach-auto-tag (if off 'off 'on)))))
|
|
|
|
(defun org-attach-untag ()
|
|
"Turn the autotag off."
|
|
(org-attach-tag 'off))
|
|
|
|
(defun org-attach-attach (file &optional visit-dir method)
|
|
"Move/copy/link FILE into the attachment directory of the current task.
|
|
If VISIT-DIR is non-nil, visit the directory with dired.
|
|
METHOD may be `cp', `mv', or `ln', default taken from `org-attach-method'."
|
|
(interactive "fFile to keep as an attachment: \nP")
|
|
(setq method (or method org-attach-method))
|
|
(let ((basename (file-name-nondirectory file)))
|
|
(when (and org-attach-file-list-property (not org-attach-inherited))
|
|
(org-entry-add-to-multivalued-property
|
|
(point) org-attach-file-list-property basename))
|
|
(let* ((attach-dir (org-attach-dir t))
|
|
(fname (expand-file-name basename attach-dir)))
|
|
(cond
|
|
((eq method 'mv) (rename-file file fname))
|
|
((eq method 'cp) (copy-file file fname))
|
|
((eq method 'ln) (add-name-to-file file fname)))
|
|
(org-attach-commit)
|
|
(org-attach-tag)
|
|
(if visit-dir
|
|
(dired attach-dir)
|
|
(message "File \"%s\" is now a task attachment." basename)))))
|
|
|
|
(defun org-attach-attach-cp ()
|
|
"Attach a file by copying it."
|
|
(interactive)
|
|
(let ((org-attach-method 'cp)) (call-interactively 'org-attach-attach)))
|
|
(defun org-attach-attach-mv ()
|
|
"Attach a file by moving (renaming) it."
|
|
(interactive)
|
|
(let ((org-attach-method 'mv)) (call-interactively 'org-attach-attach)))
|
|
(defun org-attach-attach-ln ()
|
|
"Attach a file by creating a hard link to it.
|
|
Beware that this does not work on systems that do not support hard links.
|
|
On some systems, this apparently does copy the file instead."
|
|
(interactive)
|
|
(let ((org-attach-method 'ln)) (call-interactively 'org-attach-attach)))
|
|
|
|
(defun org-attach-new (file)
|
|
"Create a new attachment FILE for the current task.
|
|
The attachment is created as an Emacs buffer."
|
|
(interactive "sCreate attachment named: ")
|
|
(when (and org-attach-file-list-property (not org-attach-inherited))
|
|
(org-entry-add-to-multivalued-property
|
|
(point) org-attach-file-list-property file))
|
|
(let ((attach-dir (org-attach-dir t)))
|
|
(org-attach-tag)
|
|
(find-file (expand-file-name file attach-dir))
|
|
(message "New attachment %s" file)))
|
|
|
|
(defun org-attach-delete-one (&optional file)
|
|
"Delete a single attachment."
|
|
(interactive)
|
|
(let* ((attach-dir (org-attach-dir t))
|
|
(files (org-attach-file-list attach-dir))
|
|
(file (or file
|
|
(org-icompleting-read
|
|
"Delete attachment: "
|
|
(mapcar (lambda (f)
|
|
(list (file-name-nondirectory f)))
|
|
files)))))
|
|
(setq file (expand-file-name file attach-dir))
|
|
(unless (file-exists-p file)
|
|
(error "No such attachment: %s" file))
|
|
(delete-file file)))
|
|
|
|
(defun org-attach-delete-all (&optional force)
|
|
"Delete all attachments from the current task.
|
|
This actually deletes the entire attachment directory.
|
|
A safer way is to open the directory in dired and delete from there."
|
|
(interactive "P")
|
|
(when (and org-attach-file-list-property (not org-attach-inherited))
|
|
(org-entry-delete (point) org-attach-file-list-property))
|
|
(let ((attach-dir (org-attach-dir)))
|
|
(when
|
|
(and attach-dir
|
|
(or force
|
|
(y-or-n-p "Are you sure you want to remove all attachments of this entry? ")))
|
|
(shell-command (format "rm -fr %s" attach-dir))
|
|
(message "Attachment directory removed")
|
|
(org-attach-commit)
|
|
(org-attach-untag))))
|
|
|
|
(defun org-attach-sync ()
|
|
"Synchronize the current tasks with its attachments.
|
|
This can be used after files have been added externally."
|
|
(interactive)
|
|
(org-attach-commit)
|
|
(when (and org-attach-file-list-property (not org-attach-inherited))
|
|
(org-entry-delete (point) org-attach-file-list-property))
|
|
(let ((attach-dir (org-attach-dir)))
|
|
(when attach-dir
|
|
(let ((files (org-attach-file-list attach-dir)))
|
|
(and files (org-attach-tag))
|
|
(when org-attach-file-list-property
|
|
(dolist (file files)
|
|
(unless (string-match "^\\." file)
|
|
(org-entry-add-to-multivalued-property
|
|
(point) org-attach-file-list-property file))))))))
|
|
|
|
(defun org-attach-file-list (dir)
|
|
"Return a list of files in the attachment directory.
|
|
This ignores files starting with a \".\", and files ending in \"~\"."
|
|
(delq nil
|
|
(mapcar (lambda (x) (if (string-match "^\\." x) nil x))
|
|
(directory-files dir nil "[^~]\\'"))))
|
|
|
|
(defun org-attach-reveal ()
|
|
"Show the attachment directory of the current task in dired."
|
|
(interactive)
|
|
(let ((attach-dir (org-attach-dir t)))
|
|
(org-open-file attach-dir)))
|
|
|
|
(defun org-attach-reveal-in-emacs ()
|
|
"Show the attachment directory of the current task.
|
|
This will attempt to use an external program to show the directory."
|
|
(interactive)
|
|
(let ((attach-dir (org-attach-dir t)))
|
|
(dired attach-dir)))
|
|
|
|
(defun org-attach-open (&optional in-emacs)
|
|
"Open an attachment of the current task.
|
|
If there are more than one attachment, you will be prompted for the file name.
|
|
This command will open the file using the settings in `org-file-apps'
|
|
and in the system-specific variants of this variable.
|
|
If IN-EMACS is non-nil, force opening in Emacs."
|
|
(interactive "P")
|
|
(let* ((attach-dir (org-attach-dir t))
|
|
(files (org-attach-file-list attach-dir))
|
|
(file (if (= (length files) 1)
|
|
(car files)
|
|
(org-icompleting-read "Open attachment: "
|
|
(mapcar 'list files) nil t))))
|
|
(org-open-file (expand-file-name file attach-dir) in-emacs)))
|
|
|
|
(defun org-attach-open-in-emacs ()
|
|
"Open attachment, force opening in Emacs.
|
|
See `org-attach-open'."
|
|
(interactive)
|
|
(org-attach-open 'in-emacs))
|
|
|
|
(defun org-attach-expand (file)
|
|
"Return the full path to the current entry's attachment file FILE.
|
|
Basically, this adds the path to the attachment directory."
|
|
(expand-file-name file (org-attach-dir)))
|
|
|
|
(defun org-attach-expand-link (file)
|
|
"Return a file link pointing to the current entry's attachment file FILE.
|
|
Basically, this adds the path to the attachment directory, and a \"file:\"
|
|
prefix."
|
|
(concat "file:" (org-attach-expand file)))
|
|
|
|
(provide 'org-attach)
|
|
|
|
;; arch-tag: fce93c2e-fe07-4fa3-a905-e10dcc7a6248
|
|
;;; org-attach.el ends here
|