Browse Source

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

Max Mikhanosha 12 years ago
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
   :group 'org-mac-link-grabber
   :type 'boolean)
   :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 ()
 (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"
   "Prompt the user for an application to grab a link from, then go grab the link, and insert it at point"
   (interactive)
   (interactive)
   (let* ((descriptors `(("F" "inder" org-mac-finder-insert-selected ,org-mac-grab-Finder-app-p)
   (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))
 		 (menu-string (make-string 0 ?x))
 		 input)
 		 input)
-
+    
 	;; Create the menu string for the keymap
 	;; Create the menu string for the keymap
 	(mapc '(lambda (descriptor)
 	(mapc '(lambda (descriptor)
 			(when (elt descriptor 3)
 			(when (elt descriptor 3)
@@ -209,8 +224,9 @@ applications and inserting them in org documents"
 					 "	activate\n"
 					 "	activate\n"
 					 "	delay 0.15\n"
 					 "	delay 0.15\n"
 					 "	tell application \"System Events\"\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"
 					 "	end tell\n"
 					 "	delay 0.15\n"
 					 "	delay 0.15\n"
 					 "	set theUrl to the clipboard\n"
 					 "	set theUrl to the clipboard\n"
@@ -460,6 +476,73 @@ applications and inserting them in org documents"
   (interactive)
   (interactive)
   (insert (org-mac-addressbook-item-get-selected)))
   (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)
 (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
          (tmp-file (make-temp-name (expand-file-name
 				    "mail" temporary-file-directory)))
 				    "mail" temporary-file-directory)))
          (body (org-export-string-as raw-body 'org t))
          (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
          ;; because we probably don't want to export a huge style file
          (org-export-htmlize-output-type 'inline-css)
          (org-export-htmlize-output-type 'inline-css)
          ;; makes the replies with ">"s look nicer
          ;; makes the replies with ">"s look nicer
          (org-export-preserve-breaks org-mime-preserve-breaks)
          (org-export-preserve-breaks org-mime-preserve-breaks)
 	 ;; dvipng for inline latex because MathJax doesn't work in mail
 	 ;; 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
          ;; to hold attachments for inline html images
          (html-and-images
          (html-and-images
           (org-mime-replace-images
           (org-mime-replace-images

+ 51 - 26
lisp/ob-gnuplot.el

@@ -52,22 +52,36 @@
   '((:results . "file") (:exports . "results") (:session . nil))
   '((:results . "file") (:exports . "results") (:session . nil))
   "Default arguments to use when evaluating a gnuplot source block.")
   "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-timestamp-fmt nil)
 
 
+(defvar *org-babel-gnuplot-missing* nil)
+
 (defun org-babel-gnuplot-process-vars (params)
 (defun org-babel-gnuplot-process-vars (params)
   "Extract variables from PARAMS and process the variables.
   "Extract variables from PARAMS and process the variables.
 Dumps all vectors into files and returns an association list
 Dumps all vectors into files and returns an association list
 of variable names and the related value to be used in the gnuplot
 of variable names and the related value to be used in the gnuplot
 code."
 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)
 (defun org-babel-expand-body:gnuplot (body params)
   "Expand BODY according to PARAMS, return the expanded body."
   "Expand BODY according to PARAMS, return the expanded body."
@@ -77,46 +91,53 @@ code."
            (term (or (cdr (assoc :term params))
            (term (or (cdr (assoc :term params))
                      (when out-file (file-name-extension out-file))))
                      (when out-file (file-name-extension out-file))))
            (cmdline (cdr (assoc :cmdline params)))
            (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)))
                          (when timefmt 1)))
+	   (missing (cdr (assoc :missing params)))
 	   (add-to-body (lambda (text) (setq body (concat text "\n" body))))
 	   (add-to-body (lambda (text) (setq body (concat text "\n" body))))
            output)
            output)
       ;; append header argument settings to body
       ;; 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
       (when sets
 	(mapc (lambda (el) (funcall add-to-body (format "set %s" el))) sets))
 	(mapc (lambda (el) (funcall add-to-body (format "set %s" el))) sets))
       (when x-labels
       (when x-labels
 	(funcall add-to-body
 	(funcall add-to-body
 		 (format "set xtics (%s)"
 		 (format "set xtics (%s)"
 			 (mapconcat (lambda (pair)
 			 (mapconcat (lambda (pair)
-				      (format "\"%s\" %d" (cdr pair) (car pair)))
+				      (format "\"%s\" %d"
+					      (cdr pair) (car pair)))
 				    x-labels ", "))))
 				    x-labels ", "))))
       (when y-labels
       (when y-labels
 	(funcall add-to-body
 	(funcall add-to-body
 		 (format "set ytics (%s)"
 		 (format "set ytics (%s)"
 			 (mapconcat (lambda (pair)
 			 (mapconcat (lambda (pair)
-				      (format "\"%s\" %d" (cdr pair) (car pair)))
+				      (format "\"%s\" %d"
+					      (cdr pair) (car pair)))
 				    y-labels ", "))))
 				    y-labels ", "))))
       (when time-ind
       (when time-ind
 	(funcall add-to-body "set xdata time")
 	(funcall add-to-body "set xdata time")
 	(funcall add-to-body (concat "set timefmt \""
 	(funcall add-to-body (concat "set timefmt \""
 				     (or timefmt
 				     (or timefmt
 					 "%Y-%m-%d-%H:%M:%S") "\"")))
 					 "%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)))
       (when term (funcall add-to-body (format "set term %s" term)))
       ;; insert variables into code body: this should happen last
       ;; insert variables into code body: this should happen last
       ;; placing the variables at the *top* of the code in case their
       ;; placing the variables at the *top* of the code in case their
       ;; values are used later
       ;; 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
       ;; replace any variable names preceded by '$' with the actual
       ;; value of the variable
       ;; value of the variable
       (mapc (lambda (pair)
       (mapc (lambda (pair)
@@ -199,7 +220,8 @@ then create one.  Return the initialized session.  The current
 
 
 (defun org-babel-gnuplot-quote-timestamp-field (s)
 (defun org-babel-gnuplot-quote-timestamp-field (s)
   "Convert S from timestamp to Unix time and export to gnuplot."
   "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-table-number-regexp)
 (defvar org-ts-regexp3)
 (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-table-number-regexp s) s
     (if (string-match org-ts-regexp3 s)
     (if (string-match org-ts-regexp3 s)
 	(org-babel-gnuplot-quote-timestamp-field 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)
 (defun org-babel-gnuplot-table-to-data (table data-file params)
   "Export TABLE to DATA-FILE in a format readable by gnuplot.
   "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."
   "Convert an elisp value to a string."
   (let ((echo-var (lambda (v) (if (stringp v) v (format "%S" v)))))
   (let ((echo-var (lambda (v) (if (stringp v) v (format "%S" v)))))
     (cond
     (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)))
       (orgtbl-to-generic var  (list :sep (or sep "\t") :fmt echo-var)))
      ((listp var)
      ((listp var)
       (mapconcat echo-var var "\n"))
       (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
 to the receiver position, otherwise, if table is not sent, the functions
 are not run.")
 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)
 (defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
   "Non-nil means use the optimized table editor version for `orgtbl-mode'.
   "Non-nil means use the optimized table editor version for `orgtbl-mode'.
@@ -3144,8 +3144,8 @@ with the prefix ARG."
 	      (setq checksum c1)))
 	      (setq checksum c1)))
 	  (user-error "No convergence after %d iterations" imax))))))
 	  (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")
   (interactive "P")
   (unless (org-at-TBLFM-p) (user-error "Not at a #+TBLFM line"))
   (unless (org-at-TBLFM-p) (user-error "Not at a #+TBLFM line"))
   (let ((formula (buffer-substring
   (let ((formula (buffer-substring
@@ -3154,33 +3154,29 @@ with the prefix ARG."
 	s e)
 	s e)
     (save-excursion
     (save-excursion
       ;; Insert a temporary formula at right after the table
       ;; 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)))
       (setq s (set-marker (make-marker) (point)))
       (insert (concat formula "\n"))
       (insert (concat formula "\n"))
       (setq e (set-marker (make-marker) (point)))
       (setq e (set-marker (make-marker) (point)))
-
       ;; Recalculate the table
       ;; Recalculate the table
       (beginning-of-line 0)		; move to the inserted line
       (beginning-of-line 0)		; move to the inserted line
       (skip-chars-backward " \r\n\t")
       (skip-chars-backward " \r\n\t")
       (if (org-at-table-p)
       (if (org-at-table-p)
 	  (unwind-protect
 	  (unwind-protect
 	      (org-call-with-arg 'org-table-recalculate (or arg t))
 	      (org-call-with-arg 'org-table-recalculate (or arg t))
-
 	    ;; delete the formula inserted temporarily
 	    ;; delete the formula inserted temporarily
 	    (delete-region s e))))))
 	    (delete-region s e))))))
 
 
-(defun org-TBLFM-begin ()
+(defun org-table-TBLFM-begin ()
   "Find the beginning of the TBLFM lines and return its position.
   "Find the beginning of the TBLFM lines and return its position.
 Return nil when the beginning of TBLFM line was not found."
 Return nil when the beginning of TBLFM line was not found."
   (save-excursion
   (save-excursion
     (when (progn (forward-line 1)
     (when (progn (forward-line 1)
 	      (re-search-backward
 	      (re-search-backward
-	       org-TBLFM-begin-regexp
+	       org-table-TBLFM-begin-regexp
 	       nil t))
 	       nil t))
 	  (point-at-bol 2))))
 	  (point-at-bol 2))))
 
 
-
-
 (defun org-table-expand-lhs-ranges (equations)
 (defun org-table-expand-lhs-ranges (equations)
   "Expand list of formulas.
   "Expand list of formulas.
 If some of the RHS in the formulas are ranges or a row reference, expand
 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-edit-field "org-table" (arg))
 (declare-function org-table-justify-field-maybe "org-table" (&optional new))
 (declare-function org-table-justify-field-maybe "org-table" (&optional new))
 (declare-function org-table-set-constants "org-table" ())
 (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-get-create "org-id" (&optional force))
 (declare-function org-id-find-id-file "org-id" (id))
 (declare-function org-id-find-id-file "org-id" (id))
 (declare-function org-tags-view "org-agenda" (&optional todo-only match))
 (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))
 	  (while (setq e (pop tgs))
 	    (or (and (stringp (car e))
 	    (or (and (stringp (car e))
 		     (assoc (car e) org-tag-alist))
 		     (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 ()
 (defun org-set-regexps-and-options ()
   "Precompute regular expressions used in the current buffer."
   "Precompute regular expressions used in the current buffer."
@@ -4900,22 +4903,27 @@ Support for group tags is controlled by the option
 	(save-restriction
 	(save-restriction
 	  (widen)
 	  (widen)
 	  (goto-char (point-min))
 	  (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))
 	    (setq key (upcase (match-string 1 ext-setup-or-nil))
 		  value (org-match-string-no-properties 2 ext-setup-or-nil))
 		  value (org-match-string-no-properties 2 ext-setup-or-nil))
 	    (if (stringp value) (setq value (org-trim value)))
 	    (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 " *<\\([^>]+\\)>")
 	    (concat "\\<" org-deadline-string " *<\\([^>]+\\)>")
 	    org-deadline-time-hour-regexp
 	    org-deadline-time-hour-regexp
 	    (concat "\\<" org-deadline-string
 	    (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
 	    org-deadline-line-regexp
 	    (concat "\\<\\(" org-deadline-string "\\).*")
 	    (concat "\\<\\(" org-deadline-string "\\).*")
 	    org-scheduled-regexp
 	    org-scheduled-regexp
@@ -5118,7 +5126,7 @@ Support for group tags is controlled by the option
 	    (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>")
 	    (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>")
 	    org-scheduled-time-hour-regexp
 	    org-scheduled-time-hour-regexp
 	    (concat "\\<" org-scheduled-string
 	    (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
 	    org-closed-time-regexp
 	    (concat "\\<" org-closed-string " *\\[\\([^]]+\\)\\]")
 	    (concat "\\<" org-closed-string " *\\[\\([^]]+\\)\\]")
 	    org-keyword-time-regexp
 	    org-keyword-time-regexp
@@ -9258,7 +9266,7 @@ property to set."
 	   (save-excursion
 	   (save-excursion
 	     (org-back-to-heading t)
 	     (org-back-to-heading t)
 	     (put-text-property
 	     (put-text-property
-	      (point-at-bol) (point-at-eol) tprop p))))))))
+	      (point-at-bol) (org-end-of-subtree t t) tprop p))))))))
 
 
 
 
 ;;;; Link Stuff
 ;;;; 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)))
 	      (set-buffer (org-get-agenda-file-buffer file)))
 	    (widen)
 	    (widen)
 	    (org-set-regexps-and-options-for-tags)
 	    (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-category-properties)
 	    (org-refresh-properties org-effort-property 'org-effort)
 	    (org-refresh-properties org-effort-property 'org-effort)
 	    (org-refresh-properties "APPT_WARNTIME" 'org-appt-warntime)
 	    (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)
 		       (and (eq type 'table-row)
 			    (= (point) (org-element-property :end context))))
 			    (= (point) (org-element-property :end context))))
 		   (save-excursion
 		   (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))
 		       (goto-char (org-element-property :contents-begin context))
 		       (org-call-with-arg 'org-table-recalculate (or arg t))
 		       (org-call-with-arg 'org-table-recalculate (or arg t))
 		       (orgtbl-send-table 'maybe)))
 		       (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
 ;;;; Latex Environment
 
 
 (defun org-html-format-latex (latex-frag processing-type)
 (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)
     (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
     (with-temp-buffer
       (insert latex-frag)
       (insert latex-frag)
       (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
       (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)
     (:section-numbers nil "num" org-export-with-section-numbers)
     (:select-tags "SELECT_TAGS" nil org-export-select-tags split)
     (:select-tags "SELECT_TAGS" nil org-export-select-tags split)
     (:time-stamp-file nil "timestamp" org-export-time-stamp-file)
     (: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-archived-trees nil "arch" org-export-with-archived-trees)
     (:with-author nil "author" org-export-with-author)
     (:with-author nil "author" org-export-with-author)
     (:with-clocks nil "c" org-export-with-clocks)
     (: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 ()
 (defun org-export--get-buffer-attributes ()
   "Return properties related to buffer attributes, as a plist."
   "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)
 (defun org-export--get-global-options (&optional backend)
   "Return global export options as a plist.
   "Return global export options as a plist.
-
 Optional argument BACKEND, if non-nil, is a symbol specifying
 Optional argument BACKEND, if non-nil, is a symbol specifying
 which back-end specific export options should also be read in the
 which back-end specific export options should also be read in the
 process."
 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 ()
 (defun org-export--list-bound-variables ()
   "Return variables bound from BIND keywords in current buffer.
   "Return variables bound from BIND keywords in current buffer.
@@ -2929,14 +2925,18 @@ Return code as a string."
 	     (narrow-to-region (point) (point-max))))
 	     (narrow-to-region (point) (point-max))))
       ;; Initialize communication channel with original buffer
       ;; Initialize communication channel with original buffer
       ;; attributes, unavailable in its copy.
       ;; 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
 	;; Update communication channel and get parse tree.  Buffer
 	;; isn't parsed directly.  Instead, a temporary copy is
 	;; isn't parsed directly.  Instead, a temporary copy is
 	;; created, where include keywords, macros are expanded and
 	;; 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)
     (forward-line 4)
     (should (equal (org-at-TBLFM-p) nil))))
     (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
   (org-test-with-temp-text-in-file
       "
       "
 | 1 |
 | 1 |
@@ -817,27 +817,27 @@ reference (with row).  Mode string N."
 
 
 "
 "
     (goto-char (point-min))
     (goto-char (point-min))
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 		   nil))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 1)
     (forward-line 1)
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 		   nil))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 3)
     (forward-line 3)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 		   14))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 4)
     (forward-line 4)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 		   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."
   "For multiple #+TBLFM lines."
   (org-test-with-temp-text-in-file
   (org-test-with-temp-text-in-file
       "
       "
@@ -848,32 +848,32 @@ reference (with row).  Mode string N."
 
 
 "
 "
     (goto-char (point-min))
     (goto-char (point-min))
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 		   nil))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 1)
     (forward-line 1)
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 		   nil))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 3)
     (forward-line 3)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 		   14))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 4)
     (forward-line 4)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 		   14))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 5)
     (forward-line 5)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 		   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
   (org-test-with-temp-text-in-file
       "
       "
 | 1 |
 | 1 |
@@ -888,50 +888,50 @@ reference (with row).  Mode string N."
 
 
 "
 "
     (goto-char (point-min))
     (goto-char (point-min))
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 		   nil))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 1)
     (forward-line 1)
