emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Matt Price <moptop99@gmail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] org-attach-attach: fix symlinks
Date: Sat, 30 Apr 2022 11:32:58 +0800	[thread overview]
Message-ID: <87pmkzutxx.fsf@localhost> (raw)
In-Reply-To: <CAN_Dec_LyTKgSN_kiftee9GULM7FPER5frQFant3n_2C3cwM-g@mail.gmail.com>

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

Matt Price <moptop99@gmail.com> writes:

> I'm having trouble with org-attach-attach if my current buffer is visiting
> a filepath starting with "~/". This trivial patch fixes the problem for me
> by running (expand-file-name) on the file before attaching. I always use
> the 'lns method, so I don't know whether it might be better to
> expand-file-name before running any of the methods.
> Alternatively, it might actually be better to use a *relative* file path
> where possible (e.g. to ensure that project directories are fully
> portable), but I'm  not sure how best to do that.

I do not like explicit expansion of the FILE path. It may break relative
vs. absolute path handling.

Attaching an alternative patch. It makes use of make-symbolic-link


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-attach-attach-Avoid-linking-to-path-starting-wit.patch --]
[-- Type: text/x-patch, Size: 1369 bytes --]

From ff9ccae51ce1b02fc5d95cbc60de7a44c42f28a1 Mon Sep 17 00:00:00 2001
Message-Id: <ff9ccae51ce1b02fc5d95cbc60de7a44c42f28a1.1651289455.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sat, 30 Apr 2022 11:27:30 +0800
Subject: [PATCH] org-attach-attach: Avoid linking to path starting with ~

* lisp/org-attach.el (org-attach-attach): Auto-expand ~ in the file
patch when using symlink (`lns') attach method.

Fixes https://orgmode.org/list/CAN_Dec_LyTKgSN_kiftee9GULM7FPER5frQFant3n_2C3cwM-g@mail.gmail.com
 lisp/org-attach.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 5ee2b84b2..760592507 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -524,7 +524,8 @@ (defun org-attach-attach (file &optional visit-dir method)
        ((eq method 'mv) (rename-file file attach-file))
        ((eq method 'cp) (copy-file file attach-file))
        ((eq method 'ln) (add-name-to-file file attach-file))
-       ((eq method 'lns) (make-symbolic-link file attach-file))
+       ;; We pass integer third argument to auto-expand "~" in FILE.
+       ((eq method 'lns) (make-symbolic-link file attach-file 1))
        ((eq method 'url) (url-copy-file file attach-file)))
       (run-hook-with-args 'org-attach-after-change-hook attach-dir)

  reply	other threads:[~2022-04-30  3:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15 13:22 [PATCH] org-attach-attach: fix symlinks Matt Price
2022-04-30  3:32 ` Ihor Radchenko [this message]
2022-07-04 13:02   ` Ihor Radchenko
2022-07-04 13:38     ` Matt Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pmkzutxx.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=moptop99@gmail.com \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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).