On 19 March 2022 11:25, Juan Manuel MacĂ­as wrote: > #+begin_src emacs-lisp > (defun my-org-rename-link-file-at-point () > (interactive) > (let* ((curr-dir (if (equal (org-element-property :type (org-element-context)) "attachment") > (concat (abbreviate-file-name (org-attach-dir)) "/") > (abbreviate-file-name default-directory))) > (current-path (if (equal (org-element-property :type (org-element-context)) "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)) "attachment") > (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 Just a couple of fixes and it seems to be working fine.