Created
November 27, 2011 05:33
-
-
Save alexras/1397027 to your computer and use it in GitHub Desktop.
Emacs lisp functions for creating attachment directories and attaching files in MarkupServe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun markupserve-resource-dir-for-buffer (buffer) | |
(concat (buffer-file-name buffer) "/../" (file-name-sans-extension | |
(buffer-name buffer)) | |
".resources")) | |
(defun markupserve-make-resource-directory () | |
(interactive) | |
(if (buffer-file-name (current-buffer)) | |
(let ((dirname (markupserve-resource-dir-for-buffer (current-buffer)))) | |
(make-directory dirname) | |
(message "Resource directory %s created" dirname) | |
) | |
(message (concat "Current buffer isn't backed by a file, so can't create " | |
"resource directory")))) | |
(defun markupserve-attach-resource () | |
(interactive) | |
(let ((attachedfile (read-file-name "File to attach: ")) | |
(resourcedir (markupserve-resource-dir-for-buffer (current-buffer)))) | |
(let ((dest-path (concat resourcedir "/" | |
(file-name-nondirectory attachedfile))) | |
(source-filename (file-name-nondirectory attachedfile))) | |
(if (file-exists-p dest-path) (delete-file dest-path)) | |
(copy-file attachedfile dest-path) | |
(insert (format "[%s](%s/%s)" source-filename | |
(url-hexify-string | |
(file-name-nondirectory resourcedir)) | |
(url-hexify-string source-filename))) | |
(message "Attached %s" attachedfile)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment