From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id +JsxDe69NWL2uAAAgWs5BA (envelope-from ) for ; Sat, 19 Mar 2022 12:26:38 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id IN6mCu69NWJSlQAA9RJhRA (envelope-from ) for ; Sat, 19 Mar 2022 12:26:38 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A6455DC33 for ; Sat, 19 Mar 2022 12:26:37 +0100 (CET) Received: from localhost ([::1]:53370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nVXEC-00073E-GK for larch@yhetil.org; Sat, 19 Mar 2022 07:26:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nVXCz-000733-4g for emacs-orgmode@gnu.org; Sat, 19 Mar 2022 07:25:21 -0400 Received: from mout02.posteo.de ([185.67.36.66]:40621) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nVXCw-0007LM-Am for emacs-orgmode@gnu.org; Sat, 19 Mar 2022 07:25:20 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 2499E240103 for ; Sat, 19 Mar 2022 12:25:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1647689115; bh=KhZss9e7mU7hcqzderWJFvesHnWQWd07lwN6VmClsI0=; h=From:To:Cc:Subject:Date:From; b=cj35RBmCnERMaBP42kb9tA+rHcbBku+y0AYYH6PSmk7PQRs9my0KjxjBz7ETRrDhj jVd1lBmKJzzNv5oEFAndv8PepoLQeyzLbxRfcilMrui4EP4VU2gRp+IFyLbIbIc8hd I7QEQ2BP7WRjXftjJO5AYCTZOJgZRYqSuzkilon8QyeX2bpd+zeuQGRcSMD6rr6rtt ARhuTxhjHB3gp5bYHFIANssU60RVsQjiP14qJ9KPEbNbt0fZj5sPSTOrUCxg6gr6Ox lgSvznqa9+6Ot98ix+CcH+B1WHXMjFTobhxe/UOIMCnIJbsPo8uBpR1lP1w+AnNaM/ U0psl8LUO+2tg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4KLJT62SxBz9rxN; Sat, 19 Mar 2022 12:25:14 +0100 (CET) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: =?utf-8?Q?Jo=C3=A3o?= Pedro de Amorim Paula Subject: Re: Move or rename a file in a link References: <87lexotblq.fsf@posteo.net> <878rti98d3.fsf@gmail.com> <878rthj1mm.fsf@posteo.net> <87pmmjgkjy.fsf@gmail.com> Date: Sat, 19 Mar 2022 11:25:12 +0000 In-Reply-To: <87pmmjgkjy.fsf@gmail.com> (=?utf-8?Q?=22Jo=C3=A3o?= Pedro de Amorim Paula"'s message of "Fri, 18 Mar 2022 15:52:33 -0300") Message-ID: <87ilsadw13.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.67.36.66; envelope-from=maciaschain@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: orgmode Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1647689197; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=cXHeDTB5xg6+LbLSJoWYiF94pshRWnSpBgDMEsV/nyE=; b=dj1V3SxFylbEXC+zQKu8bYH6u9pOSj19HPR3JBc6QqoK7kvS9ECcvPROiB4jzoEaPiKfhr NoHWjecL+VfzdpU+C857opuuzFoLSUa5/Slbb/zMB7e0XimlD9gGvI20XGX/upG41dVfRQ oollKxwcAkkeqgz8ewc+zLAyiZQwXWT6f1wLBF07lFGE4NWoxYQX8tGxU5YZZ1ta2OkVmf JazERERv4W831u+O4/U94AyS091K0zOs8NBmwsMqMmRSviJWz8RcVB0uX7G6xMN5XyPHT/ YuftfaG8BGHQyBGvZxZS7EcUST5b43wummsxdd+IOzHmIkFXtuCbSODSl8HHDw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1647689197; a=rsa-sha256; cv=none; b=TV96DfxlsFr7Ec8fYfNulPYaD/5FgDSuXE0GZdEfAqbgATxcmel7YDWpRQ5JoQ+rAqSnmb iBVjlJ7PuE9xF9ExpFZKwYqwcghX/3uOcDN98UDeT8TffCnU39IOCUnBUHpS3ycZUB69lq l6JPEjR+2iW+cRYlgRUZhTLD40/HlHVtrKO7AHCQx5ZyBBkt+wNiK/70G1M9Bh4sDF29Cz 8w1jMFIgx0MR+kYNpM1IgOzX9+TmRCGWmCd2jzVPhqnLEydeP7lPwaEo4j7ycwy8S79n8X wYGo+W8iKXQfOEeZOat06iDShld84NF+negDi0LMsps3p3+4YZ3pMj4ud5iiZA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=cj35RBmC; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -4.34 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=cj35RBmC; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: A6455DC33 X-Spam-Score: -4.34 X-Migadu-Scanner: scn1.migadu.com X-TUID: wZiKclDQHyV0 Hi Jo=C3=A3o, Jo=C3=A3o Pedro de Amorim Paula writes: > I mean org attachments. I use org-attach extensively to store documents > with notes. So I'd have a heading like so > > * Documents > :PROPERTIES: > :DIR: data/docs/ > :END: > > - [[Registration][attachment:registration.pdf]] :: My registration. > > And say I'd like to rename the file. I would need to rename it inside > data/docs and I would also need to edit the link, so I would like to > have a way to do it automatically. I just got a computer back so I will > be trying to adapt what you did to work with org-attach, but if you > figure out a way to do it as well, please, let me know. I see. This is a new version that would also work with org attachment links. I haven't tested it much and the function is a bit tricky, but I think it works fine: #+begin_src emacs-lisp (defun my-org-rename-link-file-at-point () (interactive) (let* ((curr-dir (if (equal (org-element-property :type (org-element-co= ntext)) "attachment") (concat (abbreviate-file-name (org-attach-dir)) "/") (abbreviate-file-name default-directory))) (current-path (if (equal (org-element-property :type (org-element-conte= xt)) "attachment") (concat curr-dir (org-element-property :path (org-element-context))) (org-element-property :path (org-element-context)))) (new-path (read-file-name "Rename file at point to: " current-path))) (rename-file current-path new-path) (message (concat "moved to: " new-path)) (if (directory-name-p new-path) (setq new-path (concat new-path (file-name-nondirectory current-path))) (setq new-path new-path)) (if (equal (org-element-property :type (org-element-context)) "attach= ment") (my-org-replace-link-file (file-name-nondirectory current-path) (replace-regexp-in-string curr-dir "" new-path)) (my-org-replace-link-file current-path (replace-regexp-in-string curr-dir "" new-path))))) (defun my-org-replace-link-file (from to) (save-excursion (goto-char (point-min)) (while (re-search-forward org-bracket-link-regexp nil t) (cond ((string-match-p (concat "attachment:" from) (match-string 1)) (replace-match (concat "[[attachment:" to "]]"))) ((string-match-p from (match-string 1)) (replace-match (concat "[[file:" to "]]"))))))) #+end_src Best regards, Juan Manuel=20