org-download

a fork of abo-abo's org-download
git clone https://git.trogloxene.org/org-download.git
Log | Files | Refs | README

commit bd8768630cb0554112bbf9b6010ae3bc1e131db6
parent 14261c2619be224fc4c499624abc2cba3663e7f5
Author: Wanderson Ferreira <iagwanderson@gmail.com>
Date:   Sun,  5 Nov 2017 16:52:27 -0200

Add rename last file function

Fixes #58

Diffstat:
Morg-download.el | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/org-download.el b/org-download.el @@ -103,6 +103,10 @@ See `org-download--dir-1' for more info." :group 'org-download) (make-variable-buffer-local 'org-download-heading-lvl) +(defvar org-download-path-last-file nil + "Variable to hold the full path of the last downloaded file. +See `org-download-rename-last-file'.") + (defcustom org-download-backend t "Method to use for downloading." :type '(choice @@ -330,12 +334,34 @@ It's inserted before the image link and is used to annotate it.") (funcall org-download-method link)) (t (org-download--fullname link ext))))) + (setq org-download-path-last-file filename) (when (image-type-from-file-name filename) (org-download--image link filename) (when (eq org-download-method 'attach) (org-attach-attach filename nil 'none)) (org-download-insert-link link filename))))) +(defun org-download-rename-last-file () + "Rename the last downloaded file saved in your computer." + (interactive) + (let* ((dir-path (org-download--dir)) + (newname (read-string "Rename last file to: ")) + (ext (file-name-extension org-download-path-last-file)) + (newpath (concat dir-path "/" newname "." ext))) + (when org-download-path-last-file + (rename-file org-download-path-last-file newpath 1) + (org-download-replace-all + (file-name-nondirectory org-download-path-last-file) + (concat newname "." ext)) + (setq org-download-path-last-file newpath)))) + +(defun org-download-replace-all (oldpath newpath) + "Function to search for the OLDPATH inside the buffer and replace it by the NEWPATH." + (save-excursion + (beginning-of-buffer) + (while (re-search-forward oldpath nil t) + (replace-match newpath)))) + (defun org-download-insert-link (link filename) (if (looking-back "^[ \t]+" (line-beginning-position)) (delete-region (match-beginning 0) (match-end 0))