Sfoglia il codice sorgente

Merge branch 'master' of orgmode.org:org-mode

Max Mikhanosha 12 anni fa
parent
commit
5cf92f16f7

+ 93 - 10
contrib/lisp/org-mac-link-grabber.el

@@ -128,21 +128,36 @@ applications and inserting them in org documents"
   :group 'org-mac-link-grabber
   :type 'boolean)
 
+(defcustom org-mac-grab-Skim-app-p
+  (< 0 (length (shell-command-to-string
+		"mdfind kMDItemCFBundleIdentifier == 'net.sourceforge.skim-app.skim'")))
+  "Enable menu option [S]kim to grab page links from Skim.app"
+  :tag "Grab Skim.app page links"
+  :group 'org-mac-link-grabber
+  :type 'boolean)
+
+(defcustom org-mac-Skim-highlight-selection-p nil
+  "Highlight (using notes) the selection (if present) when grabbing the a link from Skim.app"
+  :tag "Highlight selection in Skim.app"
+  :group 'org-mac-link-grabber
+  :type 'boolean)
+
 
 (defun omlg-grab-link ()
   "Prompt the user for an application to grab a link from, then go grab the link, and insert it at point"
   (interactive)
   (let* ((descriptors `(("F" "inder" org-mac-finder-insert-selected ,org-mac-grab-Finder-app-p)
-						("m" "ail" org-mac-message-insert-selected ,org-mac-grab-Mail-app-p)
-						("a" "ddressbook" org-mac-addressbook-insert-selected ,org-mac-grab-Addressbook-app-p)
-						("s" "afari" org-mac-safari-insert-frontmost-url ,org-mac-grab-Safari-app-p)
-						("f" "irefox" org-mac-firefox-insert-frontmost-url ,org-mac-grab-Firefox-app-p)
-						("v" "imperator" org-mac-vimperator-insert-frontmost-url ,org-mac-grab-Firefox+Vimperator-p)
-						("c" "hrome" org-mac-chrome-insert-frontmost-url ,org-mac-grab-Chrome-app-p)
-						("t" "ogether" org-mac-together-insert-selected ,org-mac-grab-Together-app-p)))
+			("m" "ail" org-mac-message-insert-selected ,org-mac-grab-Mail-app-p)
+			("a" "ddressbook" org-mac-addressbook-insert-selected ,org-mac-grab-Addressbook-app-p)
+			("s" "afari" org-mac-safari-insert-frontmost-url ,org-mac-grab-Safari-app-p)
+			("f" "irefox" org-mac-firefox-insert-frontmost-url ,org-mac-grab-Firefox-app-p)
+			("v" "imperator" org-mac-vimperator-insert-frontmost-url ,org-mac-grab-Firefox+Vimperator-p)
+			("c" "hrome" org-mac-chrome-insert-frontmost-url ,org-mac-grab-Chrome-app-p)
+			("t" "ogether" org-mac-together-insert-selected ,org-mac-grab-Together-app-p)
+			("S" "kim" org-mac-skim-insert-page ,org-mac-grab-Skim-app-p)))
 		 (menu-string (make-string 0 ?x))
 		 input)
-
+    
 	;; Create the menu string for the keymap
 	(mapc '(lambda (descriptor)
 			(when (elt descriptor 3)
@@ -209,8 +224,9 @@ applications and inserting them in org documents"
 					 "	activate\n"
 					 "	delay 0.15\n"
 					 "	tell application \"System Events\"\n"
-					 "		keystroke \"l\" using command down\n"
-					 "		keystroke \"c\" using command down\n"
+					 "		keystroke \"l\" using {command down}\n"
+					 "		keystroke \"a\" using {command down}\n"
+					 "		keystroke \"c\" using {command down}\n"
 					 "	end tell\n"
 					 "	delay 0.15\n"
 					 "	set theUrl to the clipboard\n"
@@ -460,6 +476,73 @@ applications and inserting them in org documents"
   (interactive)
   (insert (org-mac-addressbook-item-get-selected)))
 
+;;
+;;
+;; Handle links from Skim.app
+;;
+;; Original code & idea by Christopher Suckling (org-mac-protocol)
+
+(org-add-link-type "skim" 'org-mac-skim-open)
+
+(defun org-mac-skim-open (uri)
+  "Visit page of pdf in Skim"
+  (let* ((page (when (string-match "::\\(.+\\)\\'" uri)
+		 (match-string 1 uri)))
+	 (document (substring uri 0 (match-beginning 0))))
+    (do-applescript
+     (concat
+      "tell application \"Skim\"\n"
+         "activate\n"
+	 "set theDoc to \"" document "\"\n"
+	 "set thePage to " page "\n"
+	 "open theDoc\n"
+	 "go document 1 to page thePage of document 1\n"
+      "end tell"))))
+
+
+(defun as-get-skim-page-link ()
+  (do-applescript
+   (concat
+    "tell application \"Skim\"\n"
+       "set theDoc to front document\n"
+       "set theTitle to (name of theDoc)\n"
+       "set thePath to (path of theDoc)\n"
+       "set thePage to (get index for current page of theDoc)\n"
+       "set theSelection to selection of theDoc\n"
+       "set theContent to contents of (get text for theSelection)\n"
+       "if theContent is missing value then\n"
+       "    set theContent to theTitle & \", p. \" & thePage\n"
+       (when org-mac-Skim-highlight-selection-p
+	 (concat
+	  "else\n"
+          "    tell theDoc\n"
+          "        set theNote to make note with properties {type:highlight note, selection:theSelection}\n"
+          "         set text of theNote to (get text for theSelection)\n"
+          "    end tell\n"))
+       "end if\n"
+       "set theLink to \"skim://\" & thePath & \"::\" & thePage & "
+       "\"::split::\" & theContent\n"
+    "end tell\n"
+    "return theLink as string\n")))
+
+(defun org-mac-skim-get-page ()
+  (interactive)
+  (message "Applescript: Getting Skim page link...")
+  (let* ((link-and-descr (as-get-skim-page-link))
+         (split-link (split-string link-and-descr "::split::"))
+         (link (car split-link))
+         (description (cadr split-link))
+         (org-link))
+    (when (not (string= link ""))
+      (setq org-link (org-make-link-string link description)))
+    (kill-new org-link)
+    org-link))
+
+(defun org-mac-skim-insert-page ()
+  (interactive)
+  (insert (org-mac-skim-get-page)))
+
+
 
 (provide 'org-mac-link-grabber)
 

+ 1 - 3
contrib/lisp/org-mime.el

@@ -212,14 +212,12 @@ export that region, otherwise export the entire body."
          (tmp-file (make-temp-name (expand-file-name
 				    "mail" temporary-file-directory)))
          (body (org-export-string-as raw-body 'org t))
-         ;; because we probably don't want to skip part of our mail
-         (org-export-skip-text-before-1st-heading nil)
          ;; because we probably don't want to export a huge style file
          (org-export-htmlize-output-type 'inline-css)
          ;; makes the replies with ">"s look nicer
          (org-export-preserve-breaks org-mime-preserve-breaks)
 	 ;; dvipng for inline latex because MathJax doesn't work in mail
-	 (org-export-with-LaTeX-fragments 'dvipng)
+	 (org-html-with-latex 'dvipng)
          ;; to hold attachments for inline html images
          (html-and-images
           (org-mime-replace-images

+ 51 - 26
lisp/ob-gnuplot.el

@@ -52,22 +52,36 @@
   '((:results . "file") (:exports . "results") (:session . nil))
   "Default arguments to use when evaluating a gnuplot source block.")
 
+(defvar org-babel-header-args:gnuplot
+  '((title	. :any)
+    (lines	. :any)
+    (sets	. :any)
+    (x-labels	. :any)
+    (y-labels	. :any)
+    (timefmt	. :any)
+    (time-ind	. :any)
+    (missing	. :any))
+  "Gnuplot specific header args.")
+
 (defvar org-babel-gnuplot-timestamp-fmt nil)
 
+(defvar *org-babel-gnuplot-missing* nil)
+
 (defun org-babel-gnuplot-process-vars (params)
   "Extract variables from PARAMS and process the variables.
 Dumps all vectors into files and returns an association list
 of variable names and the related value to be used in the gnuplot
 code."
-  (mapcar
-   (lambda (pair)
-     (cons
-      (car pair) ;; variable name
-      (if (listp (cdr pair)) ;; variable value
-          (org-babel-gnuplot-table-to-data
-           (cdr pair) (org-babel-temp-file "gnuplot-") params)
-        (cdr pair))))
-   (mapcar #'cdr (org-babel-get-header params :var))))
+  (let ((*org-babel-gnuplot-missing* (cdr (assoc :missing params))))
+    (mapcar
+     (lambda (pair)
+       (cons
+	(car pair) ;; variable name
+	(if (listp (cdr pair)) ;; variable value
+	    (org-babel-gnuplot-table-to-data
+	     (cdr pair) (org-babel-temp-file "gnuplot-") params)
+	  (cdr pair))))
+     (mapcar #'cdr (org-babel-get-header params :var)))))
 
 (defun org-babel-expand-body:gnuplot (body params)
   "Expand BODY according to PARAMS, return the expanded body."
@@ -77,46 +91,53 @@ code."
            (term (or (cdr (assoc :term params))
                      (when out-file (file-name-extension out-file))))
            (cmdline (cdr (assoc :cmdline params)))
-           (title (plist-get params :title))
-           (lines (plist-get params :line))
-           (sets (plist-get params :set))
-           (x-labels (plist-get params :xlabels))
-           (y-labels (plist-get params :ylabels))
-           (timefmt (plist-get params :timefmt))
-           (time-ind (or (plist-get params :timeind)
+           (title (cdr (assoc :title params)))
+           (lines (cdr (assoc :line params)))
+           (sets (cdr (assoc :set params)))
+           (x-labels (cdr (assoc :xlabels params)))
+           (y-labels (cdr (assoc :ylabels params)))
+           (timefmt (cdr (assoc :timefmt params)))
+           (time-ind (or (cdr (assoc :timeind params))
                          (when timefmt 1)))
+	   (missing (cdr (assoc :missing params)))
 	   (add-to-body (lambda (text) (setq body (concat text "\n" body))))
            output)
       ;; append header argument settings to body
-      (when title (funcall add-to-body (format "set title '%s'" title))) ;; title
-      (when lines (mapc (lambda (el) (funcall add-to-body el)) lines)) ;; line
+      (when title (funcall add-to-body (format "set title '%s'" title)))
+      (when lines (mapc (lambda (el) (funcall add-to-body el)) lines))
+      (when missing
+	(funcall add-to-body (format "set datafile missing '%s'" missing)))
       (when sets
 	(mapc (lambda (el) (funcall add-to-body (format "set %s" el))) sets))
       (when x-labels
 	(funcall add-to-body
 		 (format "set xtics (%s)"
 			 (mapconcat (lambda (pair)
-				      (format "\"%s\" %d" (cdr pair) (car pair)))
+				      (format "\"%s\" %d"
+					      (cdr pair) (car pair)))
 				    x-labels ", "))))
       (when y-labels
 	(funcall add-to-body
 		 (format "set ytics (%s)"
 			 (mapconcat (lambda (pair)
-				      (format "\"%s\" %d" (cdr pair) (car pair)))
+				      (format "\"%s\" %d"
+					      (cdr pair) (car pair)))
 				    y-labels ", "))))
       (when time-ind
 	(funcall add-to-body "set xdata time")
 	(funcall add-to-body (concat "set timefmt \""
 				     (or timefmt
 					 "%Y-%m-%d-%H:%M:%S") "\"")))
-      (when out-file (funcall add-to-body (format "set output \"%s\"" out-file)))
+      (when out-file (funcall add-to-body (format "set output \"%s\""
+						  out-file)))
       (when term (funcall add-to-body (format "set term %s" term)))
       ;; insert variables into code body: this should happen last
       ;; placing the variables at the *top* of the code in case their
       ;; values are used later
-      (funcall add-to-body (mapconcat #'identity
-				      (org-babel-variable-assignments:gnuplot params)
-				      "\n"))
+      (funcall add-to-body
+	       (mapconcat #'identity
+			  (org-babel-variable-assignments:gnuplot params)
+			  "\n"))
       ;; replace any variable names preceded by '$' with the actual
       ;; value of the variable
       (mapc (lambda (pair)
@@ -199,7 +220,8 @@ then create one.  Return the initialized session.  The current
 
 (defun org-babel-gnuplot-quote-timestamp-field (s)
   "Convert S from timestamp to Unix time and export to gnuplot."
-  (format-time-string org-babel-gnuplot-timestamp-fmt (org-time-string-to-time s)))
+  (format-time-string org-babel-gnuplot-timestamp-fmt
+		      (org-time-string-to-time s)))
 
 (defvar org-table-number-regexp)
 (defvar org-ts-regexp3)
@@ -210,7 +232,10 @@ then create one.  Return the initialized session.  The current
   (if (string-match org-table-number-regexp s) s
     (if (string-match org-ts-regexp3 s)
 	(org-babel-gnuplot-quote-timestamp-field s)
-      (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\""))))
+      (if (zerop (length s))
+	  (or *org-babel-gnuplot-missing* s)
+	(concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"")
+		"\"")))))
 
 (defun org-babel-gnuplot-table-to-data (table data-file params)
   "Export TABLE to DATA-FILE in a format readable by gnuplot.

+ 1 - 1
lisp/ob-sh.el

@@ -106,7 +106,7 @@ var of the same value."
   "Convert an elisp value to a string."
   (let ((echo-var (lambda (v) (if (stringp v) v (format "%S" v)))))
     (cond
-     ((and (listp var) (listp (car var)))
+     ((and (listp var) (or (listp (car var)) 'hline))
       (orgtbl-to-generic var  (list :sep (or sep "\t") :fmt echo-var)))
      ((listp var)
       (mapconcat echo-var var "\n"))

+ 6 - 10
lisp/org-table.el

@@ -52,7 +52,7 @@ This can be used to add additional functionality after the table is sent
 to the receiver position, otherwise, if table is not sent, the functions
 are not run.")
 
-(defvar org-TBLFM-begin-regexp "|\n[ \t]*#\\+TBLFM: ")
+(defvar org-table-TBLFM-begin-regexp "|\n[ \t]*#\\+TBLFM: ")
 
 (defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
   "Non-nil means use the optimized table editor version for `orgtbl-mode'.
@@ -3144,8 +3144,8 @@ with the prefix ARG."
 	      (setq checksum c1)))
 	  (user-error "No convergence after %d iterations" imax))))))
 
