From 9fdddc291b5bae8516a43a4065e300d356c9c00e Mon Sep 17 00:00:00 2001 From: wasp Date: Thu, 16 May 2024 08:17:43 +0200 Subject: [PATCH] Aggiungi archive-to-org.el Signed-off-by: wasp --- archive-to-org.el | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 archive-to-org.el diff --git a/archive-to-org.el b/archive-to-org.el new file mode 100644 index 0000000..847d083 --- /dev/null +++ b/archive-to-org.el @@ -0,0 +1,35 @@ +(defun replace-in-string (what with in) + "Return a string with WHAT replaced with WITH in IN." + (replace-regexp-in-string (regexp-quote what) with in nil 'literal)) + +(defun www-get-page-title (url) + "Get the title of the page at URL." + (with-current-buffer (url-retrieve-synchronously url) + (goto-char 0) + (re-search-forward "\\(.*\\)<[/]title>" nil t 1) + (decode-coding-string (match-string 1) 'utf-8))) + +(defun wasp/url-to-org (link-url destination-file) + "Save the content of LINK-URL as an org file in DESTINATION-FILE." + (interactive) + (let ((link-title (www-get-page-title link-url)) + (buffer (generate-new-buffer "temp.org")) link-title) + (with-current-buffer buffer + (unless (fboundp 'org-web-tools-insert-web-page-as-entry) + (use-package org-web-tools)) + (org-mode) + (org-web-tools-insert-web-page-as-entry link-url) + (write-region (point-min) (point-max) destination-file) + (kill-buffer)))) + +(defun wasp/archive-url-and-make-entry () + "Archive an url from clipboard to a file. +Defauls to storing in the Org/web directory asking for file name, +then opening a new entry in the daily journal." + (interactive) + (let ((url (gui-get-selection 'CLIPBOARD)) + (destination (concat "~/Org/Web/" (read-string "Enter target file name (without extension):") ".org"))) + (wasp/url-to-org url destination) + (find-file destination))) + +(global-set-key (kbd "C-c p") 'wasp/archive-url-and-make-entry)