Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions org-cliplink.el
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,6 @@ TITLE-REGEXP does not match TITLE, return the original TITLE."
org-cliplink-max-length))
(format "[[%s]]" url)))

(defun org-cliplink-insert-org-mode-link-callback (url title)
(insert (org-cliplink-org-mode-link-transformer url title)))

(defun org-cliplink-uncompress-gziped-text (text)
(let ((filename (make-temp-file "org-cliplink" nil ".gz")))
(write-region text nil filename)
Expand Down Expand Up @@ -562,10 +559,18 @@ TITLE-REGEXP does not match TITLE, return the original TITLE."
"Takes the URL, asynchronously retrieves the title and applies
a custom TRANSFORMER which transforms the url and title and insert
the required text to the current buffer."
(org-cliplink-retrieve-title
url
(lambda (url title)
(insert (funcall transformer url title)))))
(let ((m (point-marker)))
(org-cliplink-retrieve-title
url
(lambda (url title)
(let ((save-and-restore-position (/= (point) m))
(link (funcall transformer url title)))
(if save-and-restore-position
(save-excursion
(goto-char m)
(insert link))
(insert link))
(set-marker m nil))))))

;;;###autoload
(defun org-cliplink-retrieve-title-synchronously (url)
Expand Down
9 changes: 0 additions & 9 deletions test/org-cliplink-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@
"&[Hello] '[World] α  ")))
(should (not (org-cliplink-escape-html4 nil))))

(ert-deftest org-cliplink-insert-org-mode-link-callback-test ()
(with-temp-buffer
(org-cliplink-insert-org-mode-link-callback "http://google.com/" "Google")
(should (equal (buffer-string) "[[http://google.com/][Google]]")))

(with-temp-buffer
(org-cliplink-insert-org-mode-link-callback "http://google.com" nil)
(should (equal (buffer-string) "[[http://google.com]]"))))

(ert-deftest org-cliplink-uncompress-gziped-text-test ()
(let ((gziped-content (concat "\x1F\x8B\x08\x00\xD8\x8B"
"\x74\x55\x00\x03\xCB\x48"
Expand Down