-(defun org-calc-current-TBLFM (&optional arg)
-  "Apply the #+TBLFM in the line to the table."
+(defun org-table-calc-current-TBLFM (&optional arg)
+  "Apply the #+TBLFM in the line at point to the table."
   (interactive "P")
   (unless (org-at-TBLFM-p) (user-error "Not at a #+TBLFM line"))
   (let ((formula (buffer-substring
@@ -3154,33 +3154,29 @@ with the prefix ARG."
 	s e)
     (save-excursion
       ;; Insert a temporary formula at right after the table
-      (goto-char (org-TBLFM-begin))
+      (goto-char (org-table-TBLFM-begin))
       (setq s (set-marker (make-marker) (point)))
       (insert (concat formula "\n"))
       (setq e (set-marker (make-marker) (point)))
-
       ;; Recalculate the table
       (beginning-of-line 0)		; move to the inserted line
       (skip-chars-backward " \r\n\t")
       (if (org-at-table-p)
 	  (unwind-protect
 	      (org-call-with-arg 'org-table-recalculate (or arg t))
-
 	    ;; delete the formula inserted temporarily
 	    (delete-region s e))))))
 
-(defun org-TBLFM-begin ()
+(defun org-table-TBLFM-begin ()
   "Find the beginning of the TBLFM lines and return its position.
 Return nil when the beginning of TBLFM line was not found."
   (save-excursion
     (when (progn (forward-line 1)
 	      (re-search-backward
-	       org-TBLFM-begin-regexp
+	       org-table-TBLFM-begin-regexp
 	       nil t))
 	  (point-at-bol 2))))
 
-
-
 (defun org-table-expand-lhs-ranges (equations)
   "Expand list of formulas.
 If some of the RHS in the formulas are ranges or a row reference, expand

+ 38 - 21
lisp/org.el

@@ -126,6 +126,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
 (declare-function org-table-edit-field "org-table" (arg))
 (declare-function org-table-justify-field-maybe "org-table" (&optional new))
 (declare-function org-table-set-constants "org-table" ())
+(declare-function org-table-calc-current-TBLFM "org-table" (&optional arg))
 (declare-function org-id-get-create "org-id" (&optional force))
 (declare-function org-id-find-id-file "org-id" (id))
 (declare-function org-tags-view "org-agenda" (&optional todo-only match))
@@ -4872,7 +4873,9 @@ Support for group tags is controlled by the option
 	  (while (setq e (pop tgs))
 	    (or (and (stringp (car e))
 		     (assoc (car e) org-tag-alist))
-		(push e org-tag-alist))))))))
+		(push e org-tag-alist)))
+	  ;; Return a list with tag variables
+	  (list org-file-tags org-tag-alist org-tag-groups-alist))))))
 
 (defun org-set-regexps-and-options ()
   "Precompute regular expressions used in the current buffer."
@@ -4900,22 +4903,27 @@ Support for group tags is controlled by the option
 	(save-restriction
 	  (widen)
 	  (goto-char (point-min))
-	  (while (or (and ext-setup-or-nil
-		     	  (let (ret)
-		     	    (with-temp-buffer
-		     	      (insert ext-setup-or-nil)
-		     	      (let ((major-mode 'org-mode))
-				(org-set-regexps-and-options-for-tags)
-				(setq ret (list org-file-tags org-tag-alist
-						org-tag-groups-alist))))
-		     	    (setq org-file-tags (nth 0 ret)
-		     		  org-tag-alist (nth 1 ret)
-		     		  org-tag-groups-alist (nth 2 ret))))
-		     (and ext-setup-or-nil
-			  (string-match re ext-setup-or-nil start)
-			  (setq start (match-end 0)))
-		     (and (setq ext-setup-or-nil nil start 0)
-			  (re-search-forward re nil t)))
+	  (while
+	      (or (and
+		   ext-setup-or-nil
+		   (let (ret)
+		     (with-temp-buffer
+		       (insert ext-setup-or-nil)
+		       (let ((major-mode 'org-mode))
+			 (setq ret (save-match-data
+				     (org-set-regexps-and-options-for-tags)))))
+		     ;; Append setupfile tags to existing tags
+		     (setq org-file-tags
+			   (delq nil (append org-file-tags (nth 0 ret)))
+			   org-tag-alist
+			   (delq nil (append org-tag-alist (nth 1 ret)))
+			   org-tag-groups-alist
+			   (delq nil (append org-tag-groups-alist (nth 2 ret))))))
+		  (and ext-setup-or-nil
+		       (string-match re ext-setup-or-nil start)
+		       (setq start (match-end 0)))
+		  (and (setq ext-setup-or-nil nil start 0)
+		       (re-search-forward re nil t)))
 	    (setq key (upcase (match-string 1 ext-setup-or-nil))
 		  value (org-match-string-no-properties 2 ext-setup-or-nil))
 	    (if (stringp value) (setq value (org-trim value)))
@@ -5109,7 +5117,7 @@ Support for group tags is controlled by the option
 	    (concat "\\<" org-deadline-string " *<\\([^>]+\\)>")
 	    org-deadline-time-hour-regexp
 	    (concat "\\<" org-deadline-string
-		    " *<\\(.+[0-9]\\{1,2\\}:[0-9]\\{2\\}[^>]*\\)>")
+		    " *<\\([^>]+[0-9]\\{1,2\\}:[0-9]\\{2\\}[0-9-+:hdwmy \t.]*\\)>")
 	    org-deadline-line-regexp
 	    (concat "\\<\\(" org-deadline-string "\\).*")
 	    org-scheduled-regexp
@@ -5118,7 +5126,7 @@ Support for group tags is controlled by the option
 	    (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>")
 	    org-scheduled-time-hour-regexp
 	    (concat "\\<" org-scheduled-string
-		    " *<\\(.+[0-9]\\{1,2\\}:[0-9]\\{2\\}[^>]*\\)>")
+		    " *<\\([^>]+[0-9]\\{1,2\\}:[0-9]\\{2\\}[0-9-+:hdwmy \t.]*\\)>")
 	    org-closed-time-regexp
 	    (concat "\\<" org-closed-string " *\\[\\([^]]+\\)\\]")
 	    org-keyword-time-regexp
@@ -9258,7 +9266,7 @@ property to set."
 	   (save-excursion
 	     (org-back-to-heading t)
 	     (put-text-property
-	      (point-at-bol) (point-at-eol) tprop p))))))))
+	      (point-at-bol) (org-end-of-subtree t t) tprop p))))))))
 
 
 ;;;; Link Stuff
