From: Aaron Ecay <aaronecay@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH 2/3] Mark some org-babel variables as safe locals under proper conditions
Date: Wed, 30 Oct 2013 00:19:08 -0400 [thread overview]
Message-ID: <8761sfcrwj.fsf@gmail.com> (raw)
In-Reply-To: <8761sfcykv.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
Hi Eric,
Thanks for the feedback. You are right that this could be more
extensible. I’m attaching a new version of patches #2 and 3 to this
email, which should be an improvement on that front. I also added
docstrings, and a test.
Aaron
PS You were right about org-every vs. mapcar in your other message.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Mark-some-org-babel-variables-as-safe-locals-under-p.patch --]
[-- Type: text/x-diff, Size: 5344 bytes --]
From 1ca6369721eeadded29fc538b996267ff88a38b9 Mon Sep 17 00:00:00 2001
From: Aaron Ecay <aaronecay@gmail.com>
Date: Mon, 28 Oct 2013 15:39:31 -0400
Subject: [PATCH 2/3] Mark some org-babel variables as safe locals under proper
conditions
* lisp/ob-core.el (org-babel-inline-result-wrap,
org-babel-default-header-args,
org-babel-default-inline-header-args): mark as safe local variables
---
lisp/ob-core.el | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
testing/lisp/test-ob.el | 21 +++++++++++++++++
2 files changed, 84 insertions(+)
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 8fafd4b..b1a6871 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -158,6 +158,11 @@ See also `org-babel-noweb-wrap-start'."
This string must include a \"%s\" which will be replaced by the results."
:group 'org-babel
:type 'string)
+(put 'org-babel-inline-result-wrap
+ 'safe-local-variable
+ (lambda (value)
+ (and (stringp value)
+ (string-match-p "%s" value))))
(defun org-babel-noweb-wrap (&optional regexp)
(concat org-babel-noweb-wrap-start
@@ -484,10 +489,14 @@ specific header arguments as well.")
'((:session . "none") (:results . "replace") (:exports . "code")
(:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no"))
"Default arguments to use when evaluating a source block.")
+(put 'org-babel-default-header-args 'safe-local-variable
+ (org-babel-header-args-safe-fn org-babel-safe-header-args))
(defvar org-babel-default-inline-header-args
'((:session . "none") (:results . "replace") (:exports . "results"))
"Default arguments to use when evaluating an inline source block.")
+(put 'org-babel-default-inline-header-args 'safe-local-variable
+ (org-babel-header-args-safe-fn org-babel-safe-header-args))
(defvar org-babel-data-names '("tblname" "results" "name"))
@@ -2785,6 +2794,60 @@ of `org-babel-temporary-directory'."
(add-hook 'kill-emacs-hook 'org-babel-remove-temporary-directory)
+(defconst org-babel-safe-header-args
+ '(:cache :colnames :comments :exports :epilogue :hlines :noeval
+ :noweb :noweb-ref :noweb-sep :padline :prologue :rownames
+ :sep :session :tangle :wrap
+ (:eval . ("never" "query"))
+ (:results . (lambda (str) (not (string-match "file" str)))))
+ "A list of safe header arguments for babel source blocks.
+
+The list can have entries of the following forms:
+- :ARG -> :ARG is always a safe header arg
+- (:ARG . (VAL1 VAL2 ...)) -> :ARG is safe as a header arg if it is
+ `equal' to one of the VALs.
+- (:ARG . FN) -> :ARG is safe as a header arg if the function FN
+ returns non-nil. FN is passed one
+ argument, the value of the header arg
+ (as a string).")
+
+(defun org-babel-one-header-arg-safe-p (pair safe-list)
+ "Determine if the PAIR is a safe babel header arg according to SAFE-LIST.
+
+For the format of SAFE-LIST, see `org-babel-safe-header-args'."
+ (and (consp pair)
+ (keywordp (car pair))
+ (stringp (cdr pair))
+ (or
+ (memq (car pair) safe-list)
+ (let ((entry (assq (car pair) safe-list)))
+ (and entry
+ (consp entry)
+ (cond ((functionp (cdr entry))
+ (funcall (cdr entry) (cdr pair)))
+ ((listp (cdr entry))
+ (member (cdr pair) (cdr entry)))
+ (t nil)))))))
+
+(defmacro org-babel-header-args-safe-fn (safe-list)
+ "Return a function that determines whether a list of header args are safe.
+
+Intended usage is:
+\(put 'org-babel-default-header-args 'safe-local-variable
+ (org-babel-header-args-safe-p org-babel-safe-header-args)
+
+This allows org-babel languages to extend the list of safe values for
+their `org-babel-default-header-args:foo' variable.
+
+For the format of SAFE-LIST, see `org-babel-safe-header-args'."
+ `(lambda (value)
+ (and (listp value)
+ (org-every
+ (lambda (pair)
+ (and (consp pair)
+ (org-babel-one-header-arg-safe-p pair ,safe-list)))
+ value))))
+
(provide 'ob-core)
;; Local variables:
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 93c026b..e7f0645 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1181,6 +1181,27 @@ echo \"$data\"
(list (org-get-indentation)
(progn (forward-line) (org-get-indentation)))))))
+(ert-deftest test-ob/safe-header-args ()
+ "Detect safe and unsafe header args."
+ (let ((safe-args '((:cache . "foo")
+ (:results . "output")
+ (:eval . "never")
+ (:eval . "query")))
+ (unsafe-args '((:eval . "yes")
+ (:results . "output file")
+ (:foo . "bar")))
+ (malformed-args '((bar . "foo")
+ ("foo" . "bar")
+ :foo))
+ (safe-p (org-babel-header-args-safe-fn org-babel-safe-header-args)))
+ (dolist (arg safe-args)
+ (should (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args)))
+ (dolist (arg unsafe-args)
+ (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
+ (dolist (arg malformed-args)
+ (should (not (org-babel-one-header-arg-safe-p arg org-babel-safe-header-args))))
+ (should (not (funcall safe-p (append safe-args unsafe-args))))))
+
(provide 'test-ob)
;;; test-ob ends here
--
1.8.4.2
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0003-mark-o-b-default-header-args-R-as-a-safe-local-under.patch --]
[-- Type: text/x-diff, Size: 1297 bytes --]
From f756b6f8a5704404323f9600af278292734d2ea5 Mon Sep 17 00:00:00 2001
From: Aaron Ecay <aaronecay@gmail.com>
Date: Mon, 28 Oct 2013 15:40:32 -0400
Subject: [PATCH 3/3] mark o-b-default-header-args:R as a safe local under
proper conditions
* lisp/ob-R.el (org-babel-default-header-args:R): mark as a safe local
variable
---
lisp/ob-R.el | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 74d7513..2321f64 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -65,7 +65,20 @@
(output value graphics))))
"R-specific header arguments.")
+(defconst ob-R-safe-header-args
+ (append org-babel-safe-header-args
+ '(:width :height :bg :units :pointsize :antialias :quality
+ :compression :res :type :family :title :fonts
+ :version :paper :encoding :pagecentre :colormodel
+ :useDingbats :horizontal))
+ "Header args which are safe for R babel blocks.
+
+See `org-babel-safe-header-args' for documentation of the format of
+this variable.")
+
(defvar org-babel-default-header-args:R '())
+(put 'org-babel-default-header-args:R 'safe-local-variable
+ (org-babel-header-args-safe-fn ob-R-safe-header-args))
(defcustom org-babel-R-command "R --slave --no-save"
"Name of command to use for executing R code."
--
1.8.4.2
[-- Attachment #4: Type: text/plain, Size: 15 bytes --]
--
Aaron Ecay
next prev parent reply other threads:[~2013-10-30 4:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-28 20:19 [PATCH 0/3] Safe local variable declarations Aaron Ecay
2013-10-28 20:19 ` [PATCH 1/3] Mark ox-latex variables safe locals under proper conditions Aaron Ecay
2013-10-29 8:24 ` Nicolas Goaziou
2013-10-30 4:15 ` Aaron Ecay
2013-10-30 8:35 ` Nicolas Goaziou
2013-10-28 20:19 ` [PATCH 2/3] Mark some org-babel variables as " Aaron Ecay
2013-10-30 1:50 ` Eric Schulte
2013-10-30 4:19 ` Aaron Ecay [this message]
2013-10-30 18:02 ` Eric Schulte
2013-10-28 20:19 ` [PATCH 3/3] mark o-b-default-header-args:R as a safe local " Aaron Ecay
2013-10-30 1:54 ` Eric Schulte
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=8761sfcrwj.fsf@gmail.com \
--to=aaronecay@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=schulte.eric@gmail.com \
/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).