From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id cDNqM4G/nGLn3gAAbAwnHQ (envelope-from ) for ; Sun, 05 Jun 2022 16:36:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id WFVrMoG/nGIYIwEAG6o9tA (envelope-from ) for ; Sun, 05 Jun 2022 16:36:49 +0200 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 346B42AD46 for ; Sun, 5 Jun 2022 16:36:49 +0200 (CEST) Received: from localhost ([::1]:44708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxrN2-0002Qm-A2 for larch@yhetil.org; Sun, 05 Jun 2022 10:36:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxrM6-0002Pf-Jp for emacs-orgmode@gnu.org; Sun, 05 Jun 2022 10:35:50 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:41931) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxrM4-0003ul-EV for emacs-orgmode@gnu.org; Sun, 05 Jun 2022 10:35:50 -0400 Received: by mail-pg1-x535.google.com with SMTP id e66so10960371pgc.8 for ; Sun, 05 Jun 2022 07:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:user-agent:message-id:mime-version; bh=i6+ZhsZtQI8dVCAInl2vLgZWIhQarCbLSJWQZ/i1CsU=; b=iJ+V5DLGC7DivHE2z5azN+jnoCfftBWGFT65207wzOZuL2aUkkK/phP3d6Hh/61Xpt x/vmYlw7H4oOAokB0hVnGLaYtFRomA8ve83OMB+WjoTo81gZs2S5U6haFq7W0YTN2gOz /lIrCGG2yewSt6m8QqH7LLyquaJzPBUAPTOibDHMfvC1HxoblGS1zR1qNLDCzrV5rR/C /POOXbuAXSoXEilTQ2UC748Tk5Cfe0q1KbUIMTA/YurtKmnMG9O3t68KFyoICfcJOJm5 zVN9JncHzJW5kPeZeNkvViAk0GEmTFeMENvsko8X+0Q79u1MbO8e2tgv5jTWX0zDZQlc C+EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:user-agent:message-id :mime-version; bh=i6+ZhsZtQI8dVCAInl2vLgZWIhQarCbLSJWQZ/i1CsU=; b=ACEjQl/bbjjLbBIGUJrXrFugpuYZqoyhNntnOlq2TX7fftlTtPPNNyBx4NQRYsrhc+ csXWCJ+S3VAhyEmLA/+da7yh3aDfcbo7M9kfOqeDXvqfYiG9pXO9IWmJw6NCNmM2Rp/T uFRE4nka4BMxatmDQmRhUPV3z5zORVcnGmJvnOe7weSKJy2o3bN6kzjVu6OdiHD+N0TS /QmcU8NBRVZuRwbPITwNBTVMkvAx61w+lfOEa2JGKhb4B7x429YV50jdcN5KDiYySSAs IDuseavE4RXVm5buEhvSci9o56HCu8O/uSGkjCeVs0TTyJJVG0H05C59E0vmvW7qFms+ BuJw== X-Gm-Message-State: AOAM533tmr8JYP4PAn9CSIapb3ynJzKf1zAGLMffL69UAXydKc77tdF4 Gt9VNxLgy4wRjx0OT/+qZCE0Il9OHNw= X-Google-Smtp-Source: ABdhPJzOnyWNj+xEL2Pd0M46NsPl7yYcgQCiVkx+PeTPDYP7305p4b81FwpBpFIQ2SYus3epMCXt+A== X-Received: by 2002:a05:6a00:21c8:b0:4fd:f89f:ec0e with SMTP id t8-20020a056a0021c800b004fdf89fec0emr19797728pfj.83.1654439746607; Sun, 05 Jun 2022 07:35:46 -0700 (PDT) Received: from localhost (2403-580e-91f7--124.ip6.aussiebb.net. [2403:580e:91f7::124]) by smtp.gmail.com with ESMTPSA id f8-20020a056a001ac800b0051b516fd1dcsm9542929pfv.91.2022.06.05.07.35.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 07:35:46 -0700 (PDT) From: Timothy To: Org Mode Subject: [PATCH] Support #+include-ing URLs Date: Sun, 05 Jun 2022 22:32:30 +0800 User-agent: mu4e 1.6.10; emacs 28.0.92 Message-ID: <87k09v5gap.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=tecosaur@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1654439809; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=i6+ZhsZtQI8dVCAInl2vLgZWIhQarCbLSJWQZ/i1CsU=; b=NUeVhd8sYEj3biZWIf7fwdZKF5n308GNgUiWyANreiygeGQJwRJCPeaKayWJEgObsm2QUV eMuxf5714N7kYQOAiy8C+jkJc6otOV1G7F8az7dK7TKgZ9us8u6jYp3eBblQhbg+xiuyNY 4AvlFURDkgGtslQeZmSLd0Ui6R8FzysrHPIJblS2pK7evT++cKAiQ4NpHDyjhi5HWdbZBU fKUF4MVbgho319ICsHV5XQjaBR0n4PhAjG3azu9Rt0k2XU77mNfAXbApu/i8vHLnII5wRj ybdlVZiu6IuTB9Hl37UrHyWPI+2xLez2vOVIAtTBJOR+VsTqBWIW39VXWQkN1Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654439809; a=rsa-sha256; cv=none; b=qzk4UxfR4mNBQ+JafqHkTyeKHqYBRyeHvWnIPmMPbLqSq6oDyDfUqqPhYPPgiHq10jPMK4 Q53Dzgp0Avd42VZvJHEKwWKJesFUu6OS/xMDWcu2QhG/RWrT6IDvkUR1ES6yqnz5GJ7pEA KRhtXIn9y8kK2qhkImCMQpsVuOVpys1aKJUFOi7A4464yL0MAB20yJ3slFobCY103OSO+P oOqdU4mBivTXN1v1jEn1g6iZ3A3Bb4/7XTmOSkIL4fXxKqN1/CvDzA3970YdKlFKJS8LWP iG/YwqMKibAbyrA8+QI2foVrpSh589RoAvcbDfoYYh9lPUVrGOATezCjkqP4hA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iJ+V5DLG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.51 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iJ+V5DLG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 346B42AD46 X-Spam-Score: -2.51 X-Migadu-Scanner: scn1.migadu.com X-TUID: tWfVgwm7G4vc --=-=-= Content-Type: multipart/alternative; boundary="==-=-=" --==-=-= Content-Type: text/plain Content-Disposition: inline Hi All, This is just a little patchset to treat `#+include: URL' the same way as `#+setupfile: URL'. All the usual `#+include:' bells and whistles (`::*Heading', `:lines', etc.) work as normal. All the best, Timothy --==-=-= Content-Type: text/html Content-Disposition: inline

