Add interactive wrapper around path function

copied from image-file-name
added test to see that file name unchanged when no attachments
This commit is contained in:
Willem van den Ende
2023-01-10 14:52:20 +00:00
parent 999f7abb19
commit b485706910
+10 -9
View File
@@ -293,10 +293,15 @@ the description. This may destroy existing links, or change their targets so use
)))))) ))))))
(defun qwan/image-mode-copy-filename-as-markdown-link () (defun qwan/image-mode-copy-filename-as-markdown-link ()
"example: /Users/willem/MyDocuments/qwan/sites/qwaneu.github.io/attachments/blogposts/2023/time-for-improvement-game-changer.svg "Push the currently visited file name onto the kill ring."
result: ![](/attachments/blogposts/2023/time-for-improvement-game-changer.svg)"
(interactive) (interactive)
(image-mode-copy-file-name-as-kill)) (unless buffer-file-name
(error "The current buffer doesn't visit an image file"))
(let ((path-from-attachements (qwan/relative-path-to-attachments buffer-file-name)))
(kill-new path-from-attachements)
(message "Copied %s" path-from-attachements)))
(defun qwan/relative-path-to-attachments (full-path) (defun qwan/relative-path-to-attachments (full-path)
@@ -304,14 +309,10 @@ the description. This may destroy existing links, or change their targets so use
(require 'ert) (require 'ert)
(ert-deftest relative-path-to-attachments-removes-prefix () (ert-deftest relative-path-to-attachments-removes-prefix ()
"Building block for creating url to images in the site"
(should (equal (qwan/attachments-remove-prefix-path "prefix/attachments") "/attachments"))) (should (equal (qwan/attachments-remove-prefix-path "prefix/attachments") "/attachments")))
(ert-deftest relative-five-does-not-equal-four () (ert-deftest relative-path-to-attachments-does-not-remove-prefix-when-no-attachments ()
(should (should (equal (qwan/attachments-remove-prefix-path "prefix/somethingelse") "prefix/somethingelse")))
(eql 5 5)))
(ert "relative.*") (ert "relative.*")