Skip to content

Commit

Permalink
org: Add "mark domain as safe" convenience action
Browse files Browse the repository at this point in the history
* lisp/org.el (org--confirm-resource-safe): Pick out domains from URLs,
and provide an option of marking that domain as safe.
  • Loading branch information
tecosaur committed Sep 17, 2022
1 parent 62a52b5 commit 1ae801e
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions lisp/org.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -4593,24 +4605,26 @@ 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))
""
", 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)
Expand Down

0 comments on commit 1ae801e

Please sign in to comment.