From b485706910cd051cb53301805c64c84ec1a1ad5e Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 10 Jan 2023 14:52:20 +0000 Subject: [PATCH] Add interactive wrapper around path function copied from image-file-name added test to see that file name unchanged when no attachments --- config.el | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/config.el b/config.el index b2b1c4d..8e6531d 100644 --- a/config.el +++ b/config.el @@ -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 () - "example: /Users/willem/MyDocuments/qwan/sites/qwaneu.github.io/attachments/blogposts/2023/time-for-improvement-game-changer.svg - result: ![](/attachments/blogposts/2023/time-for-improvement-game-changer.svg)" + "Push the currently visited file name onto the kill ring." (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) @@ -304,14 +309,10 @@ the description. This may destroy existing links, or change their targets so use (require 'ert) (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"))) -(ert-deftest relative-five-does-not-equal-four () - (should - (eql 5 5))) - - +(ert-deftest relative-path-to-attachments-does-not-remove-prefix-when-no-attachments () + (should (equal (qwan/attachments-remove-prefix-path "prefix/somethingelse") "prefix/somethingelse"))) (ert "relative.*")