From: Sander Boer <sanderboer@yahoo.com>
To: emacs-orgmode@gnu.org
Subject: Assets Packing
Date: Fri, 27 May 2011 15:53:27 +0200 [thread overview]
Message-ID: <iroacr$hpa$1@dough.gmane.org> (raw)
Hi all,
Maybe this already exists in org, but I needed a function that looks at
all the image links, signals if the link is broken or not, copies the
files into a folder and relinks it.
Comments and crits are greatly appreciated, I started coding elisp 2
weeks ago, so any and all pointers and tips are welcome.
-------8<------------------------------------- cut here
(defcustom sndr-assets-dir nil
"the directory org linked assets are moved to, do not forget trailing
slash..."
:type '(string)
:group'sndr
)
(defun sndr-assets-package()
"finds file links and moves them to a dir specified, or ./assets ,
relative to the org file"
(interactive)
(let (p0 p1)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp
"\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]" nil t)
(match-beginning 1)
(setq p0 (match-beginning 1))
(setq p1 (match-end 1))
(sndr-link-check-and-move p0 p1)
)
)))
(defun sndr-link-check-and-move (p0 p1)
"gets a buffer section, checks if it is a file, moves the file to a
dir specified (or ./assets) and updates the buffer accordingly"
(let (file newdir newfile)
(setq file (buffer-substring-no-properties p0 p1 ))
(file-exists-p file)
(setq newdir (or sndr-assets-dir (concat (file-name-directory
buffer-file-name) "assets/")))
(setq newfile (concat newdir(file-name-nondirectory file)))
(if (not (file-exists-p newdir))
(make-directory newdir t))
(if (file-exists-p file)
(progn
(if (not(file-exists-p newfile)) (copy-file file newfile))
(goto-char p0)
(delete-region p0 p1)
(insert newfile)
)
(progn
(goto-char p0)
(delete-region p0 p1)
(insert (concat "BROKEN#" file "#BROKEN"))
))))
-------8<------------------------------------- cut here
sander.
reply other threads:[~2011-05-27 13:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
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='iroacr$hpa$1@dough.gmane.org' \
--to=sanderboer@yahoo.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).