@@ -18007,6 +18015,13 @@ When a buffer is unmodified, it is just killed.  When modified, it is saved
 	      (set-buffer (org-get-agenda-file-buffer file)))
 	    (widen)
 	    (org-set-regexps-and-options-for-tags)
+	    (goto-char (point-min))
+	    (let ((case-fold-search t))
+	      (when (search-forward "#+setupfile" nil t)
+		;; Don't set all regexps and options systematically as
+		;; this is only run for setting agenda tags from setup
+		;; file
+		(org-set-regexps-and-options)))
 	    (org-refresh-category-properties)
 	    (org-refresh-properties org-effort-property 'org-effort)
 	    (org-refresh-properties "APPT_WARNTIME" 'org-appt-warntime)
@@ -20265,7 +20280,9 @@ This command does many different things, depending on context:
 		       (and (eq type 'table-row)
 			    (= (point) (org-element-property :end context))))
 		   (save-excursion
-		     (if (org-at-TBLFM-p) (org-calc-current-TBLFM)
+		     (if (org-at-TBLFM-p)
+			 (progn (require 'org-table)
+				(org-table-calc-current-TBLFM))
 		       (goto-char (org-element-property :contents-begin context))
 		       (org-call-with-arg 'org-table-recalculate (or arg t))
 		       (orgtbl-send-table 'maybe)))

+ 10 - 8
lisp/ox-html.el

@@ -2446,15 +2446,17 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 ;;;; Latex Environment
 
 (defun org-html-format-latex (latex-frag processing-type)
-  "Format the LaTeX fragment LATEX-FRAG into HTML."
-  (let ((cache-relpath "") (cache-dir "") bfn)
+  "Format a LaTeX fragment LATEX-FRAG into HTML."
+  (let ((cache-relpath "") (cache-dir ""))
     (unless (eq processing-type 'mathjax)
-      (setq bfn (buffer-file-name)
-	    cache-relpath
-	    (concat "ltxpng/"
-		    (file-name-sans-extension
-		     (file-name-nondirectory bfn)))
-	    cache-dir (file-name-directory bfn)))
+      (let ((bfn (or (buffer-file-name)
+		     (make-temp-name
+		      (expand-file-name "latex" temporary-file-directory)))))
+	(setq cache-relpath
+	      (concat "ltxpng/"
+		      (file-name-sans-extension
+		       (file-name-nondirectory bfn)))
+	      cache-dir (file-name-directory bfn))))
     (with-temp-buffer
       (insert latex-frag)
       (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."

+ 48 - 48
lisp/ox.el

@@ -117,7 +117,7 @@
     (:section-numbers nil "num" org-export-with-section-numbers)
     (:select-tags "SELECT_TAGS" nil org-export-select-tags split)
     (:time-stamp-file nil "timestamp" org-export-time-stamp-file)
-    (:title "TITLE" nil nil space)
+    (:title "TITLE" nil org-export--default-title space)
     (:with-archived-trees nil "arch" org-export-with-archived-trees)
     (:with-author nil "author" org-export-with-author)
     (:with-clocks nil "c" org-export-with-clocks)
@@ -1707,51 +1707,47 @@ Assume buffer is in Org mode.  Narrowing, if any, is ignored."
 
 (defun org-export--get-buffer-attributes ()
   "Return properties related to buffer attributes, as a plist."
-  (let ((visited-file (buffer-file-name (buffer-base-buffer))))
-    (list
-     ;; Store full path of input file name, or nil.  For internal use.
-     :input-file visited-file
-     :title (or (and visited-file
-		     (file-name-sans-extension
-		      (file-name-nondirectory visited-file)))
-		(buffer-name (buffer-base-buffer))))))
+  ;; Store full path of input file name, or nil.  For internal use.
+  (list :input-file (buffer-file-name (buffer-base-buffer))))
+
+(defvar org-export--default-title)	; Dynamically scoped.
+(defun org-export-store-default-title ()
+  "Return default title for current document, as a string.
+Title is extracted from associated file name, if any, or buffer's
+name."
+  (setq org-export--default-title
+	(or (let ((visited-file (buffer-file-name (buffer-base-buffer))))
+	      (and visited-file
+		   (file-name-sans-extension
+		    (file-name-nondirectory visited-file))))
+	    (buffer-name (buffer-base-buffer)))))
 
 (defun org-export--get-global-options (&optional backend)
   "Return global export options as a plist.
-
 Optional argument BACKEND, if non-nil, is a symbol specifying
 which back-end specific export options should also be read in the
 process."
-  (let ((all
-	 ;; Priority is given to back-end specific options.
-	 (append (and backend (org-export-backend-options backend))
-		 org-export-options-alist))
-	plist)
-    (mapc
-     (lambda (cell)
-       (let ((prop (car cell)))
-	 (unless (plist-member plist prop)
-	   (let ((value (eval (nth 3 cell))))
-	     ;; Only set property if default value is non-nil.
-	     (when value
-	       (setq plist
-		     (plist-put
-		      plist
-		      prop
-		      ;; If keyword belongs to
-		      ;; `org-element-document-properties', parse
-		      ;; default value as a secondary string before
-		      ;; storing it.
-		      (if (not (stringp value)) value
-			(let ((keyword (nth 1 cell)))
-			  (if (not (member keyword
-					   org-element-document-properties))
-			      value
-			    (org-element-parse-secondary-string
-			     value (org-element-restriction 'keyword))))))))))))
-     all)
-    ;; Return value.
-    plist))
+  (let (plist
+	;; Priority is given to back-end specific options.
+	(all (append (and backend (org-export-backend-options backend))
+		     org-export-options-alist)))
+    (dolist (cell all plist)
+      (let ((prop (car cell)))
+	(unless (plist-member plist prop)
+	  (setq plist
+		(plist-put
+		 plist
+		 prop
+		 ;; Eval default value provided.  If keyword is
+		 ;; a member of `org-element-document-properties',
+		 ;; parse it as a secondary string before storing it.
+		 (let ((value (eval (nth 3 cell))))
+		   (if (not (stringp value)) value
+		     (let ((keyword (nth 1 cell)))
+		       (if (member keyword org-element-document-properties)
+			   (org-element-parse-secondary-string
+			    value (org-element-restriction 'keyword))
+			 value)))))))))))
 
 (defun org-export--list-bound-variables ()
   "Return variables bound from BIND keywords in current buffer.
@@ -2929,14 +2925,18 @@ Return code as a string."
 	     (narrow-to-region (point) (point-max))))
       ;; Initialize communication channel with original buffer
       ;; attributes, unavailable in its copy.
-      (let ((info (org-combine-plists
-		   (list :export-options
-			 (delq nil
-			       (list (and subtreep 'subtree)
-				     (and visible-only 'visible-only)
-				     (and body-only 'body-only))))
-		   (org-export--get-buffer-attributes)))
-	    tree)
+      (let* ((info (org-combine-plists
+		    (list :export-options
+			  (delq nil
+				(list (and subtreep 'subtree)
+				      (and visible-only 'visible-only)
+				      (and body-only 'body-only))))
+		    (org-export--get-buffer-attributes)))
+	     tree)
+	;; Store default title in `org-export--default-title' so that
+	;; `org-export-get-environment' can access it from buffer's
+	;; copy and then add it properly to communication channel.
+	(org-export-store-default-title)
 	;; Update communication channel and get parse tree.  Buffer
 	;; isn't parsed directly.  Instead, a temporary copy is
 	;; created, where include keywords, macros are expanded and

+ 27 - 27
testing/lisp/test-org-table.el

@@ -808,7 +808,7 @@ reference (with row).  Mode string N."
     (forward-line 4)
     (should (equal (org-at-TBLFM-p) nil))))
 
-(ert-deftest test-org-table/org-TBLFM-begin ()
+(ert-deftest test-org-table/org-table-TBLFM-begin ()
   (org-test-with-temp-text-in-file
       "
 | 1 |
@@ -817,27 +817,27 @@ reference (with row).  Mode string N."
 
 "
     (goto-char (point-min))
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 
     (goto-char (point-min))
     (forward-line 1)
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 
     (goto-char (point-min))
     (forward-line 3)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 
     (goto-char (point-min))
     (forward-line 4)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 
     ))
 
-(ert-deftest test-org-table/org-TBLFM-begin-for-multiple-TBLFM-lines ()
+(ert-deftest test-org-table/org-table-TBLFM-begin-for-multiple-TBLFM-lines ()
   "For multiple #+TBLFM lines."
   (org-test-with-temp-text-in-file
       "
@@ -848,32 +848,32 @@ reference (with row).  Mode string N."
 
 "
     (goto-char (point-min))
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 
     (goto-char (point-min))
     (forward-line 1)
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 
     (goto-char (point-min))
     (forward-line 3)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 
     (goto-char (point-min))
     (forward-line 4)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 
     (goto-char (point-min))
     (forward-line 5)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 
     ))
 
-(ert-deftest test-org-table/org-TBLFM-begin-for-pultiple-TBLFM-lines-blocks ()
+(ert-deftest test-org-table/org-table-TBLFM-begin-for-pultiple-TBLFM-lines-blocks ()
   (org-test-with-temp-text-in-file
       "
 | 1 |
@@ -888,50 +888,50 @@ reference (with row).  Mode string N."
 
 "
     (goto-char (point-min))
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 
     (goto-char (point-min))
     (forward-line 1)
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 
     (goto-char (point-min))
     (forward-line 3)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 
     (goto-char (point-min))
     (forward-line 4)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 
     (goto-char (point-min))
     (forward-line 5)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 
     (goto-char (point-min))
     (forward-line 6)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 
     (goto-char (point-min))
     (forward-line 8)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   61))
 
     (goto-char (point-min))
     (forward-line 9)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   61))
 
     (goto-char (point-min))
     (forward-line 10)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   61))))
 
-(ert-deftest test-org-table/org-calc-current-TBLFM ()
+(ert-deftest test-org-table/org-table-calc-current-TBLFM ()
     (org-test-with-temp-text-in-file
       "
 | 1 |   |
@@ -942,7 +942,7 @@ reference (with row).  Mode string N."
 "
     (let ((got (progn (goto-char (point-min))
 		      (forward-line 3)
-		      (org-calc-current-TBLFM)
+		      (org-table-calc-current-TBLFM)
 		      (buffer-string)))
 	  (expect "
 | 1 | 1 |
@@ -956,7 +956,7 @@ reference (with row).  Mode string N."
 
     (let ((got (progn (goto-char (point-min))
 		      (forward-line 4)
-		      (org-calc-current-TBLFM)
+		      (org-table-calc-current-TBLFM)
 		      (buffer-string)))
 	  (expect "
 | 1 | 2 |
@@ -968,8 +968,8 @@ reference (with row).  Mode string N."
       (should (string= got
 		       expect)))))
 
-(ert-deftest test-org-table/org-calc-current-TBLFM-when-stop-because-of-error ()
-  "org-calc-current-TBLFM should preserve the input as it was."
+(ert-deftest test-org-table/org-table-calc-current-TBLFM-when-stop-because-of-error ()
+  "org-table-calc-current-TBLFM should preserve the input as it was."
   (org-test-with-temp-text-in-file
       "
 | 1 | 1 |
@@ -987,7 +987,7 @@ reference (with row).  Mode string N."
 "))
       (goto-char (point-min))
       (forward-line 4)
-      (should-error (org-calc-current-TBLFM))
+      (should-error (org-table-calc-current-TBLFM))
       (setq got (buffer-string))
       (message "%s" got)
       (should (string= got

+ 8 - 4
testing/lisp/test-ox.el

@@ -279,7 +279,8 @@ Paragraph"
       (let (org-export-registered-backends)
 	(org-export-define-backend 'test
 	  '((template . (lambda (text info)
-			  (org-export-data (plist-get info :title) info)))))
+			  (org-element-interpret-data
+			   (plist-get info :title) info)))))
 	(list (org-export-as 'test)
 	      (file-name-nondirectory
 	       (file-name-sans-extension (buffer-file-name))))))))
@@ -293,7 +294,8 @@ Paragraph"
       (let (org-export-registered-backends)
 	(org-export-define-backend 'test
 	  '((template . (lambda (text info)
-			  (org-export-data (plist-get info :title) info)))))
+			  (org-element-interpret-data
+			   (plist-get info :title) info)))))
 	(list (org-export-as 'test) (buffer-name))))))
   ;; If a title is specified, use it.
   (should
@@ -304,7 +306,8 @@ Paragraph"
       (let (org-export-registered-backends)
 	(org-export-define-backend 'test
 	  '((template . (lambda (text info)
-			  (org-export-data (plist-get info :title) info)))))
+			  (org-element-interpret-data
+			   (plist-get info :title) info)))))
 	(org-export-as 'test)))))
   ;; If an empty title is specified, do not set it.
   (should
@@ -315,7 +318,8 @@ Paragraph"
       (let (org-export-registered-backends)
 	(org-export-define-backend 'test
 	  '((template . (lambda (text info)
-			  (org-export-data (plist-get info :title) info)))))
+			  (org-element-interpret-data
+			   (plist-get info :title) info)))))
 	(org-export-as 'test))))))
 
 (ert-deftest test-org-export/handle-options ()