From: stardiviner <numbchild@gmail.com>
To: Bastien <bzg@gnu.org>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: [Feature] add a new org-attach dispatcher command to offline save web page
Date: Tue, 02 Jun 2020 22:40:30 +0800 [thread overview]
Message-ID: <87eeqxbkf5.fsf@gmail.com> (raw)
In-Reply-To: <87o8q1r1bq.fsf@gnu.org>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Bastien <bzg@gnu.org> writes:
> Hi Stardiviner,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> I think maybe Org maintainer can improve the org-attach code to suitable to add
>> custom function.
>
> Sorry, I don't understand.
>
> Can you to use M-x customize-option RET org-attach-commands RET then
> add a custom command pointing to the command you have written, bound
> to a keybinding of your choice?
>
> If something does not work with this approach, can you show me what
> you tried and what does not work?
Here is my patch, I try to annotate on my patch code to express my words:
#+begin_src diff
- From 6c667461b45e93059c6f801e485f7da4bfc3606c Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
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 | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 57d1360fc..80855d147 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.") <----- This `org-attach-commands' is an option which indeead can be customized.
((?b) org-attach-buffer
"Select a buffer and attach its contents to the task.")
((?n ?\C-n) org-attach-new
@@ -467,6 +469,31 @@ (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 | You can see, all those function code can be put in user configuration. Yes.
+ (file-name-nondirectory (executable-find "monolith")) |
+ "The command used to offline archive web page. |
+monolith can be found here: https://github.com/Y2Z/monolith." |
+ :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 +531,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)) <-------------- But this can't be don'e through advice or something else. Unless copy whole function code.
+ ((eq method 'archive) (org-attach-url-archive-page file attach-file))) In my less elisp knowledge, I don't have any idea how to add a new org-attach method in `org-attach-attach'.
(run-hook-with-args 'org-attach-after-change-hook attach-dir) Maybe you have better idea. I might consider publish this as a tiny Emacs extension.
(org-attach-tag)
(cond ((eq org-attach-store-link-p 'attached)
- --
2.26.2
#+end_src
- --
[ 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
-----BEGIN PGP SIGNATURE-----
iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl7WZN4UHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsNmdQgAymuUs1u6lq1Rf8hA2OIRp1I+SC1X
v4N1GbG8u94VuMeSHjp8zAliKuYPyBpZ6UhFahvZoXlKUX0jdZMybcQAPDUlRdSg
NbC+qJ7OFyuTVMCzPb9RJlHS8lm9oJKWcj6KlMwvOeKoIZUIeCFAV3RW+eM3diso
FNfzGOwS97YPHI9KD4IfWpM7UqtYADx3HrKYn1k0X2m46cmoSyF3FNyu9dnYfmaw
5evX62WtWOMNa1eflIO9wBr//e9bJJFSIAI0Rl2sI+/eo5uas4YJ4/ezDsyrd3nL
dDb/HywwCXjhgthzKHXQGBgXMyrx+8ZbrDaXz4ywEaUKGVL+5ri54k2Sbg==
=Elhx
-----END PGP SIGNATURE-----
next prev parent reply other threads:[~2020-06-02 14:41 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2020-06-03 15:10 ` Bastien
2020-06-03 23:34 ` stardiviner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87eeqxbkf5.fsf@gmail.com \
--to=numbchild@gmail.com \
--cc=bzg@gnu.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).