all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [Feature] add a new org-attach dispatcher command to offline save web page
@ 2020-05-27  9:55 stardiviner
  2020-05-28  2:55 ` Matthew Lundin
                   ` (3 more replies)
  0 siblings, 4 replies; 29+ messages in thread
From: stardiviner @ 2020-05-27  9:55 UTC (permalink / raw)
  To: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 553 bytes --]


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
      

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-org-attach.el-add-a-new-command-to-offline-save-web-.patch --]
[-- Type: text/x-patch, Size: 3139 bytes --]

From fcf78b5a5447ae81479e7839df001da659ede5e3 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Wed, 27 May 2020 17:42:24 +0800
Subject: [PATCH] * org-attach.el: add a new command to offline save web page

* lisp/org-attach.el (org-attach-url-offline): A new org-attach
dispatcher command to offline save web page to a single file.

* lisp/org-agenda.el (org-attach-url-offline-command): A customize
option to specify external command for offline save web page.

* lisp/org-attach.el (org-attach-offline-url-with-monolith): A command
invoke external command "monolith" to offline save web page.
---
 lisp/org-attach.el | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 57d1360fc..0d13e0da1 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-offline
+     "Attach an offline version of web page URL (use monolith).")
     ((?b) org-attach-buffer
      "Select a buffer and attach its contents to the task.")
     ((?n ?\C-n) org-attach-new
@@ -467,6 +469,27 @@ (defun org-attach-url (url)
   (let ((org-attach-method 'url))
     (org-attach-attach url)))
 
+(defun org-attach-url-offline (url)
+  (interactive "MURL of the web page be offline to attach: \n")
+  (let ((org-attach-method 'offline))
+    (org-attach-attach url)))
+
+(defcustom org-attach-url-offline-command (executable-find "monolith")
+  "The command used to offline save web page."
+  :type 'string
+  :safe #'stringp
+  :group 'org-attach)
+
+(defun org-attach-offline-url-with-monolith (url target-file)
+  "Save an offline archive of web page with monolith."
+  (if org-attach-url-offline-command
+      (make-process
+       :name "org-attach-offline"
+       :command (list org-attach-url-offline-command url "-o" target-file)
+       :sentinel (lambda (proc event) (message "org-attach-offline finished!"))
+       :buffer "*org-attach-offline*")
+    (warn "You must have a command availble for offline save web page!\n Set variable `org-attach-url-offline-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 +527,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 'offline) (org-attach-offline-url-with-monolith 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


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 515 bytes --]

^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2020-06-03 23:35 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-27  9:55 [Feature] add a new org-attach dispatcher command to offline save web page stardiviner
2020-05-28  2:55 ` Matthew Lundin
2020-05-28  5:49   ` Ihor Radchenko
2020-05-28  6:39     ` stardiviner
2020-05-28 14:03       ` Ihor Radchenko
2020-05-28 16:00         ` stardiviner
2020-05-28 18:16           ` Ihor Radchenko
2020-05-28 16:19     ` Matthew Lundin
2020-05-28 17:11       ` Ihor Radchenko
2020-05-28 22:15         ` Matthew Lundin
2020-05-29  2:15           ` stardiviner
2020-05-29  2:06         ` stardiviner
2020-05-29  2:03       ` stardiviner
2020-05-29  2:17         ` Ihor Radchenko
2020-05-29  6:16           ` stardiviner
2020-05-29 15:33           ` Matthew Lundin
2020-05-29 16:32             ` stardiviner
2020-05-30  6:09             ` Ihor Radchenko
2020-05-28  6:37   ` stardiviner
2020-05-28  6:40   ` stardiviner
2020-05-28 22:24 ` Samuel Wales
2020-05-29  2:23 ` [PATCH updated] " stardiviner
2020-05-29  2:27 ` stardiviner
2020-06-02 12:20   ` Bastien
2020-06-02 14:06     ` stardiviner
2020-06-02 14:26       ` Bastien
2020-06-02 14:40         ` stardiviner
2020-06-03 15:10           ` Bastien
2020-06-03 23:34             ` stardiviner

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.