From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id kGW3IDnBI2IGkwAAgWs5BA (envelope-from ) for ; Sat, 05 Mar 2022 20:59:53 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id IF6LGTnBI2KKigAAG6o9tA (envelope-from ) for ; Sat, 05 Mar 2022 20:59:53 +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 C12901B1FE for ; Sat, 5 Mar 2022 20:59:52 +0100 (CET) Received: from localhost ([::1]:53512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQaZD-00040h-94 for larch@yhetil.org; Sat, 05 Mar 2022 14:59:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQaYW-00040X-Eq for emacs-orgmode@gnu.org; Sat, 05 Mar 2022 14:59:08 -0500 Received: from mout02.posteo.de ([185.67.36.66]:51611) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQaYU-0004nH-0d for emacs-orgmode@gnu.org; Sat, 05 Mar 2022 14:59:08 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 609C7240104 for ; Sat, 5 Mar 2022 20:59:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1646510341; bh=QWGt9GI9R3AUMH1w648fNmpnRi2lICTXqJxr/HEs3MI=; h=From:To:Subject:Date:From; b=ouoarCilNWwTWJN6md1X3GuwcU4KyjMxovN1UKTWwwNDLWP1jAdsh/3jEC63N4xYr SZtsT5dWOkTdwtriyEWxo9qU6XPfqLp/FQ/9oBqmfOY/CXEilFnHiskPFjZKgZPN1g 5DHavNXBehdV9MHWls6XlHWPxZtvgC1ObQk6mwcKwJGl/z606rBfZ45vHnlVJoo/2f dQrF1/WE14+LcgArKzFq5j87gImx5v+ahsBCMbjInWSO0bb4yXaZzapJYCeDc0Izs6 dfh7YrqXvsfVzC83xMgtZclRXxKzwK/xXMKhrzzGcxtP7AYhwes9YF8vP4sey7AFtN 8CPWZDqqaIxBw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4K9wXN59Q1z6tm9 for ; Sat, 5 Mar 2022 20:59:00 +0100 (CET) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: Move or rename a file in a link Date: Sat, 05 Mar 2022 19:58:57 +0000 Message-ID: <87lexotblq.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1646510393; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=6yYA10N1eVY8xgfL9rR1tNcFVe4OYWYeu/FPCuhPo6U=; b=LhRbXFROe9ZEWIiHmqxegjeBqnsx2kaYS73vU4pyTcPGcPWy7gmDHuJht0yf45LOQMaWPp j4lUpj7agK0DeiMtBH6/FESguV47Mq6Dhr2FNUlHiVtcpPscI861deJx4eWEk6+mT8xaWY EM2+75rWYSaFwwG/UWxsEcFUr0bje1r/W5N5TQyYuonUxb6aK835Sc/46BuJ6ad4QIpcZK YNCs/mx9mmPMKG2y+sXyASCkakdQTXXa3JRfiZUSJ58PxkFsYnmMadTW/e6uD+yAc3J+fF s0dcKc0rWD1lxVypQWhXHNF3Qx2Vw6A8wR5tJLMUrsr2spVfs9jgwbvCy/25CA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1646510393; a=rsa-sha256; cv=none; b=iMzlatPIF505OCiKlC67cbQ1DvkNwdmQNY21An11V1/aiXJpFftDlVygOzO30Hv8kRx8hf C/30cYdBJduIZbt6wGgio9hOv6qgeeECyEV1SLKh5gXwHyUm6FIHa3ldWnNSYw5o1GFZnR eloPsImnJI9+aKYrFmy7TwNy8PdWV9WWCw1epz2f/0pCS/pNv2N4fV7icewOXMjehtaihh p2h2555YX9Ne5aHuu4DNjy94aYU3SMmW8TTpZkEaUbSKZ29i7533/RSwg8yaBbjyyGPQuR Vx0CrCfYVVVesVL3KwZsp2/iu+PhCZ7NEgbMAT27Afw+86eKqx1pxuch+Avc2g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=ouoarCil; 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: -7.94 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=ouoarCil; 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: C12901B1FE X-Spam-Score: -7.94 X-Migadu-Scanner: scn0.migadu.com X-TUID: JDYb6Bz9gsDH Hi all, I have written this simple function to move or rename a destination file in an external link at point. I share it here in case it is useful to someone. Best regards, Juan Manuel #+begin_src emacs-lisp (defun my-org-replace-link-file (from to) (save-excursion (goto-char (point-min)) (while (re-search-forward org-bracket-link-regexp nil t) (when (string-match-p from (match-string 1)) (replace-match (concat "[[file:" to "]]")))))) (defun my-org-rename-link-file-at-point () "Rename or move a file in an external link at point and update the link path" (interactive) (let* ((curr-dir (abbreviate-file-name default-directory)) (current-path (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)) (my-org-replace-link-file current-path (replace-regexp-in-string curr-dir "" new-path)))) #+end_src