emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org 1ae801e9c8 2/5: org: Add "mark domain as safe" conv


From: ELPA Syncer
Subject: [elpa] externals/org 1ae801e9c8 2/5: org: Add "mark domain as safe" convenience action
Date: Sat, 17 Sep 2022 07:57:54 -0400 (EDT)

branch: externals/org
commit 1ae801e9c86d5b150fd085230722e4dac550df30
Author: TEC <git@tecosaur.net>
Commit: TEC <git@tecosaur.net>

    org: Add "mark domain as safe" convenience action
    
    * lisp/org.el (org--confirm-resource-safe): Pick out domains from URLs,
    and provide an option of marking that domain as safe.
---
 lisp/org.el | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index bafd6115e1..618e420158 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4566,6 +4566,13 @@ returns non-nil if any of them match."
   "Ask the user if URI should be considered safe, returning non-nil if so."
   (unless noninteractive
     (let ((current-file (and buffer-file-name (file-truename 
buffer-file-name)))
+          (domain (and (string-match
+                        (rx (seq "http" (? "s") "://")
+                            (optional (+ (not (any "@/\n"))) "@")
+                            (optional "www.")
+                            (one-or-more (not (any ":/?\n"))))
+                        uri)
+                       (match-string 0 uri)))
           (buf (get-buffer-create "*Org Remote Resource*")))
       ;; Set up the contents of the *Org Remote Resource* buffer.
       (with-current-buffer buf
@@ -4576,6 +4583,11 @@ returns non-nil if any of them match."
                 "Do you want to download this?  You can type\n "
                 (propertize "!" 'face 'success)
                 " to download this resource, and permanantly mark it as 
safe.\n "
+                (if domain
+                    (concat
+                     (propertize "d" 'face 'success)
+                     " to download this resource, and mark this domain as 
safe.\n ")
+                  "")
                 (propertize "f" 'face 'success)
                 (if current-file
                     (concat
@@ -4593,8 +4605,8 @@ returns non-nil if any of them match."
       ;; Display the buffer and read a choice.
       (save-window-excursion
         (pop-to-buffer buf)
-        (let* ((exit-chars (append '(?y ?n ?! ?\s) (and current-file '(?f))))
-               (prompt (format "Please type y, n%s, or !%s: "
+        (let* ((exit-chars (append '(?y ?n ?! ?d ?\s) (and current-file 
'(?f))))
+               (prompt (format "Please type y, n%s, d, or !%s: "
                                (if current-file ", f" "")
                                (if (< (line-number-at-pos (point-max))
                                       (window-body-height))
@@ -4602,15 +4614,17 @@ returns non-nil if any of them match."
                                  ", or C-v/M-v to scroll")))
                char)
           (setq char (read-char-choice prompt exit-chars))
-          (when (memq char '(?! ?f))
+          (when (memq char '(?! ?f ?d))
             (customize-push-and-save
              'org-safe-remote-resources
-             (list (concat "\\`"
-                           (regexp-quote
-                            (if (and (= char ?f) current-file)
-                                (concat "file://" current-file) uri))
-                           "\\'"))))
-          (prog1 (memq char '(?! ?\s ?y ?f))
+             (list (if (eq char ?d)
+                       (concat "\\`" (regexp-quote domain) "\\(?:/\\|\\'\\)")
+                     (concat "\\`"
+                             (regexp-quote
+                              (if (and (= char ?f) current-file)
+                                  (concat "file://" current-file) uri))
+                             "\\'")))))
+          (prog1 (memq char '(?y ?n ?! ?d ?\s ?f))
             (quit-window t)))))))
 
 (defun org-extract-log-state-settings (x)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]