Function: org-capture-expand-embedded-elisp

org-capture-expand-embedded-elisp is a byte-compiled function defined in org-capture.el.gz.

Signature

(org-capture-expand-embedded-elisp &optional MARK)

Documentation

Evaluate embedded elisp %(sexp) and replace with the result.

When optional MARK argument is non-nil, mark Sexp with a text property (org-embedded-elisp) for later evaluation. Only marked Sexp are evaluated when this argument is nil.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-capture.el.gz
(defun org-capture-expand-embedded-elisp (&optional mark)
  "Evaluate embedded elisp %(sexp) and replace with the result.
When optional MARK argument is non-nil, mark Sexp with a text
property (`org-embedded-elisp') for later evaluation.  Only
marked Sexp are evaluated when this argument is nil."
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "%(" nil t)
      (cond
       ((get-text-property (match-beginning 0) 'org-embedded-elisp)
	(goto-char (match-beginning 0))
	(let ((template-start (point)))
	  (forward-char 1)
	  (let* ((sexp (read (current-buffer)))
		 (result (org-eval
			  (org-capture--expand-keyword-in-embedded-elisp
			   sexp))))
	    (delete-region template-start (point))
	    (cond
	     ((not result) nil)
	     ((stringp result) (insert result))
	     (t (error
		 "Capture template sexp `%s' must evaluate to string or nil"
		 sexp))))))
       ((not mark) nil)
       ;; Only mark valid and non-escaped sexp.
       ((org-capture-escaped-%) nil)
       (t
	(let ((end (with-syntax-table emacs-lisp-mode-syntax-table
		     (ignore-errors (scan-sexps (1- (point)) 1)))))
	  (when end
	    (put-text-property (- (point) 2) end 'org-embedded-elisp t))))))))