From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id yMcxDBFl1l59TwAA0tVLHw (envelope-from ) for ; Tue, 02 Jun 2020 14:41:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id ICPsBxFl1l7URAAAbx9fmQ (envelope-from ) for ; Tue, 02 Jun 2020 14:41:21 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8955A940C03 for ; Tue, 2 Jun 2020 14:41:20 +0000 (UTC) Received: from localhost ([::1]:40908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jg86R-000622-4R for larch@yhetil.org; Tue, 02 Jun 2020 10:41:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jg863-00061h-FV for emacs-orgmode@gnu.org; Tue, 02 Jun 2020 10:40:55 -0400 Received: from [183.249.132.153] (port=1196 helo=localhost) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jg861-0005sW-72; Tue, 02 Jun 2020 10:40:55 -0400 Received: by localhost (Postfix, from userid 1000) id A864F24153A; Tue, 2 Jun 2020 22:40:30 +0800 (CST) References: <87sgflu2gw.fsf@gmail.com> <87mu5rscg7.fsf@gmail.com> <87y2p51wy0.fsf@gnu.org> <87h7vtbm05.fsf@gmail.com> <87o8q1r1bq.fsf@gnu.org> User-agent: mu4e 1.4; emacs 28.0.50 From: stardiviner To: Bastien Subject: Re: [Feature] add a new org-attach dispatcher command to offline save web page In-reply-to: <87o8q1r1bq.fsf@gnu.org> Date: Tue, 02 Jun 2020 22:40:30 +0800 Message-ID: <87eeqxbkf5.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 183.249.132.153 (deferred) Received-SPF: softfail client-ip=183.249.132.153; envelope-from=numbchild@gmail.com; helo=localhost X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/02 09:55:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 53 X-Spam_score: 5.3 X-Spam_bar: +++++ X-Spam_report: (5.3 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, FSL_HELO_NON_FQDN_1=0.001, HELO_LOCALHOST=3.828, NML_ADSP_CUSTOM_MED=0.9, RDNS_NONE=0.793, SPF_SOFTFAIL=0.665, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: reject X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: numbchild@gmail.com Cc: Org Mode Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 1.59 X-TUID: 6CV3iyyXK/1Z =2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Bastien writes: > Hi Stardiviner, > > stardiviner writes: > >> I think maybe Org maintainer can improve the org-attach code to suitable= to add >> custom function.=20 > > 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 =2D From 6c667461b45e93059c6f801e485f7da4bfc3606c Mon Sep 17 00:00:00 2001 From: stardiviner 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. =2D --- 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 =2D --- 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))) =20 +(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 configura= tion. 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 meth= od) ((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)) =2D - ((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 co= py 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) =2D --=20 2.26.2 #+end_src =2D --=20 [ 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 =2D----BEGIN PGP SIGNATURE----- iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl7WZN4UHG51bWJjaGls ZEBnbWFpbC5jb20ACgkQG13xyVromsNmdQgAymuUs1u6lq1Rf8hA2OIRp1I+SC1X v4N1GbG8u94VuMeSHjp8zAliKuYPyBpZ6UhFahvZoXlKUX0jdZMybcQAPDUlRdSg NbC+qJ7OFyuTVMCzPb9RJlHS8lm9oJKWcj6KlMwvOeKoIZUIeCFAV3RW+eM3diso FNfzGOwS97YPHI9KD4IfWpM7UqtYADx3HrKYn1k0X2m46cmoSyF3FNyu9dnYfmaw 5evX62WtWOMNa1eflIO9wBr//e9bJJFSIAI0Rl2sI+/eo5uas4YJ4/ezDsyrd3nL dDb/HywwCXjhgthzKHXQGBgXMyrx+8ZbrDaXz4ywEaUKGVL+5ri54k2Sbg=3D=3D =3DElhx =2D----END PGP SIGNATURE-----