emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Org-attach for a directory
@ 2022-06-08  9:59 Cletip Cletip
  2022-06-08 10:27 ` Fraga, Eric
  2022-06-08 10:32 ` Juan Manuel Macías
  0 siblings, 2 replies; 8+ messages in thread
From: Cletip Cletip @ 2022-06-08  9:59 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]

Hello to all.
I hope to have understood the operation to ask a question to all the
members, I hope that my question will not disturb anybody.
If this is not the right place, do not hesitate to tell me and I apologize
in advance for the inconvenience

My question is in the object : can we attach a directory to a heading?
If yes, how, if not, why. Can we solve the problem?

Subsidiary question:
Can we use org-attach as a filesystem?
Thanks in advance for your future answers

[-- Attachment #2: Type: text/html, Size: 542 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Org-attach for a directory
  2022-06-08  9:59 Org-attach for a directory Cletip Cletip
@ 2022-06-08 10:27 ` Fraga, Eric
  2022-06-08 19:48   ` Cletip Cletip
  2022-06-08 10:32 ` Juan Manuel Macías
  1 sibling, 1 reply; 8+ messages in thread
From: Fraga, Eric @ 2022-06-08 10:27 UTC (permalink / raw)
  To: Cletip Cletip; +Cc: emacs-orgmode@gnu.org

On Wednesday,  8 Jun 2022 at 11:59, Cletip Cletip wrote:
> My question is in the object : can we attach a directory to a heading?

If you mean copying the directory and all of its contents, I imagine
not.  However, you can link to the directory if you wish by visiting the
directory using dired, say, and storing the link (org-store-link).  The
link can then be inserted wherever you wish using org-insert-link.
Alternatively, you could also tar or zip up the contents of the
directory and attach that.

> Subsidiary question: 
> Can we use org-attach as a filesystem?

What is it you wish to do?  I do not understand this question.

-- 
: Eric S Fraga, with org release_9.5.4-521-g1105da in Emacs 29.0.50

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Org-attach for a directory
  2022-06-08  9:59 Org-attach for a directory Cletip Cletip
  2022-06-08 10:27 ` Fraga, Eric
@ 2022-06-08 10:32 ` Juan Manuel Macías
       [not found]   ` <CAPHku6O3RojzhaSu3d2pWfnE8x7N_9WAfjCupHyKcxNyD-i=ew@mail.gmail.com>
  1 sibling, 1 reply; 8+ messages in thread
From: Juan Manuel Macías @ 2022-06-08 10:32 UTC (permalink / raw)
  To: Cletip Cletip; +Cc: orgmode

Hi,

Cletip Cletip writes:

> My question is in the object : can we attach a directory to a heading?
> If yes, how, if not, why. Can we solve the problem?

I have in my init the following modification to the org-attach-attach
function so that I can copy a directory. I have replaced the line

((eq method 'cp) (copy-file file attach-file))

with this:

((eq method 'cp) (if (file-directory-p file) 
		     (copy-directory file attach-file)
		   (copy-file file attach-file)))


You can override the old function with advice-add:

(advice-add 'org-attach-attach :override 'my-new-org-attach-attach)

> Subsidiary question:
> Can we use org-attach as a filesystem? 
> Thanks in advance for your future answers

Can you please elaborate more? In my case, I use org-attach almost as a
replacement for my folder system (ie org nodes have come to replace
directories, and many nodes have a folder attached); I access the nodes
via org-ql/helm-org-ql (https://github.com/alphapapa/org-ql). It's very
productive.

Best regards,

Juan Manuel 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Org-attach for a directory
  2022-06-08 10:27 ` Fraga, Eric
@ 2022-06-08 19:48   ` Cletip Cletip
  2022-06-09  9:37     ` [PATCH] " Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Cletip Cletip @ 2022-06-08 19:48 UTC (permalink / raw)
  To: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 1057 bytes --]

Thank you for your answer.
Unfortunately, I would like to copy the entire directory.
To clarify my second question, I would like to have a folder system with
org-mode, and therefore only use org-attach to store my documents

Le mer. 8 juin 2022 à 12:27, Fraga, Eric <e.fraga@ucl.ac.uk> a écrit :

> On Wednesday,  8 Jun 2022 at 11:59, Cletip Cletip wrote:
> > My question is in the object : can we attach a directory to a heading?
>
> If you mean copying the directory and all of its contents, I imagine
> not.  However, you can link to the directory if you wish by visiting the
> directory using dired, say, and storing the link (org-store-link).  The
> link can then be inserted wherever you wish using org-insert-link.
> Alternatively, you could also tar or zip up the contents of the
> directory and attach that.
>
> > Subsidiary question:
> > Can we use org-attach as a filesystem?
>
> What is it you wish to do?  I do not understand this question.
>
> --
> : Eric S Fraga, with org release_9.5.4-521-g1105da in Emacs 29.0.50

[-- Attachment #2: Type: text/html, Size: 1398 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] Re: Org-attach for a directory
  2022-06-08 19:48   ` Cletip Cletip
@ 2022-06-09  9:37     ` Ihor Radchenko
  2022-07-21 11:24       ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2022-06-09  9:37 UTC (permalink / raw)
  To: Cletip Cletip; +Cc: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 581 bytes --]

Cletip Cletip <clement020302@gmail.com> writes:

> Thank you for your answer.
> Unfortunately, I would like to copy the entire directory.
> To clarify my second question, I would like to have a folder system with
> org-mode, and therefore only use org-attach to store my documents

Note that it makes much more sense to use 'mv method when you actually
use attachments as your filesystem. There is no need to keep trailing
garbage files. 'mv methods works for directories.

As for the 'cp method, it does not work for directories on current main.
The fix is attached.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-attach-attach-Allow-attaching-directories-using-.patch --]
[-- Type: text/x-patch, Size: 1573 bytes --]

From 6d879aeca5d1c52a824df998704298d9ee4a4a0a Mon Sep 17 00:00:00 2001
Message-Id: <6d879aeca5d1c52a824df998704298d9ee4a4a0a.1654767374.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Thu, 9 Jun 2022 17:33:49 +0800
Subject: [PATCH] org-attach-attach: Allow attaching directories using 'cp
 method

* lisp/org-attach.el (org-attach-attach): Use `copy-directory' when
FILE is a directory.  Remove trailing slash before processing.
---
 lisp/org-attach.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 5ee2b84b2..00919bef8 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -517,12 +517,17 @@ (defun org-attach-attach (file &optional visit-dir method)
     current-prefix-arg
     nil))
   (setq method (or method org-attach-method))
+  (when (file-directory-p file)
+    (setq file (directory-file-name file)))
   (let ((basename (file-name-nondirectory file)))
     (let* ((attach-dir (org-attach-dir 'get-create))
            (attach-file (expand-file-name basename attach-dir)))
       (cond
        ((eq method 'mv) (rename-file file attach-file))
-       ((eq method 'cp) (copy-file file attach-file))
+       ((eq method 'cp)
+        (if (file-directory-p file)
+            (copy-directory file attach-file nil nil t)
+          (copy-file file attach-file)))
        ((eq method 'ln) (add-name-to-file file attach-file))
        ((eq method 'lns) (make-symbolic-link file attach-file))
        ((eq method 'url) (url-copy-file file attach-file)))
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: Org-attach for a directory
       [not found]   ` <CAPHku6O3RojzhaSu3d2pWfnE8x7N_9WAfjCupHyKcxNyD-i=ew@mail.gmail.com>
@ 2022-06-09 10:11     ` Juan Manuel Macías
  0 siblings, 0 replies; 8+ messages in thread
From: Juan Manuel Macías @ 2022-06-09 10:11 UTC (permalink / raw)
  To: Cletip Cletip; +Cc: orgmode

Cletip Cletip writes:

> Thank you for your answer. 

You're welcome.

> Your answer seems perfect to answer my question: I modify a function
> of org-mode, and it allows me to attach folders and files to a
> heading. 
> Unfortunately, it doesn't work (probably because of my version of
> org-mode I guess)
>
> I have the following error:
> make-directory: The file exists:
> /home/user/sharedDirectoryPrivate/notes/braindump/.data/11e080/1b-7896-4f20-a24a-b9f45337e940

I don't know all the details of your problem. But if it gives you an
error saying The file exists, I would say that the cause is that the
directory you want to copy already exists in your attach folder. Could
it be that in your case? Note that the 'copy-directory' function does not
overwrite copied directories.

> Just to make sure I understood correctly: you can, with the "copy"
> method and the simple modification of the "org-attach-attach"
> function, attach a folder to a heading of org mode? 
> If so, this is exactly what I am looking for, and this would be a
> great help.

Exactly. I wrote a new version of org-attach-attach, modified that part,
as I told you, and added it via advice-add (with :override keyword) so
that it overrides the old function.

> To clarify my second question, I would like to have a folder system
> with org-mode, and therefore only use org-attach to arrange my
> documents, exactly like you. 
> Could you describe your workflow in more detail? Your use of tags for
> example, do you put dates, etc.

Now I have less time than I would like to go into the details, but
perhaps some reflections that I shared here may be useful to you:

https://list.orgmode.org/875yms7wys.fsf@posteo.net/

The strong point of my approach is to think of Org nodes and not the
classic directory/file scheme. But for that to work well you must rely
on a system that ensures a semantic search through the nodes. For me the
answer is org-ql (and if you're a helm user, you have helm-org-ql too).
Basically it's turning all your Org documents into a human-readable
database, where searches can be narrowed down by tags, status, content,
etc.

Another important point is that this scheme works wonderfully well with
org-capture.

Best regards,

Juan Manuel 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Re: Org-attach for a directory
  2022-06-09  9:37     ` [PATCH] " Ihor Radchenko
@ 2022-07-21 11:24       ` Ihor Radchenko
  2022-07-21 13:51         ` Cletip Cletip
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2022-07-21 11:24 UTC (permalink / raw)
  To: Cletip Cletip; +Cc: Org Mode List

Ihor Radchenko <yantar92@gmail.com> writes:

> As for the 'cp method, it does not work for directories on current main.
> The fix is attached.

Applied onto main via d2a110ffe.

Best,
Ihor


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Re: Org-attach for a directory
  2022-07-21 11:24       ` Ihor Radchenko
@ 2022-07-21 13:51         ` Cletip Cletip
  0 siblings, 0 replies; 8+ messages in thread
From: Cletip Cletip @ 2022-07-21 13:51 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 290 bytes --]

Thank you!

On Thu, 21 Jul 2022, 13:23 Ihor Radchenko, <yantar92@gmail.com> wrote:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
> > As for the 'cp method, it does not work for directories on current main.
> > The fix is attached.
>
> Applied onto main via d2a110ffe.
>
> Best,
> Ihor
>

[-- Attachment #2: Type: text/html, Size: 669 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-21 13:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-08  9:59 Org-attach for a directory Cletip Cletip
2022-06-08 10:27 ` Fraga, Eric
2022-06-08 19:48   ` Cletip Cletip
2022-06-09  9:37     ` [PATCH] " Ihor Radchenko
2022-07-21 11:24       ` Ihor Radchenko
2022-07-21 13:51         ` Cletip Cletip
2022-06-08 10:32 ` Juan Manuel Macías
     [not found]   ` <CAPHku6O3RojzhaSu3d2pWfnE8x7N_9WAfjCupHyKcxNyD-i=ew@mail.gmail.com>
2022-06-09 10:11     ` Juan Manuel Macías

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).