From 5091facd7f4ec80cce86049d6d84a164cb017970 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Fri, 21 Oct 2011 17:46:37 +0200 Subject: [PATCH 1/4] org.el: Enable recursive minibuffers in `org-completing-read'. org.el: (org-completing-read): Enable recursive minibuffers and add the `C-c !' key in the minibuffer local map. Thanks to Skip Collins for the idea and to Nick Dokos for the implementation. --- lisp/org.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/org.el b/lisp/org.el index 8ea691c77..81a17f6a3 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9159,10 +9159,12 @@ Use TAB to complete link prefixes, then RET for type-specific completion support (defun org-completing-read (&rest args) "Completing-read with SPACE being a normal character." - (let ((minibuffer-local-completion-map + (let ((enable-recursive-minibuffers t) + (minibuffer-local-completion-map (copy-keymap minibuffer-local-completion-map))) (org-defkey minibuffer-local-completion-map " " 'self-insert-command) (org-defkey minibuffer-local-completion-map "?" 'self-insert-command) + (org-defkey minibuffer-local-completion-map (kbd "C-c !") 'org-time-stamp-inactive) (apply 'org-icompleting-read args))) (defun org-completing-read-no-i (&rest args) From 4c3d289faf5ef4c9badf7a2075885b92c9ee6547 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Fri, 21 Oct 2011 11:15:06 -0600 Subject: [PATCH 2/4] Now allow multiple "var" specifications behind a single ":var" * lisp/ob.el (org-babel-params-from-properties): Now splits multiple var arguments behind a single ":var". (org-babel-balanced-split): Separated balanced splitting of strings out into a new function. (org-babel-parse-multiple-vars): Splits multiple var arguments behind a single ":var". --- lisp/ob.el | 85 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 27 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index f954e7bed..4d8636752 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1047,19 +1047,21 @@ Return an association list of any source block params which may be specified in the properties of the current outline entry." (save-match-data (let (val sym) - (delq nil - (mapcar - (lambda (header-arg) - (and (setq val (org-entry-get (point) header-arg t)) - (cons (intern (concat ":" header-arg)) - (org-babel-read val)))) + (org-babel-parse-multiple-vars + (delq nil (mapcar - 'symbol-name - (append - org-babel-header-arg-names - (progn - (setq sym (intern (concat "org-babel-header-arg-names:" lang))) - (and (boundp sym) (eval sym)))))))))) + (lambda (header-arg) + (and (setq val (org-entry-get (point) header-arg t)) + (cons (intern (concat ":" header-arg)) + (org-babel-read val)))) + (mapcar + 'symbol-name + (append + org-babel-header-arg-names + (progn + (setq sym (intern (concat "org-babel-header-arg-names:" + lang))) + (and (boundp sym) (eval sym))))))))))) (defvar org-src-preserve-indentation) (defun org-babel-parse-src-block-match () @@ -1107,6 +1109,32 @@ may be specified in the properties of the current outline entry." (org-babel-parse-header-arguments (org-babel-clean-text-properties (or (match-string 4) ""))))))) +(defun org-babel-balanced-split (string alts) + "Split STRING on instances of ALTS. +ALTS is a cons of two character options where each option may be +either the numeric code of a single character or a list of +character alternatives. For example to split on balanced +instances of \"[ \t]:\" set ALTS to '((32 9) . 58)." + (flet ((matches (ch spec) (or (and (numberp spec) (= spec ch)) + (member ch spec))) + (matched (ch last) + (and (matches ch (cdr alts)) + (matches last (car alts))))) + (let ((balance 0) (partial nil) (lst nil) (last 0)) + (mapc (lambda (ch) ; split on [] balanced instances of [ \t]: + (setq balance (+ balance + (cond ((equal 91 ch) 1) + ((equal 93 ch) -1) + (t 0)))) + (setq partial (cons ch partial)) + (when (and (= balance 0) (matched ch last)) + (setq lst (cons (apply #'string (nreverse (cddr partial))) + lst)) + (setq partial nil)) + (setq last ch)) + (string-to-list string)) + (nreverse (cons (apply #'string (nreverse partial)) lst))))) + (defun org-babel-parse-header-arguments (arg-string) "Parse a string of header arguments returning an alist." (when (> (length arg-string) 0) @@ -1119,21 +1147,24 @@ may be specified in the properties of the current outline entry." (cons (intern (match-string 1 arg)) (org-babel-read (org-babel-chomp (match-string 2 arg)))) (cons (intern (org-babel-chomp arg)) nil))) - (let ((balance 0) (partial nil) (lst nil) (last 0)) - (mapc (lambda (ch) ; split on [] balanced instances of [ \t]: - (setq balance (+ balance - (cond ((equal 91 ch) 1) - ((equal 93 ch) -1) - (t 0)))) - (setq partial (cons ch partial)) - (when (and (= ch 58) (= balance 0) - (or (= last 32) (= last 9))) - (setq lst (cons (apply #'string (nreverse (cddr partial))) - lst)) - (setq partial (list ch))) - (setq last ch)) - (string-to-list arg-string)) - (nreverse (cons (apply #'string (nreverse partial)) lst))))))) + (org-babel-parse-multiple-vars + (org-babel-balanced-split arg-string '((32 9) . 58))))))) + +(defun org-babel-parse-multiple-vars (header-arguments) + "Expand multiple variable assignments behind a single :var keyword. + +This allows expression of multiple variables with one :var as +shown below. + +#+PROPERTY: var foo=1, bar=2" + (let (results) + (mapc (lambda (pair) + (if (eq (car pair) :var) + (mapcar (lambda (spec) (push (cons :var spec) results)) + (org-babel-balanced-split (cdr pair) '(44 . (32 9)))) + (push pair results))) + header-arguments) + (nreverse results))) (defun org-babel-process-params (params) "Expand variables in PARAMS and add summary parameters." From 0bcb248ee68497fc1eca722eb299ba254bcc726e Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Fri, 21 Oct 2011 11:21:39 -0600 Subject: [PATCH 3/4] quick fix for a tiny bug * lisp/ob.el (org-babel-parse-header-arguments): Quick fix for a tiny bug. --- lisp/ob.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index 4d8636752..274d50a3d 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1138,16 +1138,16 @@ instances of \"[ \t]:\" set ALTS to '((32 9) . 58)." (defun org-babel-parse-header-arguments (arg-string) "Parse a string of header arguments returning an alist." (when (> (length arg-string) 0) - (delq nil - (mapcar - (lambda (arg) - (if (string-match - "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)" - arg) - (cons (intern (match-string 1 arg)) - (org-babel-read (org-babel-chomp (match-string 2 arg)))) - (cons (intern (org-babel-chomp arg)) nil))) - (org-babel-parse-multiple-vars + (org-babel-parse-multiple-vars + (delq nil + (mapcar + (lambda (arg) + (if (string-match + "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)" + arg) + (cons (intern (match-string 1 arg)) + (org-babel-read (org-babel-chomp (match-string 2 arg)))) + (cons (intern (org-babel-chomp arg)) nil))) (org-babel-balanced-split arg-string '((32 9) . 58))))))) (defun org-babel-parse-multiple-vars (header-arguments) From 93bdeb92127fbfd8bc897c26e3dcb6d785da5ccb Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Fri, 21 Oct 2011 11:35:41 -0600 Subject: [PATCH 4/4] two more quick fixes * lisp/ob.el (org-babel-balanced-split): Balance both [] and () groupings. (org-babel-parse-header-arguments): Be sure to replace removed ":" characters. --- lisp/ob.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index 274d50a3d..a5103b287 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1121,10 +1121,10 @@ instances of \"[ \t]:\" set ALTS to '((32 9) . 58)." (and (matches ch (cdr alts)) (matches last (car alts))))) (let ((balance 0) (partial nil) (lst nil) (last 0)) - (mapc (lambda (ch) ; split on [] balanced instances of [ \t]: + (mapc (lambda (ch) ; split on [] or () balanced instances of [ \t]: (setq balance (+ balance - (cond ((equal 91 ch) 1) - ((equal 93 ch) -1) + (cond ((or (equal 91 ch) (equal 40 ch)) 1) + ((or (equal 93 ch) (equal 41 ch)) -1) (t 0)))) (setq partial (cons ch partial)) (when (and (= balance 0) (matched ch last)) @@ -1148,7 +1148,9 @@ instances of \"[ \t]:\" set ALTS to '((32 9) . 58)." (cons (intern (match-string 1 arg)) (org-babel-read (org-babel-chomp (match-string 2 arg)))) (cons (intern (org-babel-chomp arg)) nil))) - (org-babel-balanced-split arg-string '((32 9) . 58))))))) + ((lambda (raw) + (cons (car raw) (mapcar (lambda (r) (concat ":" r)) (cdr raw)))) + (org-babel-balanced-split arg-string '((32 9) . 58)))))))) (defun org-babel-parse-multiple-vars (header-arguments) "Expand multiple variable assignments behind a single :var keyword.