I adopted some part of my patch, and make function name and docstring more clear
after this mail thread long discussion.
From 7e682ccd8d0d2a567de1bbbc0c8e02ee59e156bb Mon Sep 17 00:00:00 2001 From: stardiviner <[email protected]> Date: Fri, 29 May 2020 09:46:15 +0800 Subject: [PATCH] * org-attach.el: add a new command to archive web page
* lisp/org-attach.el (org-attach-url-archive): A new org-attach
dispatcher command to archive web page to a single file.
* lisp/org-agenda.el (org-attach-url-archive-command): A customize
option to specify external command for archiving web page.
* lisp/org-attach.el (org-attach-url-archive-page): A command
invoke external command to offline archive save web page.
---
lisp/org-attach.el | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 57d1360fc..14ac0f828 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -204,6 +204,8 @@ (defcustom org-attach-commands
"Attach a file using symbolic-link method.")
((?u ?\C-u) org-attach-url
"Attach a file from URL (downloading it).")
+ ((?U) org-attach-url-archive
+ "Attach an offline version of web page URL.")
((?b) org-attach-buffer
"Select a buffer and attach its contents to the task.")
((?n ?\C-n) org-attach-new
@@ -467,6 +469,30 @@ (defun org-attach-url (url)
(let ((org-attach-method 'url))
(org-attach-attach url)))
+(defun org-attach-url-archive (url)
+ (interactive "MURL of the web page be archived to attach: \n")
+ (let ((org-attach-method 'archive))
+ (org-attach-attach url)))
+
+(defcustom org-attach-url-archive-command
+ (file-name-nondirectory (executable-find "monolith"))
+ "The command used to offline archive web page."
+ :type 'string
+ :safe #'stringp
+ :group 'org-attach)
+
+(defun org-attach-url-archive-page (url target-file)
+ "Save an offline archive of web page."
+ (pcase org-attach-url-archive-command
+ ("monolith"
+ (make-process
+ :name "org-attach-offline"
+ :command (list org-attach-url-archive-command url "-o" target-file)
+ :sentinel (lambda (proc event) (message "org-attach-offline finished!"))
+ :buffer "*org-attach-url-archive*"))
+ (nil (warn "You must have a command availble for offline save web page!
+Set variable `org-attach-url-archive-command'."))))
+
(defun org-attach-buffer (buffer-name)
"Attach BUFFER-NAME's contents to current outline node.
BUFFER-NAME is a string. Signals a `file-already-exists' error
@@ -504,7 +530,8 @@ (defun org-attach-attach (file &optional visit-dir method)
((eq method 'cp) (copy-file file attach-file))
((eq method 'ln) (add-name-to-file file attach-file))
((eq method 'lns) (make-symbolic-link file attach-file))
- ((eq method 'url) (url-copy-file file attach-file)))
+ ((eq method 'url) (url-copy-file file attach-file))
+ ((eq method 'archive) (org-attach-url-archive-page file attach-file)))
(run-hook-with-args 'org-attach-after-change-hook attach-dir)
(org-attach-tag)
(cond ((eq org-attach-store-link-p 'attached)
--
2.26.2
stardiviner <[email protected]> writes: > I attached the patch. > > I think this feature will be helpful for use who archive web page data usually > like me. To be more portable, I also added an defcustom option for other > external command. And use an if condition to detect whether external command > available, else warning user. -- [ stardiviner ] I try to make every word tell the meaning that I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
signature.asc
Description: PGP signature