-    (should (equal (org-TBLFM-begin)
+    (should (equal (org-table-TBLFM-begin)
 		   nil))
 		   nil))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 3)
     (forward-line 3)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 		   14))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 4)
     (forward-line 4)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 		   14))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 5)
     (forward-line 5)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 		   14))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 6)
     (forward-line 6)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   14))
 		   14))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 8)
     (forward-line 8)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   61))
 		   61))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 9)
     (forward-line 9)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   61))
 		   61))
 
 
     (goto-char (point-min))
     (goto-char (point-min))
     (forward-line 10)
     (forward-line 10)
-    (should (= (org-TBLFM-begin)
+    (should (= (org-table-TBLFM-begin)
 		   61))))
 		   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
     (org-test-with-temp-text-in-file
       "
       "
 | 1 |   |
 | 1 |   |
@@ -942,7 +942,7 @@ reference (with row).  Mode string N."
 "
 "
     (let ((got (progn (goto-char (point-min))
     (let ((got (progn (goto-char (point-min))
 		      (forward-line 3)
 		      (forward-line 3)
-		      (org-calc-current-TBLFM)
+		      (org-table-calc-current-TBLFM)
 		      (buffer-string)))
 		      (buffer-string)))
 	  (expect "
 	  (expect "
 | 1 | 1 |
 | 1 | 1 |
@@ -956,7 +956,7 @@ reference (with row).  Mode string N."
 
 
     (let ((got (progn (goto-char (point-min))
     (let ((got (progn (goto-char (point-min))
 		      (forward-line 4)
 		      (forward-line 4)
-		      (org-calc-current-TBLFM)
+		      (org-table-calc-current-TBLFM)
 		      (buffer-string)))
 		      (buffer-string)))
 	  (expect "
 	  (expect "
 | 1 | 2 |
 | 1 | 2 |
@@ -968,8 +968,8 @@ reference (with row).  Mode string N."
       (should (string= got
       (should (string= got
 		       expect)))))
 		       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
   (org-test-with-temp-text-in-file
       "
       "
 | 1 | 1 |
 | 1 | 1 |
@@ -987,7 +987,7 @@ reference (with row).  Mode string N."
 "))
 "))
       (goto-char (point-min))
       (goto-char (point-min))
       (forward-line 4)
       (forward-line 4)
-      (should-error (org-calc-current-TBLFM))
+      (should-error (org-table-calc-current-TBLFM))
       (setq got (buffer-string))
       (setq got (buffer-string))
       (message "%s" got)
       (message "%s" got)
       (should (string= got
       (should (string= got

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

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