Hi All,

This is just a little patchset to treat #+include: URL the same way as #+setupfile: URL. All the usual #+include: bells and whistles (::*Heading, :lines, etc.) work as normal.

All the best,
Timothy

--==-=-=-- --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-org-lint-don-t-complain-about-include-URL.patch >From df0b382e43cf44860247fafd14bd2932fe3ed026 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 5 Jun 2022 22:28:39 +0800 Subject: [PATCH 2/2] org-lint: don't complain about #+include URL * lisp/org-lint.el (org-lint-wrong-include-link-parameter): When the included file is a URL, skip the usual file checks. --- lisp/org-lint.el | 67 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/lisp/org-lint.el b/lisp/org-lint.el index cce6fddbd..1e0dba4a0 100644 --- a/lisp/org-lint.el +++ b/lisp/org-lint.el @@ -649,39 +649,40 @@ (defun org-lint-wrong-include-link-parameter (ast) (org-element-map ast 'keyword (lambda (k) (when (equal (org-element-property :key k) "INCLUDE") - (let* ((value (org-element-property :value k)) - (path - (and (string-match "^\\(\".+\"\\|\\S-+\\)[ \t]*" value) - (save-match-data - (org-strip-quotes (match-string 1 value)))))) - (if (not path) - (list (org-element-property :post-affiliated k) - "Missing location argument in INCLUDE keyword") - (let* ((file (org-string-nw-p - (if (string-match "::\\(.*\\)\\'" path) - (substring path 0 (match-beginning 0)) - path))) - (search (and (not (equal file path)) - (org-string-nw-p (match-string 1 path))))) - (if (and file - (not (file-remote-p file)) - (not (file-exists-p file))) - (list (org-element-property :post-affiliated k) - "Non-existent file argument in INCLUDE keyword") - (let* ((visiting (if file (find-buffer-visiting file) - (current-buffer))) - (buffer (or visiting (find-file-noselect file))) - (org-link-search-must-match-exact-headline t)) - (unwind-protect - (with-current-buffer buffer - (when (and search - (not (ignore-errors - (org-link-search search nil t)))) - (list (org-element-property :post-affiliated k) - (format - "Invalid search part \"%s\" in INCLUDE keyword" - search)))) - (unless visiting (kill-buffer buffer)))))))))))) + (let* ((value (org-element-property :value k)) + (path + (and (string-match "^\\(\".+\"\\|\\S-+\\)[ \t]*" value) + (save-match-data + (org-strip-quotes (match-string 1 value)))))) + (if (not path) + (list (org-element-property :post-affiliated k) + "Missing location argument in INCLUDE keyword") + (let* ((file (org-string-nw-p + (if (string-match "::\\(.*\\)\\'" path) + (substring path 0 (match-beginning 0)) + path))) + (search (and (not (equal file path)) + (org-string-nw-p (match-string 1 path))))) + (unless (org-url-p file) + (if (and file + (not (file-remote-p file)) + (not (file-exists-p file))) + (list (org-element-property :post-affiliated k) + "Non-existent file argument in INCLUDE keyword") + (let* ((visiting (if file (find-buffer-visiting file) + (current-buffer))) + (buffer (or visiting (find-file-noselect file))) + (org-link-search-must-match-exact-headline t)) + (unwind-protect + (with-current-buffer buffer + (when (and search + (not (ignore-errors + (org-link-search search nil t)))) + (list (org-element-property :post-affiliated k) + (format + "Invalid search part \"%s\" in INCLUDE keyword" + search)))) + (unless visiting (kill-buffer buffer))))))))))))) (defun org-lint-obsolete-include-markup (ast) (let ((regexp (format "\\`\\(?:\".+\"\\|\\S-+\\)[ \t]+%s" -- 2.36.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ox-Support-include-ing-URLs.patch >From 2e2189c451c8e8bbd8461a626fe63e5e97dd4a07 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 5 Jun 2022 22:25:22 +0800 Subject: [PATCH 1/2] ox: Support #+include-ing URLs * lisp/ox.el (org-export--prepare-file-contents, org-export--inclusion-absolute-lines): Replace instances of `(insert-file-contents FILE)' with `(insert (org-file-contents FILE))', as in `org--collect-keywords-1'. (org-export-expand-include-keyword): Tweak to accept a URL as FILE, and not perform the standard "file exists and is readable" check. * etc/ORG-NEWS: Mention this change in behaviour. --- etc/ORG-NEWS | 3 +++ lisp/ox.el | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 35af94f92..397cb668c 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -219,6 +219,9 @@ blocks to LaTeX. This requires the =fvextra=, =float=, and (by default, but not necessarily) =tcolorbox= LaTeX packages be installed. It uses Emacs' font-lock information, and so tends to produce results superior to Minted or Listings. +*** Support for =#+include=-ing URLs + +=#+include: FILE= will now accept URLs as the file. ** New functions and changes in function arguments diff --git a/lisp/ox.el b/lisp/ox.el index 9a8e63046..fc0ee671f 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3229,15 +3229,18 @@ (defun org-export-expand-include-keyword (&optional included dir footnotes) value) (prog1 (save-match-data - (let ((matched (match-string 1 value))) + (let ((matched (match-string 1 value)) + stripped) (when (string-match "\\(::\\(.*?\\)\\)\"?\\'" matched) (setq location (match-string 2 matched)) (setq matched (replace-match "" nil nil matched 1))) - (expand-file-name (org-strip-quotes matched) - dir))) - (setq value (replace-match "" nil nil value))))) + (setq stripped (org-strip-quotes matched)) + (if (org-url-p stripped) + stripped + (expand-file-name stripped dir)))) + (setq value (replace-match "" nil nil value))))) (only-contents (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?" value) @@ -3273,7 +3276,7 @@ (defun org-export-expand-include-keyword (&optional included dir footnotes) (delete-region (point) (line-beginning-position 2)) (cond ((not file) nil) - ((not (file-readable-p file)) + ((and (not (org-url-p file)) (not (file-readable-p file))) (error "Cannot include file %s" file)) ;; Check if files has already been parsed. Look after ;; inclusion lines too, as different parts of the same @@ -3319,8 +3322,9 @@ (defun org-export-expand-include-keyword (&optional included dir footnotes) includer-file))) (org-export-expand-include-keyword (cons (list file lines) included) - (file-name-directory file) - footnotes) + (unless (org-url-p file) + (file-name-directory file)) + footnotes) (buffer-string))))) ;; Expand footnotes after all files have been ;; included. Footnotes are stored at end of buffer. @@ -3343,7 +3347,7 @@ (defun org-export--inclusion-absolute-lines (file location only-contents lines) Return a string of lines to be included in the format expected by `org-export--prepare-file-contents'." (with-temp-buffer - (insert-file-contents file) + (insert (org-file-contents file)) (unless (eq major-mode 'org-mode) (let ((org-inhibit-startup t)) (org-mode))) (condition-case err @@ -3448,7 +3452,7 @@ (defun org-export--prepare-file-contents Optional argument INCLUDER is the file name where the inclusion is to happen." (with-temp-buffer - (insert-file-contents file) + (insert (org-file-contents file)) (when lines (let* ((lines (split-string lines "-")) (lbeg (string-to-number (car lines))) -- 2.36.1 --=-=-=--