[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] An org-attach link type [7.9.1 (7.9.1-elpa @ /home/youngfrog/.em
From: |
Nicolas Richard |
Subject: |
Re: [O] An org-attach link type [7.9.1 (7.9.1-elpa @ /home/youngfrog/.emacs.d/elpa/org-20120903/)] |
Date: |
Thu, 27 Sep 2012 18:25:27 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
Bastien <address@hidden> writes:
Hello,
> If you feel like adding the attach link type to org-attach.el
> please go ahead and provide a patch.
Ok, so here it is, in two parts.
The first patch (included below) modifies org-attach-file-list to try
and make it slightly more customizable :
- The DIR argument is made optional (when given, old behaviour is used)
- When that argument is not given, the function obeys a customizable
option saying which attached files it should list for the subtree at
point. That option defaults to the old behaviour.
- Accordingly, functions that use org-attach-file-list are modified.
The second patch (which should be independent from this one) follows in
a different email, with the actual completing function.
> Beware of the format of
> the patch, though: it must contain a proper ChangeLog. See
I did my best. Now I hope its sufficient.
--
N.
-- 8> --
>From 0b675ab013de01422f55669ea1aebd8a77c1f7af Mon Sep 17 00:00:00 2001
From: "nrichard (geodiff-mac3)" <address@hidden>
Date: Thu, 27 Sep 2012 17:37:03 +0200
Subject: [PATCH 1/2] (org-attach) Add some options for listing attachments
* lisp/org-attach.el (org-attach-file-list-method): new variable
(org-attach-file-list-skip-re): new variable
(org-attach-file-list): use new variables to customize which files are
listed. Moreover the argument DIR is now optional : if it is given,
the old behaviour is kept for backward compatibility, otherwise
attachments are listed for the subtree at point.
(org-attach-delete-one): drop the now optional argument
(org-attach-sync): drop the now optional argument
(org-attach-open): drop the now optional argument
---
lisp/org-attach.el | 59 +++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 50 insertions(+), 9 deletions(-)
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index e02d7e0..4a4c195 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -71,6 +71,28 @@ attachments is not kept in this property."
(const :tag "None" nil)
(string :tag "Tag")))
+(defcustom org-attach-file-list-method 'default
+ "Determine what files are to be listed as attached files.
+
+It can be the symbols :
+- `default' :: list all files and directories in the attachment directory.
+- `explicit' :: list only attached files that are explicitly listed in
+ the `org-attach-file-list-property' (Attachments)
+ property. (unreliable)
+- `recurse' :: list all files in the attachment directory, recursively.
+
+See also variable `org-attach-file-list-skip-re'."
+ :group 'org-attach
+ :type '(choice
+ (const :tag "List content of the attachment directory" default)
+ (const :tag "List content of the property
`org-attach-file-list-property'" explicit)
+ (const :tag "List files in the attachment directory recursively"
recurse)))
+
+(defcustom org-attach-file-list-skip-re "\\`\\.\\|~\\'"
+ "Files matching this regexp will be skipped when listing attachments."
+ :group 'org-attach
+ :type 'regexp)
+
(defcustom org-attach-method 'cp
"The preferred method to attach a file.
Allowed values are:
@@ -350,7 +372,7 @@ The attachment is created as an Emacs buffer."
"Delete a single attachment."
(interactive)
(let* ((attach-dir (org-attach-dir t))
- (files (org-attach-file-list attach-dir))
+ (files (org-attach-file-list))
(file (or file
(org-icompleting-read
"Delete attachment: "
@@ -389,7 +411,7 @@ This can be used after files have been added externally."
(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)))
+ (let ((files (org-attach-file-list)))
(and files (org-attach-tag))
(when org-attach-file-list-property
(dolist (file files)
@@ -397,12 +419,31 @@ This can be used after files have been added externally."
(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 "[^~]\\'"))))
+(declare-function find-lisp-find-files "find-lisp")
+
+(defun org-attach-file-list (&optional dir)
+ "List files in the directory DIR, or attachments to the subtree at point.
+
+When DIR is not given, list attachments to the subtree at point
+according to `org-attach-file-list-method'.
+
+When DIR is given, list files in that directory.
+
+In both cases, files matching `org-attach-file-list-skip-re' are
+ignored. Default is to skip files starting with a \".\" and files
+ending in \"~\"."
+ (let* ((attach-dir (or dir (org-attach-dir nil)))
+ (list (cond
+ ; when DIR is explicitly given, use old method for backward
compatibility.
+ ((or (eq org-attach-file-list-method 'default) dir)
+ (directory-files attach-dir))
+ ((eq org-attach-file-list-method 'explicit)
+ (org-entry-get-multivalued-property nil
org-attach-file-list-property))
+ ((eq org-attach-file-list-method 'recurse)
+ (progn (require 'find-lisp)
+ (mapcar (lambda (x) (file-relative-name x attach-dir))
(find-lisp-find-files attach-dir ""))))))
+ (skip-function (lambda (x) (if (string-match
org-attach-file-list-skip-re x) nil x))))
+ (delq nil (mapcar skip-function list))))
(defun org-attach-reveal (&optional if-exists)
"Show the attachment directory of the current task in dired."
@@ -425,7 +466,7 @@ 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))
+ (files (org-attach-file-list))
(file (if (= (length files) 1)
(car files)
(org-icompleting-read "Open attachment: "
--
1.7.12