Просмотр исходного кода

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

Bastien Guerry 12 лет назад
Родитель
Сommit
12793e45c3

+ 14 - 1
contrib/lisp/org-contacts.el

@@ -224,7 +224,20 @@ A regexp matching strings of whitespace, `,' and `;'.")
       (org-find-if (lambda (file)
       (org-find-if (lambda (file)
 		     (or (time-less-p org-contacts-last-update
 		     (or (time-less-p org-contacts-last-update
 				      (elt (file-attributes file) 5))))
 				      (elt (file-attributes file) 5))))
-		   (org-contacts-files))))
+		   (org-contacts-files))
+      (org-contacts-db-has-dead-markers-p org-contacts-db)))
+
+(defun org-contacts-db-has-dead-markers-p (org-contacts-db)
+  "Returns t if at least one dead marker is found in
+ORG-CONTACTS-DB. A dead marker in this case is a marker pointing
+to dead or no buffer."
+    ;; Scan contacts list looking for dead markers, and return t at first found.
+    (catch 'dead-marker-found
+      (while org-contacts-db
+        (unless (marker-buffer (nth 1 (car org-contacts-db)))
+          (throw 'dead-marker-found t))
+        (setq org-contacts-db (cdr org-contacts-db)))
+      nil))
 
 
 (defun org-contacts-db ()
 (defun org-contacts-db ()
   "Return the latest Org Contacts Database."
   "Return the latest Org Contacts Database."

+ 3 - 3
contrib/lisp/orgtbl-sqlinsert.el

@@ -70,14 +70,14 @@ this function is called."
          (*orgtbl-default-fmt* 'orgtbl-sql-strip-and-quote)
          (*orgtbl-default-fmt* 'orgtbl-sql-strip-and-quote)
 	 (params2
 	 (params2
 	  (list
 	  (list
-	   :sqlname name
+	   :sqlname (plist-get params :sqlname)
 	   :tstart (lambda () (concat (if nowebname
 	   :tstart (lambda () (concat (if nowebname
 					  (format "<<%s>>= \n" nowebname)
 					  (format "<<%s>>= \n" nowebname)
 					"")
 					"")
 				      "BEGIN TRANSACTION;"))
 				      "BEGIN TRANSACTION;"))
 	   :tend (lambda () (concat "COMMIT;" (if nowebname "\n@ " "")))
 	   :tend (lambda () (concat "COMMIT;" (if nowebname "\n@ " "")))
-	   :hfmt (lambda (f) (progn (if firstheader (push f hdrlist)) ""))
-	   :hlfmt (lambda (lst) (setq firstheader nil))
+	   :hfmt (lambda (f) (progn (if firstheader (push f hdrlist) "")))
+	   :hlfmt (lambda (&rest cells) (setq firstheader nil))
 	   :lstart (lambda () (concat "INSERT INTO "
 	   :lstart (lambda () (concat "INSERT INTO "
 				      sqlname "( "
 				      sqlname "( "
 				      (mapconcat 'identity (reverse hdrlist)
 				      (mapconcat 'identity (reverse hdrlist)

+ 55 - 14
contrib/lisp/ox-bibtex.el

@@ -28,6 +28,8 @@
 ;;
 ;;
 ;;   http://www.lri.fr/~filliatr/bibtex2html/
 ;;   http://www.lri.fr/~filliatr/bibtex2html/
 ;;
 ;;
+;; It also introduces "cite" syntax for Org links.
+;;
 ;; The usage is as follows:
 ;; The usage is as follows:
 ;;
 ;;
 ;;   #+BIBLIOGRAPHY: bibfilebasename stylename optional-options
 ;;   #+BIBLIOGRAPHY: bibfilebasename stylename optional-options
@@ -64,9 +66,18 @@
 ;; into the TeX file when exporting.
 ;; into the TeX file when exporting.
 ;;
 ;;
 ;; For HTML export it:
 ;; For HTML export it:
-;; 1) converts all \cite{foo} to links to the bibliography,
+;; 1) converts all \cite{foo} and [[cite:foo]] to links to the
+;;    bibliography,
 ;; 2) creates a foo.html and foo_bib.html,
 ;; 2) creates a foo.html and foo_bib.html,
 ;; 3) includes the contents of foo.html in the exported HTML file.
 ;; 3) includes the contents of foo.html in the exported HTML file.
+;;
+;; For LaTeX export it:
+;; 1) converts all [[cite:foo]] to \cite{foo}.
+
+;; Initialization
+
+(eval-when-compile (require 'cl))
+(org-add-link-type "cite" 'ebib)
 
 
 
 
 ;;; Internal Functions
 ;;; Internal Functions
@@ -109,18 +120,22 @@ contains a list of strings to be passed as options ot
                       (setq limit (not (equal "nil" value))))
                       (setq limit (not (equal "nil" value))))
                      ((equal "option" key) (push value options)))))))))
                      ((equal "option" key) (push value options)))))))))
 
 
-(defun org-bibtex-citation-p (fragment)
-  "Non-nil when a LaTeX macro is a citation.
-FRAGMENT is a `latex-fragment' type object."
-  (string-match "\\`\\\\cite{" (org-element-property :value fragment)))
+(defun org-bibtex-citation-p (object)
+  "Non-nil when OBJECT is a citation."
+  (case (org-element-type object)
+    (link (equal (org-element-property :type object) "cite"))
+    (latex-fragment
+     (string-match "\\`\\\\cite{" (org-element-property :value object)))))
 
 
 (defun org-bibtex-get-citation-key (citation)
 (defun org-bibtex-get-citation-key (citation)
   "Return key for a given citation, as a string.
   "Return key for a given citation, as a string.
-CITATION is a `latex-fragment' type object satisfying to
-`org-bibtex-citation-p' predicate."
-  (let ((value (org-element-property :value citation)))
-    (and (string-match "\\`\\\\cite{" value)
-         (substring value (match-end 0) -1))))
+CITATION is a `latex-fragment' or `link' type object satisfying
+to `org-bibtex-citation-p' predicate."
+  (if (eq (org-element-type citation) 'link)
+      (org-element-property :path citation)
+    (let ((value (org-element-property :value citation)))
+      (and (string-match "\\`\\\\cite{" value)
+	   (substring value (match-end 0) -1)))))
 
 
 
 
 
 
@@ -139,7 +154,16 @@ Fallback to `latex' back-end for other keywords."
                 (concat (and style (format "\\bibliographystyle{%s}\n" style))
                 (concat (and style (format "\\bibliographystyle{%s}\n" style))
                         (format "\\bibliography{%s}" file))))))))
                         (format "\\bibliography{%s}" file))))))))
 
 
+(defadvice org-latex-link (around bibtex-link)
+  "Translate \"cite\" type links into LaTeX syntax.
+Fallback to `latex' back-end for other keywords."
+  (let ((link (ad-get-arg 0)))
+    (if (not (org-bibtex-citation-p link)) ad-do-it
+      (setq ad-return-value
+	    (format "\\cite{%s}" (org-bibtex-get-citation-key link))))))
+
 (ad-activate 'org-latex-keyword)
 (ad-activate 'org-latex-keyword)
+(ad-activate 'org-latex-link)
 
 
 
 
 
 
@@ -176,8 +200,25 @@ Fallback to `html' back-end for other keywords."
              (org-split-string (org-bibtex-get-citation-key fragment) ",")
              (org-split-string (org-bibtex-get-citation-key fragment) ",")
              "")))))
              "")))))
 
 
+(defadvice org-html-link (around bibtex-link)
+  "Translate \"cite:\" type links into HTML syntax.
+Fallback to `html' back-end for other types."
+  (let ((link (ad-get-arg 0)))
+    (if (not (org-bibtex-citation-p link)) ad-do-it
+      (setq ad-return-value
+	    (mapconcat
+	     (lambda (key)
+	       (format "[<a href=\"#%s\">%s</a>]"
+		       key
+		       (or (cdr (assoc key org-bibtex-html-entries-alist))
+			   key)))
+	     (org-split-string (org-bibtex-get-citation-key link)
+			       "[ \t]*,[ \t]*")
+	     "")))))
+
 (ad-activate 'org-html-keyword)
 (ad-activate 'org-html-keyword)
 (ad-activate 'org-html-latex-fragment)
 (ad-activate 'org-html-latex-fragment)
+(ad-activate 'org-html-link)
 
 
 
 
 ;;;; Filter
 ;;;; Filter
@@ -202,10 +243,10 @@ Return new parse tree.  This function assumes current back-end is HTML."
           ;; argument.
           ;; argument.
           (when (plist-get arguments :limit)
           (when (plist-get arguments :limit)
             (let ((citations
             (let ((citations
-                   (org-element-map tree 'latex-fragment
-                     (lambda (fragment)
-                       (and (org-bibtex-citation-p fragment)
-                            (org-bibtex-get-citation-key fragment))))))
+                   (org-element-map tree '(latex-fragment link)
+                     (lambda (object)
+                       (and (org-bibtex-citation-p object)
+			    (org-bibtex-get-citation-key object))))))
               (with-temp-file (setq temp-file (make-temp-file "ox-bibtex"))
               (with-temp-file (setq temp-file (make-temp-file "ox-bibtex"))
                 (insert (mapconcat 'identity citations "\n")))
                 (insert (mapconcat 'identity citations "\n")))
               (setq arguments
               (setq arguments

+ 6 - 7
contrib/lisp/ox-freemind.el

@@ -314,14 +314,13 @@ will result in following node:
 		   (plist-get info :title))
 		   (plist-get info :title))
 		  (t (error "Shouldn't come here."))))
 		  (t (error "Shouldn't come here."))))
 	 (element-contents (org-element-contents element))
 	 (element-contents (org-element-contents element))
-	 (section (assoc 'section element-contents))
+	 (section (assq 'section element-contents))
 	 (section-contents
 	 (section-contents
-	  (let* ((translations
-		  (nconc (list (cons 'section
-				     (lambda (section contents info)
-				       contents)))
-			 (plist-get info :translate-alist))))
-	    (org-export-data-with-translations section translations info)))
+	  (let ((backend (org-export-create-backend
+			  :parent (org-export-backend-name
+				   (plist-get info :back-end))
+			  :transcoders '((section . (lambda (e c i) c))))))
+	    (org-export-data-with-backend section backend info)))
 	 (itemized-contents-p (let ((first-child-headline
 	 (itemized-contents-p (let ((first-child-headline
 				     (org-element-map element-contents
 				     (org-element-map element-contents
 					 'headline 'identity info t)))
 					 'headline 'identity info t)))

+ 23 - 23
contrib/lisp/ox-koma-letter.el

@@ -499,27 +499,27 @@ holding export options."
    (and (plist-get info :time-stamp-file)
    (and (plist-get info :time-stamp-file)
         (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
         (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
    ;; Document class and packages.
    ;; Document class and packages.
-   (let ((class (plist-get info :latex-class))
-         (class-options (plist-get info :latex-class-options)))
-     (org-element-normalize-string
-      (let* ((header (nth 1 (assoc class org-latex-classes)))
-             (document-class-string
-              (and (stringp header)
-                   (if (not class-options) header
-		     (replace-regexp-in-string
-		      "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
-		      class-options header t nil 1)))))
-        (if (not document-class-string)
-	    (user-error "Unknown LaTeX class `%s'" class)
-          (org-latex-guess-babel-language
-           (org-latex-guess-inputenc
-            (org-splice-latex-header
-             document-class-string
-             org-latex-default-packages-alist ; defined in org.el
-             org-latex-packages-alist nil     ; defined in org.el
-	     (concat (plist-get info :latex-header)
-		     (plist-get info :latex-header-extra))))
-           info)))))
+   (let* ((class (plist-get info :latex-class))
+	  (class-options (plist-get info :latex-class-options))
+	  (header (nth 1 (assoc class org-latex-classes)))
+	  (document-class-string
+	   (and (stringp header)
+		(if (not class-options) header
+		  (replace-regexp-in-string
+		   "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
+		   class-options header t nil 1)))))
+     (if (not document-class-string)
+	 (user-error "Unknown LaTeX class `%s'" class)
+       (org-latex-guess-babel-language
+	(org-latex-guess-inputenc
+	 (org-element-normalize-string
+	  (org-splice-latex-header
+	   document-class-string
+	   org-latex-default-packages-alist ; Defined in org.el.
+	   org-latex-packages-alist nil     ; Defined in org.el.
+	   (concat (org-element-normalize-string (plist-get info :latex-header))
+		   (plist-get info :latex-header-extra)))))
+	info)))
    (let ((lco (plist-get info :lco))
    (let ((lco (plist-get info :lco))
 	 (author (plist-get info :author))
 	 (author (plist-get info :author))
 	 (from-address (org-koma-letter--determine-special-value info 'from))
 	 (from-address (org-koma-letter--determine-special-value info 'from))
@@ -578,8 +578,8 @@ holding export options."
 		(dotimes (x l y)
 		(dotimes (x l y)
 		  (setq y (concat (if (> x 0) "%s," "%s") y)))
 		  (setq y (concat (if (> x 0) "%s," "%s") y)))
 		subject-format) "}\n"))
 		subject-format) "}\n"))
-     (when (and subject with-subject)
-       (format "\\setkomavar{subject}{%s}\n\n" subject))))
+      (when (and subject with-subject)
+	(format "\\setkomavar{subject}{%s}\n\n" subject))))
    ;; Letter start
    ;; Letter start
    (format "\\begin{letter}{%%\n%s}\n\n"
    (format "\\begin{letter}{%%\n%s}\n\n"
 	   (org-koma-letter--determine-special-value info 'to))
 	   (org-koma-letter--determine-special-value info 'to))

+ 32 - 16
contrib/lisp/ox-rss.el

@@ -25,6 +25,8 @@
 ;; This library implements a RSS 2.0 back-end for Org exporter, based on
 ;; This library implements a RSS 2.0 back-end for Org exporter, based on
 ;; the `html' back-end.
 ;; the `html' back-end.
 ;;
 ;;
+;; It requires Emacs 24.1 at least.
+;;
 ;; It provides two commands for export, depending on the desired output:
 ;; It provides two commands for export, depending on the desired output:
 ;; `org-rss-export-as-rss' (temporary buffer) and `org-rss-export-to-rss'
 ;; `org-rss-export-as-rss' (temporary buffer) and `org-rss-export-to-rss'
 ;; (as a ".xml" file).
 ;; (as a ".xml" file).
@@ -48,7 +50,7 @@
 ;;    :base-directory "~/myhomepage/"
 ;;    :base-directory "~/myhomepage/"
 ;;    :base-extension "org"
 ;;    :base-extension "org"
 ;;    :rss-image-url "http://lumiere.ens.fr/~guerry/images/faces/15.png"
 ;;    :rss-image-url "http://lumiere.ens.fr/~guerry/images/faces/15.png"
-;;    :home-link-home "http://lumiere.ens.fr/~guerry/"
+;;    :html-link-home "http://lumiere.ens.fr/~guerry/"
 ;;    :rss-extension "xml"
 ;;    :rss-extension "xml"
 ;;    :publishing-directory "/home/guerry/public_html/"
 ;;    :publishing-directory "/home/guerry/public_html/"
 ;;    :publishing-function (org-rss-publish-to-rss)
 ;;    :publishing-function (org-rss-publish-to-rss)
@@ -58,6 +60,10 @@
 ;;    :table-of-contents nil))
 ;;    :table-of-contents nil))
 ;;
 ;;
 ;; ... then rsync /home/guerry/public_html/ with your server.
 ;; ... then rsync /home/guerry/public_html/ with your server.
+;;
+;; By default, the permalink for a blog entry points to the headline.
+;; You can specify a different one by using the :RSS_PERMALINK:
+;; property within an entry.
 
 
 ;;; Code:
 ;;; Code:
 
 
@@ -213,6 +219,14 @@ is the property list for the given project.  PUB-DIR is the
 publishing directory.
 publishing directory.
 
 
 Return output file name."
 Return output file name."
+  (let ((bf (get-file-buffer filename)))
+    (if bf
+	(with-current-buffer bf
+	  (org-rss-add-pubdate-property)
+	  (write-file filename))
+      (find-file filename)
+      (org-rss-add-pubdate-property)
+      (write-file filename) (kill-buffer)))
   (org-publish-org-to
   (org-publish-org-to
    'rss filename (concat "." org-rss-extension) plist pub-dir))
    'rss filename (concat "." org-rss-extension) plist pub-dir))
 
 
@@ -227,6 +241,9 @@ communication channel."
 	      (> (org-export-get-relative-level headline info) 1))
 	      (> (org-export-get-relative-level headline info) 1))
     (let* ((htmlext (plist-get info :html-extension))
     (let* ((htmlext (plist-get info :html-extension))
 	   (hl-number (org-export-get-headline-number headline info))
 	   (hl-number (org-export-get-headline-number headline info))
+	   (hl-home (file-name-as-directory (plist-get info :html-link-home)))
+	   (hl-pdir (plist-get info :publishing-directory))
+	   (hl-perm (org-element-property :RSS_PERMALINK headline))
 	   (anchor
 	   (anchor
 	    (org-export-solidify-link-text
 	    (org-export-solidify-link-text
 	     (or (org-element-property :CUSTOM_ID headline)
 	     (or (org-element-property :CUSTOM_ID headline)
@@ -236,20 +253,18 @@ communication channel."
 	   (pubdate
 	   (pubdate
 	    (let ((system-time-locale "C"))
 	    (let ((system-time-locale "C"))
 	      (format-time-string
 	      (format-time-string
-	       "%a, %d %h %Y %H:%M:%S %Z"
+	       "%a, %d %h %Y %H:%M:%S %z"
 	       (org-time-string-to-time
 	       (org-time-string-to-time
 		(or (org-element-property :PUBDATE headline)
 		(or (org-element-property :PUBDATE headline)
 		    (error "Missing PUBDATE property"))))))
 		    (error "Missing PUBDATE property"))))))
-	   (title (org-rss-plain-text
-		   (org-element-property :raw-value headline) info))
+	   (title (org-element-property :raw-value headline))
 	   (publink
 	   (publink
-	    (concat
-	     (file-name-as-directory
-	      (or (plist-get info :html-link-home)
-		  (plist-get info :publishing-directory)))
-	     (file-name-nondirectory
-	      (file-name-sans-extension
-	       (buffer-file-name))) "." htmlext "#" anchor))
+	    (or (and hl-perm (concat (or hl-home hl-pdir) hl-perm))
+		(concat
+		 (or hl-home hl-pdir)
+		 (file-name-nondirectory
+		  (file-name-sans-extension
+		   (plist-get info :input-file))) "." htmlext "#" anchor)))
 	   (guid (if org-rss-use-entry-url-as-guid
 	   (guid (if org-rss-use-entry-url-as-guid
 		     publink
 		     publink
 		   (org-rss-plain-text
 		   (org-rss-plain-text
@@ -305,12 +320,12 @@ as a communication channel."
 (defun org-rss-build-channel-info (info)
 (defun org-rss-build-channel-info (info)
   "Build the RSS channel information."
   "Build the RSS channel information."
   (let* ((system-time-locale "C")
   (let* ((system-time-locale "C")
-	 (title (org-export-data (plist-get info :title) info))
+	 (title (plist-get info :title))
 	 (email (org-export-data (plist-get info :email) info))
 	 (email (org-export-data (plist-get info :email) info))
 	 (author (and (plist-get info :with-author)
 	 (author (and (plist-get info :with-author)
 		      (let ((auth (plist-get info :author)))
 		      (let ((auth (plist-get info :author)))
 			(and auth (org-export-data auth info)))))
 			(and auth (org-export-data auth info)))))
-	 (date (format-time-string "%a, %d %h %Y %H:%M:%S %Z")) ;; RFC 882
+	 (date (format-time-string "%a, %d %h %Y %H:%M:%S %z")) ;; RFC 882
 	 (description (org-export-data (plist-get info :description) info))
 	 (description (org-export-data (plist-get info :description) info))
 	 (lang (plist-get info :language))
 	 (lang (plist-get info :language))
 	 (keywords (plist-get info :keywords))
 	 (keywords (plist-get info :keywords))
@@ -318,10 +333,11 @@ as a communication channel."
 	 (blogurl (or (plist-get info :html-link-home)
 	 (blogurl (or (plist-get info :html-link-home)
 		      (plist-get info :publishing-directory)))
 		      (plist-get info :publishing-directory)))
 	 (image (url-encode-url (plist-get info :rss-image-url)))
 	 (image (url-encode-url (plist-get info :rss-image-url)))
+	 (ifile (plist-get info :input-file))
 	 (publink
 	 (publink
 	  (concat (file-name-as-directory blogurl)
 	  (concat (file-name-as-directory blogurl)
 		   (file-name-nondirectory
 		   (file-name-nondirectory
-		    (file-name-sans-extension (buffer-file-name)))
+		    (file-name-sans-extension ifile))
 		  "." rssext)))
 		  "." rssext)))
     (format
     (format
      "\n<title>%s</title>
      "\n<title>%s</title>
@@ -332,7 +348,7 @@ as a communication channel."
 <pubDate>%s</pubDate>
 <pubDate>%s</pubDate>
 <lastBuildDate>%s</lastBuildDate>
 <lastBuildDate>%s</lastBuildDate>
 <generator>%s</generator>
 <generator>%s</generator>
-<webMaster>%s</webMaster>
+<webMaster>%s (%s)</webMaster>
 <image>
 <image>
 <url>%s</url>
 <url>%s</url>
 <title>%s</title>
 <title>%s</title>
@@ -344,7 +360,7 @@ as a communication channel."
 		     emacs-major-version
 		     emacs-major-version
 		     emacs-minor-version)
 		     emacs-minor-version)
 	     " Org-mode " (org-version))
 	     " Org-mode " (org-version))
-     email image title blogurl)))
+     email author image title blogurl)))
 
 
 (defun org-rss-section (section contents info)
 (defun org-rss-section (section contents info)
   "Transcode SECTION element into RSS format.
   "Transcode SECTION element into RSS format.

+ 87 - 26
doc/org.texi

@@ -1832,9 +1832,11 @@ This command also cycles bullet styles when the cursor in on the bullet or
 anywhere in an item line, details depending on
 anywhere in an item line, details depending on
 @code{org-support-shift-select}.
 @code{org-support-shift-select}.
 @kindex C-c ^
 @kindex C-c ^
+@cindex sorting, of plain list
 @item C-c ^
 @item C-c ^
 Sort the plain list.  You will be prompted for the sorting method:
 Sort the plain list.  You will be prompted for the sorting method:
-numerically, alphabetically, by time, or by custom function.
+numerically, alphabetically, by time, by checked status for check lists,
+or by a custom function.
 @end table
 @end table
 
 
 @node Drawers, Blocks, Plain lists, Document Structure
 @node Drawers, Blocks, Plain lists, Document Structure
@@ -5056,7 +5058,7 @@ tags---beware that all whitespaces are mandatory so that Org can parse this
 line correctly:
 line correctly:
 
 
 @example
 @example
-#+TAGS: @{ @@read : @@read_book  @@read_ebook @}
+#+TAGS: @{ @@read : @@read_book @@read_ebook @}
 @end example
 @end example
 
 
 In this example, @samp{@@read} is a @emph{group tag} for a set of three
 In this example, @samp{@@read} is a @emph{group tag} for a set of three
@@ -7381,6 +7383,7 @@ Copying works like refiling, except that the original note is not deleted.
 @vindex org-refile-allow-creating-parent-nodes
 @vindex org-refile-allow-creating-parent-nodes
 @vindex org-log-refile
 @vindex org-log-refile
 @vindex org-refile-use-cache
 @vindex org-refile-use-cache
+@vindex org-refile-keep
 Refile the entry or region at point.  This command offers possible locations
 Refile the entry or region at point.  This command offers possible locations
 for refiling the entry and lets you select one with completion.  The item (or
 for refiling the entry and lets you select one with completion.  The item (or
 all items in the region) is filed below the target heading as a subitem.
 all items in the region) is filed below the target heading as a subitem.
@@ -7404,6 +7407,10 @@ Use the refile interface to jump to a heading.
 Jump to the location where @code{org-refile} last moved a tree to.
 Jump to the location where @code{org-refile} last moved a tree to.
 @item C-2 C-c C-w
 @item C-2 C-c C-w
 Refile as the child of the item currently being clocked.
 Refile as the child of the item currently being clocked.
+@item C-3 C-c C-w
+Refile and keep the entry in place.  Also see @code{org-refile-keep} to make
+this the default behavior, and beware that this may result in duplicated
+@code{ID} properties.
 @orgcmdtkc{C-0 C-c C-w @ @r{or} @ C-u C-u C-u C-c C-w,C-0 C-c C-w,org-refile-cache-clear}
 @orgcmdtkc{C-0 C-c C-w @ @r{or} @ C-u C-u C-u C-c C-w,C-0 C-c C-w,org-refile-cache-clear}
 Clear the target cache.  Caching of refile targets can be turned on by
 Clear the target cache.  Caching of refile targets can be turned on by
 setting @code{org-refile-use-cache}.  To make the command see new possible
 setting @code{org-refile-use-cache}.  To make the command see new possible
@@ -8049,15 +8056,18 @@ You may also test for properties (@pxref{Properties and Columns}) at the same
 time as matching tags.  The properties may be real properties, or special
 time as matching tags.  The properties may be real properties, or special
 properties that represent other metadata (@pxref{Special properties}).  For
 properties that represent other metadata (@pxref{Special properties}).  For
 example, the ``property'' @code{TODO} represents the TODO keyword of the
 example, the ``property'' @code{TODO} represents the TODO keyword of the
-entry.  Or, the ``property'' @code{LEVEL} represents the level of an entry.
-So a search @samp{+LEVEL=3+boss-TODO="DONE"} lists all level three headlines
-that have the tag @samp{boss} and are @emph{not} marked with the TODO keyword
-DONE@.  In buffers with @code{org-odd-levels-only} set, @samp{LEVEL} does not
-count the number of stars, but @samp{LEVEL=2} will correspond to 3 stars etc.
-The ITEM special property cannot currently be used in tags/property
+entry and the ``propety'' @code{PRIORITY} represents the PRIORITY keyword of
+the entry.  The ITEM special property cannot currently be used in tags/property
 searches@footnote{But @pxref{x-agenda-skip-entry-regexp,
 searches@footnote{But @pxref{x-agenda-skip-entry-regexp,
 ,skipping entries based on regexp}.}.
 ,skipping entries based on regexp}.}.
 
 
+Except the @pxref{Special properties}, one other ``property'' can also be
+used. @code{LEVEL} represents the level of an entry.  So a search
+@samp{+LEVEL=3+boss-TODO="DONE"} lists all level three headlines that have
+the tag @samp{boss} and are @emph{not} marked with the TODO keyword DONE@.
+In buffers with @code{org-odd-levels-only} set, @samp{LEVEL} does not count
+the number of stars, but @samp{LEVEL=2} will correspond to 3 stars etc.
+
 Here are more examples:
 Here are more examples:
 
 
 @table @samp
 @table @samp
@@ -10006,7 +10016,7 @@ Conversely, backslash characters before a comma, and only them, need to be
 escaped with another backslash character.}.  In addition to defined macros,
 escaped with another backslash character.}.  In addition to defined macros,
 @code{@{@{@{title@}@}@}}, @code{@{@{@{author@}@}@}}, etc., will reference
 @code{@{@{@{title@}@}@}}, @code{@{@{@{author@}@}@}}, etc., will reference
 information set by the @code{#+TITLE:}, @code{#+AUTHOR:}, and similar lines.
 information set by the @code{#+TITLE:}, @code{#+AUTHOR:}, and similar lines.
-Also, @code{@{@{@{date(@var{FORMAT})@}@}@}} and
+Also, @code{@{@{@{time(@var{FORMAT})@}@}@}} and
 @code{@{@{@{modification-time(@var{FORMAT})@}@}@}} refer to current date time
 @code{@{@{@{modification-time(@var{FORMAT})@}@}@}} refer to current date time
 and to the modification time of the file being exported, respectively.
 and to the modification time of the file being exported, respectively.
 @var{FORMAT} should be a format string understood by
 @var{FORMAT} should be a format string understood by
@@ -10146,10 +10156,10 @@ snippets will be identified as @LaTeX{} source code:
 @item
 @item
 Environments of any kind@footnote{When @file{MathJax} is used, only the
 Environments of any kind@footnote{When @file{MathJax} is used, only the
 environments recognized by @file{MathJax} will be processed.  When
 environments recognized by @file{MathJax} will be processed.  When
-@file{dvipng} is used to create images, any @LaTeX{} environment will be
-handled.}.  The only requirement is that the @code{\begin} and @code{\end}
-statements appear on a new line, at the beginning of the line or after
-whitespaces only.
+@file{dvipng} program or @file{imagemagick} suite is used to create images,
+any @LaTeX{} environment will be handled.}.  The only requirement is that the
+@code{\begin} and @code{\end} statements appear on a new line, at the
+beginning of the line or after whitespaces only.
 @item
 @item
 Text within the usual @LaTeX{} math delimiters.  To avoid conflicts with
 Text within the usual @LaTeX{} math delimiters.  To avoid conflicts with
 currency specifications, single @samp{$} characters are only recognized as
 currency specifications, single @samp{$} characters are only recognized as
@@ -10187,7 +10197,6 @@ lines:
 
 
 @example
 @example
 #+OPTIONS: tex:t          @r{Do the right thing automatically (MathJax)}
 #+OPTIONS: tex:t          @r{Do the right thing automatically (MathJax)}
-#+OPTIONS: tex:dvipng     @r{Force using dvipng images}
 #+OPTIONS: tex:nil        @r{Do not process @LaTeX{} fragments at all}
 #+OPTIONS: tex:nil        @r{Do not process @LaTeX{} fragments at all}
 #+OPTIONS: tex:verbatim   @r{Verbatim export, for jsMath or so}
 #+OPTIONS: tex:verbatim   @r{Verbatim export, for jsMath or so}
 @end example
 @end example
@@ -11247,6 +11256,7 @@ You could use @code{http} addresses just as well.
 @subsection Math formatting in HTML export
 @subsection Math formatting in HTML export
 @cindex MathJax
 @cindex MathJax
 @cindex dvipng
 @cindex dvipng
+@cindex imagemagick
 
 
 @LaTeX{} math snippets (@pxref{@LaTeX{} fragments}) can be displayed in two
 @LaTeX{} math snippets (@pxref{@LaTeX{} fragments}) can be displayed in two
 different ways on HTML pages.  The default is to use the
 different ways on HTML pages.  The default is to use the
@@ -11272,13 +11282,19 @@ this line.
 If you prefer, you can also request that @LaTeX{} fragments are processed
 If you prefer, you can also request that @LaTeX{} fragments are processed
 into small images that will be inserted into the browser page.  Before the
 into small images that will be inserted into the browser page.  Before the
 availability of MathJax, this was the default method for Org files.  This
 availability of MathJax, this was the default method for Org files.  This
-method requires that the @file{dvipng} program is available on your system.
-You can still get this processing with
+method requires that the @file{dvipng} program or @file{imagemagick} suite is
+available on your system.  You can still get this processing with
 
 
 @example
 @example
 #+OPTIONS: tex:dvipng
 #+OPTIONS: tex:dvipng
 @end example
 @end example
 
 
+or:
+
+@example
+#+OPTIONS: tex:imagemagick
+@end example
+
 @node Text areas in HTML export, CSS support, Math formatting in HTML export, HTML export
 @node Text areas in HTML export, CSS support, Math formatting in HTML export, HTML export
 @subsection Text areas in HTML export
 @subsection Text areas in HTML export
 
 
@@ -11335,6 +11351,9 @@ p.creator           @r{creator info, about org mode version}
 div.outline-N       @r{div for outline level N (headline plus text))}
 div.outline-N       @r{div for outline level N (headline plus text))}
 div.outline-text-N  @r{extra div for text at outline level N}
 div.outline-text-N  @r{extra div for text at outline level N}
 .section-number-N   @r{section number in headlines, different for each level}
 .section-number-N   @r{section number in headlines, different for each level}
+.figure-number      @r{label like "Figure 1:"}
+.table-number       @r{label like "Table 1:"}
+.listing-number     @r{label like "Listing 1:"}
 div.figure          @r{how to format an inlined image}
 div.figure          @r{how to format an inlined image}
 pre.src             @r{formatted source code}
 pre.src             @r{formatted source code}
 pre.example         @r{normal example}
 pre.example         @r{normal example}
@@ -11599,6 +11618,11 @@ Environment used for the table.  It can be set to any @LaTeX{} table
 environment, like @code{tabularx}, @code{longtable}, @code{array},
 environment, like @code{tabularx}, @code{longtable}, @code{array},
 @code{tabu}, @code{bmatrix}@enddots{}  It defaults to
 @code{tabu}, @code{bmatrix}@enddots{}  It defaults to
 @code{org-latex-default-table-environment} value.
 @code{org-latex-default-table-environment} value.
+@item :caption
+@code{#+CAPTION} keyword is the simplest way to set a caption for a table
+(@pxref{Images and tables}).  If you need more advanced commands for that
+task, you can use @code{:caption} attribute instead.  Its value should be raw
+@LaTeX{} code.  It has precedence over @code{#+CAPTION}.
 @item :float
 @item :float
 @itemx :placement
 @itemx :placement
 Float environment for the table.  Possible values are @code{sidewaystable},
 Float environment for the table.  Possible values are @code{sidewaystable},
@@ -11651,6 +11675,16 @@ a table that will span over multiple pages, or a matrix product:
 | 3 | 4 |
 | 3 | 4 |
 @end example
 @end example
 
 
+In the example below, @LaTeX{} command
+@code{\bicaption@{HeadingA@}@{HeadingB@}} will set the caption.
+
+@example
+#+ATTR_LATEX: :caption \bicaption@{HeadingA@}@{HeadingB@}
+| ..... | ..... |
+| ..... | ..... |
+@end example
+
+
 @subsubheading Images in @LaTeX{} export
 @subsubheading Images in @LaTeX{} export
 @cindex images, inline in @LaTeX{}
 @cindex images, inline in @LaTeX{}
 @cindex inlining images in @LaTeX{}
 @cindex inlining images in @LaTeX{}
@@ -11672,6 +11706,14 @@ example:
 [[./img/sed-hr4049.pdf]]
 [[./img/sed-hr4049.pdf]]
 @end example
 @end example
 
 
+If you need a specific command for the caption, use @code{:caption}
+attribute.  It will override standard @code{#+CAPTION} value, if any.
+
+@example
+#+ATTR_LATEX: :caption \bicaption@{HeadingA@}@{HeadingB@}
+[[./img/sed-hr4049.pdf]]
+@end example
+
 If you have specified a caption as described in @ref{Images and tables}, the
 If you have specified a caption as described in @ref{Images and tables}, the
 picture will be wrapped into a @code{figure} environment and thus become
 picture will be wrapped into a @code{figure} environment and thus become
 a floating element.  You can also ask Org to export an image as a float
 a floating element.  You can also ask Org to export an image as a float
@@ -11768,6 +11810,17 @@ Therefore, any even number greater than 2 is the sum of two primes.
 \end@{proof@}
 \end@{proof@}
 @end example
 @end example
 
 
+If you need to insert a specific caption command, use @code{:caption}
+attribute.  It will override standard @code{#+CAPTION} value, if any.  For
+example:
+
+@example
+#+ATTR_LATEX: :caption \MyCaption@{HeadingA@}
+#+BEGIN_PROOF
+...
+#+END_PROOF
+@end example
+
 @subsubheading Horizontal rules
 @subsubheading Horizontal rules
 @cindex horizontal rules, in @LaTeX{} export
 @cindex horizontal rules, in @LaTeX{} export
 
 
@@ -12218,17 +12271,25 @@ and open the formula file with the system-registered application.
 @end table
 @end table
 
 
 @cindex dvipng
 @cindex dvipng
+@cindex imagemagick
 @item PNG images
 @item PNG images
 
 
 This option is activated on a per-file basis with
 This option is activated on a per-file basis with
 
 
 @example
 @example
-#+OPTIONS: LaTeX:dvipng
+#+OPTIONS: tex:dvipng
+@end example
+
+or:
+
+@example
+#+OPTIONS: tex:imagemagick
 @end example
 @end example
 
 
 With this option, @LaTeX{} fragments are processed into PNG images and the
 With this option, @LaTeX{} fragments are processed into PNG images and the
 resulting images are embedded in the exported document.  This method requires
 resulting images are embedded in the exported document.  This method requires
-that the @file{dvipng} program be available on your system.
+that the @file{dvipng} program or @file{imagemagick} suite be available on
+your system.
 @end enumerate
 @end enumerate
 
 
 @node Working with MathML or OpenDocument formula files,  , Working with @LaTeX{} math snippets, Math formatting in ODT export
 @node Working with MathML or OpenDocument formula files,  , Working with @LaTeX{} math snippets, Math formatting in ODT export
@@ -12957,7 +13018,7 @@ the Org buffer and get them translated into @LaTeX{} without using the
 @end group
 @end group
 @end lisp
 @end lisp
 
 
-Three arguments must be provided to a fiter: the code being changed, the
+Three arguments must be provided to a filter: the code being changed, the
 back-end used, and some information about the export process.  You can safely
 back-end used, and some information about the export process.  You can safely
 ignore the third argument for most purposes.  Note the use of
 ignore the third argument for most purposes.  Note the use of
 @code{org-export-derived-backend-p}, which ensures that the filter will only
 @code{org-export-derived-backend-p}, which ensures that the filter will only
@@ -13260,8 +13321,8 @@ string of these options for details.
 @vindex org-html-preamble
 @vindex org-html-preamble
 @vindex org-html-postamble
 @vindex org-html-postamble
 @vindex org-html-table-default-attributes
 @vindex org-html-table-default-attributes
-@vindex org-html-style-include-default
-@vindex org-html-style-include-scripts
+@vindex org-html-head-include-default-style
+@vindex org-html-head-include-scripts
 @multitable @columnfractions 0.32 0.68
 @multitable @columnfractions 0.32 0.68
 @item @code{:html-doctype}          @tab @code{org-html-doctype}
 @item @code{:html-doctype}          @tab @code{org-html-doctype}
 @item @code{:html-xml-declaration}  @tab @code{org-html-xml-declaration}
 @item @code{:html-xml-declaration}  @tab @code{org-html-xml-declaration}
@@ -13275,8 +13336,8 @@ string of these options for details.
 @item @code{:html-preamble}         @tab @code{org-html-preamble}
 @item @code{:html-preamble}         @tab @code{org-html-preamble}
 @item @code{:html-postamble}        @tab @code{org-html-postamble}
 @item @code{:html-postamble}        @tab @code{org-html-postamble}
 @item @code{:html-table-attributes}        @tab @code{org-html-table-default-attributes}
 @item @code{:html-table-attributes}        @tab @code{org-html-table-default-attributes}
-@item @code{:html-head-include-default-style} @tab @code{org-html-style-include-default}
-@item @code{:html-head-include-scripts} @tab @code{org-html-style-include-scripts}
+@item @code{:html-head-include-default-style} @tab @code{org-html-head-include-default-style}
+@item @code{:html-head-include-scripts} @tab @code{org-html-head-include-scripts}
 @end multitable
 @end multitable
 
 
 Most of the @code{org-export-with-*} variables have the same effect in each
 Most of the @code{org-export-with-*} variables have the same effect in each
@@ -14809,7 +14870,7 @@ references will not be expanded when the code block is exported.
 @item @code{strip-export}
 @item @code{strip-export}
 ``Noweb'' syntax references in the body of the code block will be expanded
 ``Noweb'' syntax references in the body of the code block will be expanded
 before the block is evaluated or tangled.  However, ``noweb'' syntax
 before the block is evaluated or tangled.  However, ``noweb'' syntax
-references will not be removed when the code block is exported.
+references will be removed when the code block is exported.
 @item @code{eval}
 @item @code{eval}
 ``Noweb'' syntax references in the body of the code block will only be
 ``Noweb'' syntax references in the body of the code block will only be
 expanded before the block is evaluated.
 expanded before the block is evaluated.
@@ -15185,7 +15246,7 @@ argument.
 @end example
 @end example
 
 
 @node prologue, epilogue, post, Specific header arguments
 @node prologue, epilogue, post, Specific header arguments
-
+@subsubsection @code{:prologue}
 The value of the @code{prologue} header argument will be prepended to the
 The value of the @code{prologue} header argument will be prepended to the
 code block body before execution.  For example, @code{:prologue "reset"} may
 code block body before execution.  For example, @code{:prologue "reset"} may
 be used to reset a gnuplot session before execution of a particular code
 be used to reset a gnuplot session before execution of a particular code
@@ -15198,7 +15259,7 @@ code blocks.  Also see @ref{epilogue}.
 @end lisp
 @end lisp
 
 
 @node epilogue, , prologue, Specific header arguments
 @node epilogue, , prologue, Specific header arguments
-
+@subsubsection @code{:epilogue}
 The value of the @code{epilogue} header argument will be appended to the code
 The value of the @code{epilogue} header argument will be appended to the code
 block body before execution.  Also see @ref{prologue}.
 block body before execution.  Also see @ref{prologue}.
 
 

+ 7 - 2
lisp/ob-R.el

@@ -93,8 +93,13 @@
 	     inside
 	     inside
 	     (list "dev.off()"))
 	     (list "dev.off()"))
 	  inside))
 	  inside))
-      (append (org-babel-variable-assignments:R params)
-	      (list body))) "\n")))
+      (append
+       (when (cdr (assoc :prologue params))
+	 (list (cdr (assoc :prologue params))))
+       (org-babel-variable-assignments:R params)
+       (list body)
+       (when (cdr (assoc :epilogue params))
+	 (list (cdr (assoc :epilogue params)))))) "\n")))
 
 
 (defun org-babel-execute:R (body params)
 (defun org-babel-execute:R (body params)
   "Execute a block of R code.
   "Execute a block of R code.

+ 37 - 34
lisp/ob-core.el

@@ -301,10 +301,10 @@ name of the code block."
 	    (noeval          (or ,eval-no ,eval-no-export))
 	    (noeval          (or ,eval-no ,eval-no-export))
 	    (query           (or (equal ,eval "query")
 	    (query           (or (equal ,eval "query")
 				 (and ,export (equal ,eval "query-export"))
 				 (and ,export (equal ,eval "query-export"))
-				 (when (functionp org-confirm-babel-evaluate)
-				   (funcall org-confirm-babel-evaluate
-					    ,lang ,block-body))
-				 org-confirm-babel-evaluate))
+				 (if (functionp org-confirm-babel-evaluate)
+				     (funcall org-confirm-babel-evaluate
+					      ,lang ,block-body)
+				   org-confirm-babel-evaluate)))
 	    (code-block      (if ,info (format  " %s "  ,lang) " "))
 	    (code-block      (if ,info (format  " %s "  ,lang) " "))
 	    (block-name      (if ,name (format " (%s) " ,name) " ")))
 	    (block-name      (if ,name (format " (%s) " ,name) " ")))
        ,@body)))
        ,@body)))
@@ -562,7 +562,11 @@ Optionally supply a value for PARAMS which will be merged with
 the header arguments specified at the front of the source code
 the header arguments specified at the front of the source code
 block."
 block."
   (interactive)
   (interactive)
-  (let* ((info (if info
+  (let* ((org-babel-current-src-block-location
+	  (or org-babel-current-src-block-location
+	      (nth 6 info)
+	      (org-babel-where-is-src-block-head)))
+	 (info (if info
 		   (copy-tree info)
 		   (copy-tree info)
 		 (org-babel-get-src-block-info)))
 		 (org-babel-get-src-block-info)))
 	 (merged-params (org-babel-merge-params (nth 2 info) params)))
 	 (merged-params (org-babel-merge-params (nth 2 info) params)))
@@ -571,8 +575,6 @@ block."
       (let* ((params (if params
       (let* ((params (if params
 			 (org-babel-process-params merged-params)
 			 (org-babel-process-params merged-params)
 		       (nth 2 info)))
 		       (nth 2 info)))
-	     (org-babel-current-src-block-location
-	      (or org-babel-current-src-block-location (nth 6 info)))
 	     (cachep (and (not arg) (cdr (assoc :cache params))
 	     (cachep (and (not arg) (cdr (assoc :cache params))
 			   (string= "yes" (cdr (assoc :cache params)))))
 			   (string= "yes" (cdr (assoc :cache params)))))
 	     (new-hash (when cachep (org-babel-sha1-hash info)))
 	     (new-hash (when cachep (org-babel-sha1-hash info)))
@@ -1167,9 +1169,12 @@ the current subtree."
 (defun org-babel-set-current-result-hash (hash)
 (defun org-babel-set-current-result-hash (hash)
   "Set the current in-buffer hash to HASH."
   "Set the current in-buffer hash to HASH."
   (org-babel-where-is-src-block-result)
   (org-babel-where-is-src-block-result)
-  (save-excursion (goto-char (match-beginning 3))
-		  ;; (mapc #'delete-overlay (overlays-at (point)))
-		  (replace-match hash nil nil nil 3)
+  (save-excursion (goto-char (match-beginning 5))
+		  (mapc #'delete-overlay (overlays-at (point)))
+		  (forward-char org-babel-hash-show)
+		  (mapc #'delete-overlay (overlays-at (point)))
+		  (replace-match hash nil nil nil 5)
+		  (goto-char (point-at-bol))
 		  (org-babel-hide-hash)))
 		  (org-babel-hide-hash)))
 
 
 (defun org-babel-hide-hash ()
 (defun org-babel-hide-hash ()
@@ -1511,22 +1516,18 @@ names."
 (defun org-babel-get-rownames (table)
 (defun org-babel-get-rownames (table)
   "Return the row names of TABLE.
   "Return the row names of TABLE.
 Return a cons cell, the `car' of which contains the TABLE less
 Return a cons cell, the `car' of which contains the TABLE less
-colnames, and the `cdr' of which contains a list of the column
-names.  Note: this function removes any hlines in TABLE."
-  (let* ((trans (lambda (table) (apply #'mapcar* #'list table)))
-	 (width (apply 'max
-		       (mapcar (lambda (el) (if (listp el) (length el) 0)) table)))
-	 (table (funcall trans (mapcar (lambda (row)
-					 (if (not (equal row 'hline))
-					     row
-					   (setq row '())
-					   (dotimes (n width)
-					     (setq row (cons 'hline row)))
-					   row))
-				       table))))
-    (cons (mapcar (lambda (row) (if (equal (car row) 'hline) 'hline row))
-		  (funcall trans (cdr table)))
-	  (remove 'hline (car table)))))
+rownames, and the `cdr' of which contains a list of the rownames.
+Note: this function removes any hlines in TABLE."
+  (let* ((table (org-babel-del-hlines table))
+	 (rownames (funcall (lambda ()
+			      (let ((tp table))
+				(mapcar
+				 (lambda (row)
+				   (prog1
+				       (pop (car tp))
+				     (setq tp (cdr tp))))
+				 table))))))
+    (cons table rownames)))
 
 
 (defun org-babel-put-colnames (table colnames)
 (defun org-babel-put-colnames (table colnames)
   "Add COLNAMES to TABLE if they exist."
   "Add COLNAMES to TABLE if they exist."
@@ -1719,7 +1720,8 @@ buffer or nil if no such result exists."
 	  (when (and (string= "name" (downcase (match-string 1)))
 	  (when (and (string= "name" (downcase (match-string 1)))
 		     (or (beginning-of-line 1)
 		     (or (beginning-of-line 1)
 			 (looking-at org-babel-src-block-regexp)
 			 (looking-at org-babel-src-block-regexp)
-			 (looking-at org-babel-multi-line-header-regexp)))
+			 (looking-at org-babel-multi-line-header-regexp)
+			 (looking-at org-babel-lob-one-liner-regexp)))
 	    (throw 'is-a-code-block (org-babel-find-named-result name (point))))
 	    (throw 'is-a-code-block (org-babel-find-named-result name (point))))
 	  (beginning-of-line 0) (point))))))
 	  (beginning-of-line 0) (point))))))
 
 
@@ -1796,9 +1798,13 @@ region is not active then the point is demarcated."
 	   (move-end-of-line 2))
 	   (move-end-of-line 2))
          (sort (if (org-region-active-p) (list (mark) (point)) (list (point))) #'>))
          (sort (if (org-region-active-p) (list (mark) (point)) (list (point))) #'>))
       (let ((start (point))
       (let ((start (point))
-	    (lang (org-icompleting-read "Lang: "
-					(mapcar (lambda (el) (symbol-name (car el)))
-						org-babel-load-languages)))
+	    (lang (org-icompleting-read
+		   "Lang: "
+		   (mapcar #'symbol-name
+			   (delete-dups
+			    (append (mapcar #'car org-babel-load-languages)
+				    (mapcar (lambda (el) (intern (car el)))
+					    org-src-lang-modes))))))
 	    (body (delete-and-extract-region
 	    (body (delete-and-extract-region
 		   (if (org-region-active-p) (mark) (point)) (point))))
 		   (if (org-region-active-p) (mark) (point)) (point))))
 	(insert (concat (if (looking-at "^") "" "\n")
 	(insert (concat (if (looking-at "^") "" "\n")
@@ -1824,10 +1830,7 @@ following the source block."
 			  (looking-at org-babel-lob-one-liner-regexp)))
 			  (looking-at org-babel-lob-one-liner-regexp)))
 	   (inlinep (when (org-babel-get-inline-src-block-matches)
 	   (inlinep (when (org-babel-get-inline-src-block-matches)
 		      (match-end 0)))
 		      (match-end 0)))
-	   (name (if on-lob-line
-		     (mapconcat #'identity (butlast (org-babel-lob-get-info))
-				"")
-		   (nth 4 (or info (org-babel-get-src-block-info 'light)))))
+	   (name (nth 4 (or info (org-babel-get-src-block-info 'light))))
 	   (head (unless on-lob-line (org-babel-where-is-src-block-head)))
 	   (head (unless on-lob-line (org-babel-where-is-src-block-head)))
 	   found beg end)
 	   found beg end)
       (when head (goto-char head))
       (when head (goto-char head))

+ 7 - 1
lisp/ob-ditaa.el

@@ -58,6 +58,11 @@
   :group 'org-babel
   :group 'org-babel
   :type 'string)
   :type 'string)
 
 
+(defcustom org-babel-ditaa-java-cmd "java"
+  "Java executable to use when evaluating ditaa blocks."
+  :group 'org-babel
+  :type 'string)
+
 (defcustom org-ditaa-eps-jar-path
 (defcustom org-ditaa-eps-jar-path
   (expand-file-name "DitaaEps.jar" (file-name-directory org-ditaa-jar-path))
   (expand-file-name "DitaaEps.jar" (file-name-directory org-ditaa-jar-path))
   "Path to the DitaaEps.jar executable."
   "Path to the DitaaEps.jar executable."
@@ -86,7 +91,8 @@ This function is called by `org-babel-execute-src-block'."
 	 (java (cdr (assoc :java params)))
 	 (java (cdr (assoc :java params)))
 	 (in-file (org-babel-temp-file "ditaa-"))
 	 (in-file (org-babel-temp-file "ditaa-"))
 	 (eps (cdr (assoc :eps params)))
 	 (eps (cdr (assoc :eps params)))
-	 (cmd (concat "java " java " " org-ditaa-jar-option " "
+	 (cmd (concat org-babel-ditaa-java-cmd
+		      " " java " " org-ditaa-jar-option " "
 		      (shell-quote-argument
 		      (shell-quote-argument
 		       (expand-file-name
 		       (expand-file-name
 			(if eps org-ditaa-eps-jar-path org-ditaa-jar-path)))
 			(if eps org-ditaa-eps-jar-path org-ditaa-jar-path)))

+ 2 - 2
lisp/ob-exp.el

@@ -217,9 +217,9 @@ this template."
 					     (concat
 					     (concat
 					      ":var results="
 					      ":var results="
 					      (mapconcat 'identity
 					      (mapconcat 'identity
-							 (butlast lob-info)
+							 (butlast lob-info 2)
 							 " ")))))))
 							 " ")))))))
-				  "" nil (car (last lob-info)))
+				  "" (nth 3 lob-info) (nth 2 lob-info))
 			    'lob))
 			    'lob))
 			  (rep (org-fill-template
 			  (rep (org-fill-template
 				org-babel-exp-call-line-template
 				org-babel-exp-call-line-template

+ 49 - 1
lisp/ob-latex.el

@@ -50,6 +50,17 @@
   '((:results . "latex") (:exports . "results"))
   '((:results . "latex") (:exports . "results"))
   "Default arguments to use when evaluating a LaTeX source block.")
   "Default arguments to use when evaluating a LaTeX source block.")
 
 
+(defcustom org-babel-latex-htlatex nil
+  "The htlatex command to enable conversion of latex to SVG or HTML."
+  :group 'org-babel
+  :type 'string)
+
+(defcustom org-babel-latex-htlatex-packages
+  '("[usenames]{color}" "{tikz}" "{color}" "{listings}" "{amsmath}")
+  "Packages to use for htlatex export."
+  :group 'org-babel
+  :type '(list string))
+
 (defun org-babel-expand-body:latex (body params)
 (defun org-babel-expand-body:latex (body params)
   "Expand BODY according to PARAMS, return the expanded body."
   "Expand BODY according to PARAMS, return the expanded body."
   (mapc (lambda (pair) ;; replace variables
   (mapc (lambda (pair) ;; replace variables
@@ -84,7 +95,11 @@ This function is called by `org-babel-execute-src-block'."
          ((and (string-match "\\.png$" out-file) (not imagemagick))
          ((and (string-match "\\.png$" out-file) (not imagemagick))
           (org-create-formula-image
           (org-create-formula-image
            body out-file org-format-latex-options in-buffer))
            body out-file org-format-latex-options in-buffer))
-         ((or (string-match "\\.pdf$" out-file) imagemagick)
+         ((string-match "\\.tikz$" out-file)
+	  (when (file-exists-p out-file) (delete-file out-file))
+	  (with-temp-file out-file
+	    (insert body)))
+	 ((or (string-match "\\.pdf$" out-file) imagemagick)
 	  (with-temp-file tex-file
 	  (with-temp-file tex-file
 	    (require 'ox-latex)
 	    (require 'ox-latex)
 	    (insert
 	    (insert
@@ -124,6 +139,39 @@ This function is called by `org-babel-execute-src-block'."
 	       transient-pdf-file out-file im-in-options im-out-options)
 	       transient-pdf-file out-file im-in-options im-out-options)
 	      (when (file-exists-p transient-pdf-file)
 	      (when (file-exists-p transient-pdf-file)
 		(delete-file transient-pdf-file))))))
 		(delete-file transient-pdf-file))))))
+	 ((and (or (string-match "\\.svg$" out-file)
+		   (string-match "\\.html$" out-file))
+	       org-babel-latex-htlatex)
+	  (with-temp-file tex-file
+	    (insert (concat
+		     "\\documentclass[preview]{standalone}
+\\def\\pgfsysdriver{pgfsys-tex4ht.def}
+"
+		     (mapconcat (lambda (pkg)
+				  (concat "\\usepackage" pkg))
+				org-babel-latex-htlatex-packages
+				"\n")
+		     "\\begin{document}"
+		     body
+		     "\\end{document}")))
+	  (when (file-exists-p out-file) (delete-file out-file))
+	  (let ((default-directory (file-name-directory tex-file)))
+	    (shell-command (format "%s %s" org-babel-latex-htlatex tex-file)))
+	  (cond
+	   ((file-exists-p (concat (file-name-sans-extension tex-file) "-1.svg"))
+	    (if (string-match "\\.svg$" out-file)
+		(progn
+		  (shell-command "pwd")
+		  (shell-command (format "mv %s %s"
+					 (concat (file-name-sans-extension tex-file) "-1.svg")
+					 out-file)))
+	      (error "SVG file produced but HTML file requested.")))
+	   ((file-exists-p (concat (file-name-sans-extension tex-file) ".html"))
+	    (if (string-match "\\.html$" out-file)
+		(shell-command "mv %s %s"
+			       (concat (file-name-base tex-file) ".html")
+			       out-file)
+	      (error "HTML file produced but SVG file requested.")))))
          ((string-match "\\.\\([^\\.]+\\)$" out-file)
          ((string-match "\\.\\([^\\.]+\\)$" out-file)
           (error "Can not create %s files, please specify a .png or .pdf file or try the :imagemagick header argument"
           (error "Can not create %s files, please specify a .png or .pdf file or try the :imagemagick header argument"
 		 (match-string 1 out-file))))
 		 (match-string 1 out-file))))

+ 11 - 3
lisp/ob-lob.el

@@ -114,12 +114,20 @@ if so then run the appropriate source block from the Library."
 			  (or (funcall nonempty 8 19) ""))
 			  (or (funcall nonempty 8 19) ""))
 		  (funcall nonempty 9 18)))
 		  (funcall nonempty 9 18)))
 	 (list (length (if (= (length (match-string 12)) 0)
 	 (list (length (if (= (length (match-string 12)) 0)
-			   (match-string 2) (match-string 11)))))))))
+			   (match-string 2) (match-string 11)))
+	       (save-excursion
+		 (forward-line -1)
+		 (and (looking-at (concat org-babel-src-name-regexp
+					  "\\([^\n]*\\)$"))
+		      (org-no-properties (match-string 1))))))))))
 
 
 (defvar org-babel-default-header-args:emacs-lisp) ; Defined in ob-emacs-lisp.el
 (defvar org-babel-default-header-args:emacs-lisp) ; Defined in ob-emacs-lisp.el
 (defun org-babel-lob-execute (info)
 (defun org-babel-lob-execute (info)
   "Execute the lob call specified by INFO."
   "Execute the lob call specified by INFO."
-  (let* ((mkinfo (lambda (p) (list "emacs-lisp" "results" p nil nil (nth 2 info))))
+  (let* ((mkinfo (lambda (p)
+		   (list "emacs-lisp" "results" p nil
+			 (nth 3 info) ;; name
+			 (nth 2 info))))
 	 (pre-params (apply #'org-babel-merge-params
 	 (pre-params (apply #'org-babel-merge-params
 			    org-babel-default-header-args
 			    org-babel-default-header-args
 			    org-babel-default-header-args:emacs-lisp
 			    org-babel-default-header-args:emacs-lisp
@@ -130,7 +138,7 @@ if so then run the appropriate source block from the Library."
 			       (org-no-properties
 			       (org-no-properties
 				(concat
 				(concat
 				 ":var results="
 				 ":var results="
-				 (mapconcat #'identity (butlast info)
+				 (mapconcat #'identity (butlast info 2)
 					    " "))))))))
 					    " "))))))))
 	 (pre-info (funcall mkinfo pre-params))
 	 (pre-info (funcall mkinfo pre-params))
 	 (cache-p (and (cdr (assoc :cache pre-params))
 	 (cache-p (and (cdr (assoc :cache pre-params))

+ 4 - 1
lisp/ob-ref.el

@@ -83,7 +83,10 @@ the variable."
     (let ((var (match-string 1 assignment))
     (let ((var (match-string 1 assignment))
 	  (ref (match-string 2 assignment)))
 	  (ref (match-string 2 assignment)))
       (cons (intern var)
       (cons (intern var)
-	    (let ((out (org-babel-read ref)))
+	    (let ((out (save-excursion
+			 (when org-babel-current-src-block-location
+			   (goto-char org-babel-current-src-block-location))
+			 (org-babel-read ref))))
 	      (if (equal out ref)
 	      (if (equal out ref)
 		  (if (string-match "^\".*\"$" ref)
 		  (if (string-match "^\".*\"$" ref)
 		      (read ref)
 		      (read ref)

+ 129 - 76
lisp/ob-scheme.el

@@ -2,7 +2,7 @@
 
 
 ;; Copyright (C) 2010-2013 Free Software Foundation, Inc.
 ;; Copyright (C) 2010-2013 Free Software Foundation, Inc.
 
 
-;; Author: Eric Schulte
+;; Authors: Eric Schulte, Michael Gauland
 ;; Keywords: literate programming, reproducible research, scheme
 ;; Keywords: literate programming, reproducible research, scheme
 ;; Homepage: http://orgmode.org
 ;; Homepage: http://orgmode.org
 
 
@@ -33,27 +33,25 @@
 ;; - a working scheme implementation
 ;; - a working scheme implementation
 ;;   (e.g. guile http://www.gnu.org/software/guile/guile.html)
 ;;   (e.g. guile http://www.gnu.org/software/guile/guile.html)
 ;;
 ;;
-;; - for session based evaluation cmuscheme.el is required which is
-;;   included in Emacs
+;; - for session based evaluation geiser is required, which is available from
+;;   ELPA.
 
 
 ;;; Code:
 ;;; Code:
 (require 'ob)
 (require 'ob)
-(eval-when-compile (require 'cl))
+(require 'geiser nil t)
+(defvar geiser-repl--repl)             ; Defined in geiser-repl.el
+(defvar geiser-impl--implementation)   ; Defined in geiser-impl.el
+(defvar geiser-default-implementation) ; Defined in geiser-impl.el
+(defvar geiser-active-implementations) ; Defined in geiser-impl.el
 
 
-(declare-function run-scheme "ext:cmuscheme" (cmd))
+(declare-function run-geiser "geiser-repl" (impl))
+(declare-function geiser-mode "geiser-mode" ())
+(declare-function geiser-eval-region "geiser-mode" (start end &optional and-go raw nomsg))
+(declare-function geiser-repl-exit "geiser-repl" (&optional arg))
 
 
 (defvar org-babel-default-header-args:scheme '()
 (defvar org-babel-default-header-args:scheme '()
   "Default header arguments for scheme code blocks.")
   "Default header arguments for scheme code blocks.")
 
 
-(defvar org-babel-scheme-eoe "org-babel-scheme-eoe"
-  "String to indicate that evaluation has completed.")
-
-(defcustom org-babel-scheme-cmd "guile"
-  "Name of command used to evaluate scheme blocks."
-  :group 'org-babel
-  :version "24.1"
-  :type 'string)
-
 (defun org-babel-expand-body:scheme (body params)
 (defun org-babel-expand-body:scheme (body params)
   "Expand BODY according to PARAMS, return the expanded body."
   "Expand BODY according to PARAMS, return the expanded body."
   (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
   (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
@@ -65,72 +63,127 @@
                 ")\n" body ")")
                 ")\n" body ")")
       body)))
       body)))
 
 
-(defvar scheme-program-name)
+
+(defvar org-babel-scheme-repl-map (make-hash-table :test 'equal)
+  "Map of scheme sessions to session names.")
+
+(defun org-babel-scheme-cleanse-repl-map ()
+  "Remove dead buffers from the REPL map."
+  (maphash
+   (lambda (x y)
+     (when (not (buffer-name y))
+       (remhash x org-babel-scheme-repl-map)))
+   org-babel-scheme-repl-map))
+
+(defun org-babel-scheme-get-session-buffer (session-name)
+  "Look up the scheme buffer for a session; return nil if it doesn't exist."
+  (org-babel-scheme-cleanse-repl-map) ; Prune dead sessions
+  (gethash session-name org-babel-scheme-repl-map))
+
+(defun org-babel-scheme-set-session-buffer (session-name buffer)
+  "Record the scheme buffer used for a given session."
+  (puthash session-name buffer org-babel-scheme-repl-map))
+
+(defun org-babel-scheme-get-buffer-impl (buffer)
+  "Returns the scheme implementation geiser associates with the buffer."
+  (with-current-buffer (set-buffer buffer)
+    geiser-impl--implementation))
+
+(defun org-babel-scheme-get-repl (impl name)
+  "Switch to a scheme REPL, creating it if it doesn't exist:"
+  (let ((buffer (org-babel-scheme-get-session-buffer name)))
+    (or buffer
+	(progn
+	  (run-geiser impl)
+	  (if name
+	      (progn
+		(rename-buffer name t)
+		(org-babel-scheme-set-session-buffer name (current-buffer))))
+	  (current-buffer)))))
+
+(defun org-babel-scheme-make-session-name (buffer name impl)
+  "Generate a name for the session buffer.
+
+For a named session, the buffer name will be the session name.
+
+If the session is unnamed (nil), generate a name.
+
+If the session is 'none', use nil for the session name, and
+org-babel-scheme-execute-with-geiser will use a temporary session."
+  (let ((result
+	 (cond ((not name)
+		(concat buffer " " (symbol-name impl) " REPL"))
+	       ((string= name "none") nil)
+	       (name))))
+    result))
+
+(defun org-babel-scheme-execute-with-geiser (code output impl repl)
+  "Execute code in specified REPL. If the REPL doesn't exist, create it
+using the given scheme implementation.
+
+Returns the output of executing the code if the output parameter
+is true; otherwise returns the last value."
+  (let ((result nil))
+    (with-temp-buffer
+      (insert (format ";; -*- geiser-scheme-implementation: %s -*-" impl))
+      (newline)
+      (insert (if output
+		  (format "(with-output-to-string (lambda () %s))" code)
+		code))
+      (geiser-mode)
+      (let ((repl-buffer (save-current-buffer
+			   (org-babel-scheme-get-repl impl repl))))
+	(when (not (eq impl (org-babel-scheme-get-buffer-impl
+			     (current-buffer))))
+	  (message "Implementation mismatch: %s (%s) %s (%s)" impl (symbolp impl)
+		   (org-babel-scheme-get-buffer-impl (current-buffer))
+		   (symbolp (org-babel-scheme-get-buffer-impl
+			     (current-buffer)))))
+	(setq geiser-repl--repl repl-buffer)
+	(setq geiser-impl--implementation nil)
+	(geiser-eval-region (point-min) (point-max))
+	(setq result
+	      (if (equal (substring (current-message) 0 3) "=> ")
+		  (replace-regexp-in-string "^=> " "" (current-message))
+		"\"An error occurred.\""))
+	(when (not repl)
+	  (save-current-buffer (set-buffer repl-buffer)
+			       (geiser-repl-exit))
+	  (set-process-query-on-exit-flag (get-buffer-process repl-buffer) nil)
+	  (kill-buffer repl-buffer))
+	(setq result (if (or (string= result "#<void>")
+			     (string= result "#<unspecified>"))
+			 nil
+		       (read result)))))
+    result))
+
 (defun org-babel-execute:scheme (body params)
 (defun org-babel-execute:scheme (body params)
   "Execute a block of Scheme code with org-babel.
   "Execute a block of Scheme code with org-babel.
 This function is called by `org-babel-execute-src-block'"
 This function is called by `org-babel-execute-src-block'"
-  (let* ((result-type (cdr (assoc :result-type params)))
-	 (org-babel-scheme-cmd (or (cdr (assoc :scheme params))
-				   org-babel-scheme-cmd))
-         (full-body (org-babel-expand-body:scheme body params))
-	 (result (if (not (string= (cdr (assoc :session params)) "none"))
-		     ;; session evaluation
-		     (let ((session (org-babel-prep-session:scheme
-				     (cdr (assoc :session params)) params)))
-		       (org-babel-comint-with-output
-			   (session (format "%S" org-babel-scheme-eoe) t body)
-			 (mapc
-			  (lambda (line)
-			    (insert (org-babel-chomp line))
-			    (comint-send-input nil t))
-			  (list body (format "%S" org-babel-scheme-eoe)))))
-		   ;; external evaluation
-		   (let ((script-file (org-babel-temp-file "scheme-script-")))
-		     (with-temp-file script-file
-		       (insert
-			;; return the value or the output
-			(if (string= result-type "value")
-			    (format "(display %s)" full-body)
-			  full-body)))
-		     (org-babel-eval
-		      (format "%s %s" org-babel-scheme-cmd
-			      (org-babel-process-file-name script-file)) "")))))
-    (org-babel-result-cond (cdr (assoc :result-params params))
-      result (read result))))
-
-(defun org-babel-prep-session:scheme (session params)
-  "Prepare SESSION according to the header arguments specified in PARAMS."
-  (let* ((session (org-babel-scheme-initiate-session session))
-	 (vars (mapcar #'cdr (org-babel-get-header params :var)))
-	 (var-lines
-	  (mapcar
-	   (lambda (var) (format "%S" (print `(define ,(car var) ',(cdr var)))))
-	   vars)))
-    (when session
-      (org-babel-comint-in-buffer session
-	(sit-for .5) (goto-char (point-max))
-	(mapc (lambda (var)
-		(insert var) (comint-send-input nil t)
-		(org-babel-comint-wait-for-output session)
-		(sit-for .1) (goto-char (point-max))) var-lines)))
-    session))
-
-(defun org-babel-scheme-initiate-session (&optional session)
-  "If there is not a current inferior-process-buffer in SESSION
-then create.  Return the initialized session."
-  (require 'cmuscheme)
-  (unless (string= session "none")
-    (let ((session-buffer (save-window-excursion
-			    (run-scheme org-babel-scheme-cmd)
-			    (rename-buffer session)
-			    (current-buffer))))
-      (if (org-babel-comint-buffer-livep session-buffer)
-	  (progn (sit-for .25) session-buffer)
-        (sit-for .5)
-        (org-babel-scheme-initiate-session session)))))
+  (let* ((source-buffer (current-buffer))
+	 (source-buffer-name (replace-regexp-in-string ;; zap surrounding *
+			      "^ ?\\*\\([^*]+\\)\\*" "\\1"
+			      (buffer-name source-buffer))))
+    (save-excursion
+      (org-babel-reassemble-table
+       (let* ((result-type (cdr (assoc :result-type params)))
+	      (impl (or (when (cdr (assoc :scheme params))
+			  (intern (cdr (assoc :scheme params))))
+			geiser-default-implementation
+			(car geiser-active-implementations)))
+	      (session (org-babel-scheme-make-session-name
+			source-buffer-name (cdr (assoc :session params)) impl))
+	      (full-body (org-babel-expand-body:scheme body params)))
+	 (org-babel-scheme-execute-with-geiser
+	  full-body			 ; code
+	  (string= result-type "output") ; output?
+	  impl				 ; implementation
+	  (and (not (string= session "none")) session))) ; session
+       (org-babel-pick-name (cdr (assoc :colname-names params))
+			    (cdr (assoc :colnames params)))
+       (org-babel-pick-name (cdr (assoc :rowname-names params))
+			    (cdr (assoc :rownames params)))))))
 
 
 (provide 'ob-scheme)
 (provide 'ob-scheme)
 
 
-
-
 ;;; ob-scheme.el ends here
 ;;; ob-scheme.el ends here

+ 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) (or (listp (car var)) 'hline))
+     ((and (listp var) (or (listp (car var)) (equal (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"))

+ 5 - 3
lisp/ob-table.el

@@ -97,9 +97,11 @@ as shown in the example below.
 				(lambda (el)
 				(lambda (el)
 				  (if (eq '$ el)
 				  (if (eq '$ el)
 				      (prog1 nil (setq quote t))
 				      (prog1 nil (setq quote t))
-				    (prog1 (if quote
-					       (format "\"%s\"" el)
-					     (org-no-properties el))
+				    (prog1
+					(cond
+					 (quote (format "\"%s\"" el))
+					 ((stringp el) (org-no-properties el))
+					 (t el))
 				      (setq quote nil))))
 				      (setq quote nil))))
 				(cdr var)))))
 				(cdr var)))))
 	     variables)))
 	     variables)))

+ 15 - 11
lisp/org-agenda.el

@@ -3130,9 +3130,10 @@ longer string it is used as a tags/todo match string.
 Parameters are alternating variable names and values that will be bound
 Parameters are alternating variable names and values that will be bound
 before running the agenda command."
 before running the agenda command."
   (org-eval-in-environment (org-make-parameter-alist parameters)
   (org-eval-in-environment (org-make-parameter-alist parameters)
-    (if (> (length cmd-key) 2)
-	(org-tags-view nil cmd-key)
-      (org-agenda nil cmd-key)))
+    (let (org-agenda-sticky)
+      (if (> (length cmd-key) 2)
+	  (org-tags-view nil cmd-key)
+	(org-agenda nil cmd-key))))
   (set-buffer org-agenda-buffer-name)
   (set-buffer org-agenda-buffer-name)
   (princ (buffer-string)))
   (princ (buffer-string)))
 
 
@@ -3879,7 +3880,7 @@ continue from there."
       (throw :skip t))))
       (throw :skip t))))
 
 
 (defun org-agenda-skip-eval (form)
 (defun org-agenda-skip-eval (form)
-  "If FORM is a function or a list, call (or eval) is and return result.
+  "If FORM is a function or a list, call (or eval) it and return the result.
 `save-excursion' and `save-match-data' are wrapped around the call, so point
 `save-excursion' and `save-match-data' are wrapped around the call, so point
 and match data are returned to the previous state no matter what these
 and match data are returned to the previous state no matter what these
 functions do."
 functions do."
@@ -7308,12 +7309,15 @@ The category is that of the current line."
 	   org-agenda-category-filter)
 	   org-agenda-category-filter)
       (org-agenda-filter-show-all-cat)
       (org-agenda-filter-show-all-cat)
     (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
     (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
-      (if (and cat (not (string= "" cat)))
-	  (org-agenda-filter-apply
-	   (setq org-agenda-category-filter
-		 (list (concat (if strip "-" "+") cat)))
-	   'category)
-	(error "No category at point")))))
+      (cond
+       ((and cat strip)
+        (org-agenda-filter-apply
+         (push (concat "-" cat) org-agenda-category-filter) 'category))
+       ((and cat)
+        (org-agenda-filter-apply
+         (setq org-agenda-category-filter
+	       (list (concat "+" cat))) 'category))
+       ((error "No category at point"))))))
 
 
 (defun org-find-top-headline (&optional pos)
 (defun org-find-top-headline (&optional pos)
   "Find the topmost parent headline and return it."
   "Find the topmost parent headline and return it."
@@ -8375,7 +8379,7 @@ Point is in the buffer where the item originated.")
 	    (if (and confirm
 	    (if (and confirm
 		     (not (y-or-n-p "Archive this subtree or entry? ")))
 		     (not (y-or-n-p "Archive this subtree or entry? ")))
 		(error "Abort")
 		(error "Abort")
-	      (save-excursion
+	      (save-window-excursion
 		(goto-char pos)
 		(goto-char pos)
 		(let ((org-agenda-buffer-name bufname-orig))
 		(let ((org-agenda-buffer-name bufname-orig))
 		  (org-remove-subtree-entries-from-agenda))
 		  (org-remove-subtree-entries-from-agenda))

+ 2 - 1
lisp/org-capture.el

@@ -909,7 +909,8 @@ Store them in the capture property list."
 				(current-time))))
 				(current-time))))
 	      (org-capture-put
 	      (org-capture-put
 	       :default-time
 	       :default-time
-	       (cond ((and (not org-time-was-given)
+	       (cond ((and (or (not (boundp 'org-time-was-given))
+			       (not org-time-was-given))
 			   (not (= (time-to-days prompt-time) (org-today))))
 			   (not (= (time-to-days prompt-time) (org-today))))
 		      ;; Use 00:00 when no time is given for another date than today?
 		      ;; Use 00:00 when no time is given for another date than today?
 		      (apply 'encode-time (append '(0 0 0) (cdddr (decode-time prompt-time)))))
 		      (apply 'encode-time (append '(0 0 0) (cdddr (decode-time prompt-time)))))

+ 4 - 2
lisp/org-colview.el

@@ -169,8 +169,10 @@ This is the compiled version of the format.")
 			    (get-text-property (point-at-bol) 'face))
 			    (get-text-property (point-at-bol) 'face))
 		       'default))
 		       'default))
 	 (color (list :foreground (face-attribute ref-face :foreground)))
 	 (color (list :foreground (face-attribute ref-face :foreground)))
-	 (face (list color 'org-column ref-face))
-	 (face1 (list color 'org-agenda-column-dateline ref-face))
+	 (font (list :height (face-attribute 'default :height)
+		     :family (face-attribute 'default :family)))
+	 (face (list color font 'org-column ref-face))
+	 (face1 (list color font 'org-agenda-column-dateline ref-face))
 	 (cphr (get-text-property (point-at-bol) 'org-complex-heading-regexp))
 	 (cphr (get-text-property (point-at-bol) 'org-complex-heading-regexp))
 	 pom property ass width f string ov column val modval s2 title calc)
 	 pom property ass width f string ov column val modval s2 title calc)
     ;; Check if the entry is in another buffer.
     ;; Check if the entry is in another buffer.

+ 30 - 26
lisp/org-element.el

@@ -1119,7 +1119,11 @@ Assume point is at the beginning of the item."
 (defun org-element-item-interpreter (item contents)
 (defun org-element-item-interpreter (item contents)
   "Interpret ITEM element as Org syntax.
   "Interpret ITEM element as Org syntax.
 CONTENTS is the contents of the element."
 CONTENTS is the contents of the element."
-  (let* ((bullet (org-list-bullet-string (org-element-property :bullet item)))
+  (let* ((bullet (let ((bullet (org-element-property :bullet item)))
+		   (org-list-bullet-string
+		    (cond ((not (string-match "[0-9a-zA-Z]" bullet)) "- ")
+			  ((eq org-plain-list-ordered-item-terminator ?\)) "1)")
+			  (t "1.")))))
 	 (checkbox (org-element-property :checkbox item))
 	 (checkbox (org-element-property :checkbox item))
 	 (counter (org-element-property :counter item))
 	 (counter (org-element-property :counter item))
 	 (tag (let ((tag (org-element-property :tag item)))
 	 (tag (let ((tag (org-element-property :tag item)))
@@ -1138,10 +1142,11 @@ CONTENTS is the contents of the element."
        (off "[ ] ")
        (off "[ ] ")
        (trans "[-] "))
        (trans "[-] "))
      (and tag (format "%s :: " tag))
      (and tag (format "%s :: " tag))
-     (let ((contents (replace-regexp-in-string
-		      "\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))
-       (if item-starts-with-par-p (org-trim contents)
-	 (concat "\n" contents))))))
+     (when contents
+       (let ((contents (replace-regexp-in-string
+			"\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))
+	 (if item-starts-with-par-p (org-trim contents)
+	   (concat "\n" contents)))))))
 
 
 
 
 ;;;; Plain List
 ;;;; Plain List
@@ -1256,8 +1261,7 @@ Assume point is at the beginning of the list."
 		   (unless (bolp) (forward-line))
 		   (unless (bolp) (forward-line))
 		   (point)))
 		   (point)))
 	   (end (progn (skip-chars-forward " \r\t\n" limit)
 	   (end (progn (skip-chars-forward " \r\t\n" limit)
-		       (skip-chars-backward " \t")
-		       (if (bolp) (point) (line-end-position)))))
+		       (if (= (point) limit) limit (line-beginning-position)))))
       ;; Return value.
       ;; Return value.
       (list 'plain-list
       (list 'plain-list
 	    (nconc
 	    (nconc
@@ -3130,42 +3134,42 @@ Assume point is at the beginning of the link."
 	      ;; abbreviation in it.
 	      ;; abbreviation in it.
 	      raw-link (org-translate-link
 	      raw-link (org-translate-link
 			(org-link-expand-abbrev
 			(org-link-expand-abbrev
-			 (org-match-string-no-properties 1)))
-	      link (org-link-unescape raw-link))
+			 (org-match-string-no-properties 1))))
 	;; Determine TYPE of link and set PATH accordingly.
 	;; Determine TYPE of link and set PATH accordingly.
 	(cond
 	(cond
 	 ;; File type.
 	 ;; File type.
-	 ((or (file-name-absolute-p link) (string-match "^\\.\\.?/" link))
-	  (setq type "file" path link))
+	 ((or (file-name-absolute-p raw-link)
+	      (string-match "^\\.\\.?/" raw-link))
+	  (setq type "file" path raw-link))
 	 ;; Explicit type (http, irc, bbdb...).  See `org-link-types'.
 	 ;; Explicit type (http, irc, bbdb...).  See `org-link-types'.
-	 ((string-match org-link-re-with-space3 link)
-	  (setq type (match-string 1 link) path (match-string 2 link)))
+	 ((string-match org-link-re-with-space3 raw-link)
+	  (setq type (match-string 1 raw-link) path (match-string 2 raw-link)))
 	 ;; Id type: PATH is the id.
 	 ;; Id type: PATH is the id.
-	 ((string-match "^id:\\([-a-f0-9]+\\)" link)
-	  (setq type "id" path (match-string 1 link)))
+	 ((string-match "^id:\\([-a-f0-9]+\\)" raw-link)
+	  (setq type "id" path (match-string 1 raw-link)))
 	 ;; Code-ref type: PATH is the name of the reference.
 	 ;; Code-ref type: PATH is the name of the reference.
-	 ((string-match "^(\\(.*\\))$" link)
-	  (setq type "coderef" path (match-string 1 link)))
+	 ((string-match "^(\\(.*\\))$" raw-link)
+	  (setq type "coderef" path (match-string 1 raw-link)))
 	 ;; Custom-id type: PATH is the name of the custom id.
 	 ;; Custom-id type: PATH is the name of the custom id.
-	 ((= (aref link 0) ?#)
-	  (setq type "custom-id" path (substring link 1)))
+	 ((= (aref raw-link 0) ?#)
+	  (setq type "custom-id" path (substring raw-link 1)))
 	 ;; Fuzzy type: Internal link either matches a target, an
 	 ;; Fuzzy type: Internal link either matches a target, an
 	 ;; headline name or nothing.  PATH is the target or
 	 ;; headline name or nothing.  PATH is the target or
 	 ;; headline's name.
 	 ;; headline's name.
-	 (t (setq type "fuzzy" path link))))
+	 (t (setq type "fuzzy" path raw-link))))
        ;; Type 3: Plain link, i.e. http://orgmode.org
        ;; Type 3: Plain link, i.e. http://orgmode.org
        ((looking-at org-plain-link-re)
        ((looking-at org-plain-link-re)
 	(setq raw-link (org-match-string-no-properties 0)
 	(setq raw-link (org-match-string-no-properties 0)
 	      type (org-match-string-no-properties 1)
 	      type (org-match-string-no-properties 1)
-	      path (org-match-string-no-properties 2)
-	      link-end (match-end 0)))
+	      link-end (match-end 0)
+	      path (org-match-string-no-properties 2)))
        ;; Type 4: Angular link, i.e. <http://orgmode.org>
        ;; Type 4: Angular link, i.e. <http://orgmode.org>
        ((looking-at org-angle-link-re)
        ((looking-at org-angle-link-re)
 	(setq raw-link (buffer-substring-no-properties
 	(setq raw-link (buffer-substring-no-properties
 			(match-beginning 1) (match-end 2))
 			(match-beginning 1) (match-end 2))
 	      type (org-match-string-no-properties 1)
 	      type (org-match-string-no-properties 1)
-	      path (org-match-string-no-properties 2)
-	      link-end (match-end 0))))
+	      link-end (match-end 0)
+	      path (org-match-string-no-properties 2))))
       ;; In any case, deduce end point after trailing white space from
       ;; In any case, deduce end point after trailing white space from
       ;; LINK-END variable.
       ;; LINK-END variable.
       (setq post-blank (progn (goto-char link-end) (skip-chars-forward " \t"))
       (setq post-blank (progn (goto-char link-end) (skip-chars-forward " \t"))
@@ -3182,7 +3186,7 @@ Assume point is at the beginning of the link."
 	(when (string-match "::\\(.*\\)$" path)
 	(when (string-match "::\\(.*\\)$" path)
 	  (setq search-option (match-string 1 path)
 	  (setq search-option (match-string 1 path)
 		path (replace-match "" nil nil path)))
 		path (replace-match "" nil nil path)))
-	;; Make sure TYPE always report "file".
+	;; Make sure TYPE always reports "file".
 	(setq type "file"))
 	(setq type "file"))
       (list 'link
       (list 'link
 	    (list :type type
 	    (list :type type
@@ -3900,7 +3904,7 @@ element it has to parse."
 	    (cond
 	    (cond
 	     ;; Jumping over affiliated keywords put point off-limits.
 	     ;; Jumping over affiliated keywords put point off-limits.
 	     ;; Parse them as regular keywords.
 	     ;; Parse them as regular keywords.
-	     ((>= (point) limit)
+	     ((and (cdr affiliated) (>= (point) limit))
 	      (goto-char (car affiliated))
 	      (goto-char (car affiliated))
 	      (org-element-keyword-parser limit nil))
 	      (org-element-keyword-parser limit nil))
 	     ;; LaTeX Environment.
 	     ;; LaTeX Environment.

+ 0 - 6
lisp/org-faces.el

@@ -217,12 +217,6 @@ column view defines special faces for each outline level.  See the file
   "Face for column display of entry properties."
   "Face for column display of entry properties."
   :group 'org-faces)
   :group 'org-faces)
 
 
-(when (fboundp 'set-face-attribute)
-  ;; Make sure that a fixed-width face is used when we have a column table.
-  (set-face-attribute 'org-column nil
-		      :height (face-attribute 'default :height)
-		      :family (face-attribute 'default :family)))
-
 (defface org-agenda-column-dateline
 (defface org-agenda-column-dateline
   (org-compatible-face 'org-column
   (org-compatible-face 'org-column
     '((t nil)))
     '((t nil)))

+ 9 - 4
lisp/org-list.el

@@ -2799,13 +2799,14 @@ optional argument WITH-CASE, the sorting considers case as well.
 
 
 The command prompts for the sorting type unless it has been given
 The command prompts for the sorting type unless it has been given
 to the function through the SORTING-TYPE argument, which needs to
 to the function through the SORTING-TYPE argument, which needs to
-be a character, \(?n ?N ?a ?A ?t ?T ?f ?F).  Here is the precise
-meaning of each character:
+be a character, \(?n ?N ?a ?A ?t ?T ?f ?F ?x ?X).  Here is the
+detailed meaning of each character:
 
 
 n   Numerically, by converting the beginning of the item to a number.
 n   Numerically, by converting the beginning of the item to a number.
 a   Alphabetically.  Only the first line of item is checked.
 a   Alphabetically.  Only the first line of item is checked.
 t   By date/time, either the first active time stamp in the entry, if
 t   By date/time, either the first active time stamp in the entry, if
     any, or by the first inactive one.  In a timer list, sort the timers.
     any, or by the first inactive one.  In a timer list, sort the timers.
+x   By \"checked\" status of a check list.
 
 
 Capital letters will reverse the sort order.
 Capital letters will reverse the sort order.
 
 
@@ -2827,7 +2828,7 @@ ignores hidden links."
 	  (or sorting-type
 	  (or sorting-type
 	      (progn
 	      (progn
 		(message
 		(message
-		 "Sort plain list: [a]lpha  [n]umeric  [t]ime  [f]unc   A/N/T/F means reversed:")
+		 "Sort plain list: [a]lpha  [n]umeric  [t]ime  [f]unc  [x]checked  A/N/T/F/X means reversed:")
 		(read-char-exclusive))))
 		(read-char-exclusive))))
 	 (getkey-func
 	 (getkey-func
 	  (or getkey-func
 	  (or getkey-func
@@ -2844,7 +2845,8 @@ ignores hidden links."
 	     (sort-func (cond
 	     (sort-func (cond
 			 ((= dcst ?a) 'string<)
 			 ((= dcst ?a) 'string<)
 			 ((= dcst ?f) compare-func)
 			 ((= dcst ?f) compare-func)
-			 ((= dcst ?t) '<)))
+			 ((= dcst ?t) '<)
+			 ((= dcst ?x) 'string<)))
 	     (next-record (lambda ()
 	     (next-record (lambda ()
 			    (skip-chars-forward " \r\t\n")
 			    (skip-chars-forward " \r\t\n")
 			    (or (eobp) (beginning-of-line))))
 			    (or (eobp) (beginning-of-line))))
@@ -2875,6 +2877,9 @@ ignores hidden links."
 							     (point-at-eol) t)))
 							     (point-at-eol) t)))
 		      (org-time-string-to-seconds (match-string 0)))
 		      (org-time-string-to-seconds (match-string 0)))
 		     (t (org-float-time now))))
 		     (t (org-float-time now))))
+		   ((= dcst ?x) (or (and (stringp (match-string 1))
+					 (match-string 1))
+				    ""))
 		   ((= dcst ?f)
 		   ((= dcst ?f)
 		    (if getkey-func
 		    (if getkey-func
 			(let ((value (funcall getkey-func)))
 			(let ((value (funcall getkey-func)))

+ 2 - 2
lisp/org-mouse.el

@@ -656,11 +656,11 @@ This means, between the beginning of line and the point."
 	 ["All Clear" (org-mouse-for-each-item
 	 ["All Clear" (org-mouse-for-each-item
 		       (lambda ()
 		       (lambda ()
 			 (when (save-excursion (org-at-item-checkbox-p))
 			 (when (save-excursion (org-at-item-checkbox-p))
-			   (replace-match "[ ]"))))]
+			   (replace-match "[ ] "))))]
 	 ["All Set" (org-mouse-for-each-item
 	 ["All Set" (org-mouse-for-each-item
 		     (lambda ()
 		     (lambda ()
 		       (when (save-excursion (org-at-item-checkbox-p))
 		       (when (save-excursion (org-at-item-checkbox-p))
-			 (replace-match "[X]"))))]
+			 (replace-match "[X] "))))]
 	 ["All Toggle" (org-mouse-for-each-item 'org-toggle-checkbox) t]
 	 ["All Toggle" (org-mouse-for-each-item 'org-toggle-checkbox) t]
 	 ["All Remove" (org-mouse-for-each-item
 	 ["All Remove" (org-mouse-for-each-item
 			(lambda ()
 			(lambda ()

+ 15 - 10
lisp/org-pcomplete.el

@@ -153,13 +153,16 @@ When completing for #+STARTUP, for example, this function returns
 	    (mapcar (lambda (keyword) (concat keyword ": "))
 	    (mapcar (lambda (keyword) (concat keyword ": "))
 		    org-element-affiliated-keywords)
 		    org-element-affiliated-keywords)
 	    (let (block-names)
 	    (let (block-names)
-	      (mapc (lambda (block-name)
-		      (let ((name (car block-name)))
-			(push (format "END_%s: " name) block-names)
-			(push (format "BEGIN_%s: " name) block-names)
-			(push (format "ATTR_%s: " name) block-names)))
-		    org-element-block-name-alist)
-	      block-names)
+	      (dolist (block-info org-element-block-name-alist block-names)
+		(let ((name (car block-info)))
+		  (push (format "END_%s" name) block-names)
+		  (push (concat "BEGIN_"
+				name
+				;; Since language is compulsory in
+				;; source blocks, add a space.
+				(and (equal name "SRC") " "))
+			block-names)
+		  (push (format "ATTR_%s: " name) block-names))))
 	    (mapcar (lambda (keyword) (concat keyword ": "))
 	    (mapcar (lambda (keyword) (concat keyword ": "))
 		    (org-get-export-keywords))))
 		    (org-get-export-keywords))))
    (substring pcomplete-stub 2)))
    (substring pcomplete-stub 2)))
@@ -254,6 +257,8 @@ When completing for #+STARTUP, for example, this function returns
 		     (file-name-nondirectory visited-file)))
 		     (file-name-nondirectory visited-file)))
 	       (buffer-name (buffer-base-buffer)))))))
 	       (buffer-name (buffer-base-buffer)))))))
 
 
+
+(declare-function org-export-backend-options "org-export" (cl-x))
 (defun pcomplete/org-mode/file-option/options ()
 (defun pcomplete/org-mode/file-option/options ()
   "Complete arguments for the #+OPTIONS file option."
   "Complete arguments for the #+OPTIONS file option."
   (while (pcomplete-here
   (while (pcomplete-here
@@ -266,9 +271,9 @@ When completing for #+STARTUP, for example, this function returns
 	      "|:" "tags:" "tasks:" "<:" "todo:")
 	      "|:" "tags:" "tasks:" "<:" "todo:")
 	    ;; OPTION items from registered back-ends.
 	    ;; OPTION items from registered back-ends.
 	    (let (items)
 	    (let (items)
-	      (dolist (back-end (org-bound-and-true-p
-				 org-export-registered-backends))
-		(dolist (option (plist-get (cdr back-end) :options-alist))
+	      (dolist (backend (org-bound-and-true-p
+				org-export--registered-backends))
+		(dolist (option (org-export-backend-options backend))
 		  (let ((item (nth 2 option)))
 		  (let ((item (nth 2 option)))
 		    (when item (push (concat item ":") items)))))
 		    (when item (push (concat item ":") items)))))
 	      items))))))
 	      items))))))

+ 1 - 1
lisp/org-src.el

@@ -179,7 +179,7 @@ but which mess up the display of a snippet in Org exported files.")
 (defcustom org-src-lang-modes
 (defcustom org-src-lang-modes
   '(("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . artist)
   '(("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . artist)
     ("asymptote" . asy) ("dot" . fundamental) ("sqlite" . sql)
     ("asymptote" . asy) ("dot" . fundamental) ("sqlite" . sql)
-    ("calc" . fundamental) ("C" . c) ("cpp" . c++)
+    ("calc" . fundamental) ("C" . c) ("cpp" . c++) ("C++" . c++)
     ("screen" . shell-script))
     ("screen" . shell-script))
   "Alist mapping languages to their major mode.
   "Alist mapping languages to their major mode.
 The key is the language name, the value is the string that should
 The key is the language name, the value is the string that should

+ 11 - 6
lisp/org-table.el

@@ -1829,11 +1829,16 @@ will be transposed as
 
 
 Note that horizontal lines disappeared."
 Note that horizontal lines disappeared."
   (interactive)
   (interactive)
-  (let ((contents
-         (apply #'mapcar* #'list
-                ;; remove 'hline from list
-		(delq nil (mapcar (lambda (x) (when (listp x) x))
-				  (org-table-to-lisp))))))
+  (let* ((table (delete 'hline (org-table-to-lisp)))
+	 (contents (mapcar (lambda (p)
+			     (let ((tp table))
+			       (mapcar
+				(lambda (rown)
+				  (prog1
+				      (pop (car tp))
+				    (setq tp (cdr tp))))
+				table)))
+			   (car table))))
     (delete-region (org-table-begin) (org-table-end))
     (delete-region (org-table-begin) (org-table-end))
     (insert (mapconcat (lambda(x) (concat "| " (mapconcat 'identity x " | " ) "  |\n" ))
     (insert (mapconcat (lambda(x) (concat "| " (mapconcat 'identity x " | " ) "  |\n" ))
                        contents ""))
                        contents ""))
@@ -2064,7 +2069,7 @@ If NLAST is a number, only the NLAST fields will actually be summed."
 			   h (floor (/ diff 3600)) diff (mod diff 3600)
 			   h (floor (/ diff 3600)) diff (mod diff 3600)
 			   m (floor (/ diff 60)) diff (mod diff 60)
 			   m (floor (/ diff 60)) diff (mod diff 60)
 			   s diff)
 			   s diff)
-		     (format "%d:%02d:%02d" h m s))))
+		     (format "%.0f:%02.0f:%02.0f" h m s))))
 	(kill-new sres)
 	(kill-new sres)
 	(if (org-called-interactively-p 'interactive)
 	(if (org-called-interactively-p 'interactive)
 	    (message "%s"
 	    (message "%s"

+ 182 - 141
lisp/org.el

@@ -436,8 +436,9 @@ For export specific modules, see also `org-export-backends'."
 	(const :tag "C  wl:                Links to Wanderlust folders/messages" org-wl)
 	(const :tag "C  wl:                Links to Wanderlust folders/messages" org-wl)
 	(repeat :tag "External packages" :inline t (symbol :tag "Package"))))
 	(repeat :tag "External packages" :inline t (symbol :tag "Package"))))
 
 
-(defvar org-export-registered-backends)	; From ox.el
+(defvar org-export--registered-backends) ; From ox.el.
 (declare-function org-export-derived-backend-p "ox" (backend &rest backends))
 (declare-function org-export-derived-backend-p "ox" (backend &rest backends))
+(declare-function org-export-backend-name "ox" (backend))
 (defcustom org-export-backends '(ascii html icalendar latex)
 (defcustom org-export-backends '(ascii html icalendar latex)
   "List of export back-ends that should be always available.
   "List of export back-ends that should be always available.
 
 
@@ -451,30 +452,29 @@ needed.
 
 
 This variable needs to be set before org.el is loaded.  If you
 This variable needs to be set before org.el is loaded.  If you
 need to make a change while Emacs is running, use the customize
 need to make a change while Emacs is running, use the customize
-interface or run the following code, where VALUE stands for the
-new value of the variable, after updating it:
+interface or run the following code, where VAL stands for the new
+value of the variable, after updating it:
 
 
   \(progn
   \(progn
-    \(setq org-export-registered-backends
+    \(setq org-export--registered-backends
           \(org-remove-if-not
           \(org-remove-if-not
            \(lambda (backend)
            \(lambda (backend)
-             \(or (memq backend val)
-                 \(catch 'parentp
-                   \(mapc
-                    \(lambda (b)
-                      \(and (org-export-derived-backend-p b (car backend))
-                           \(throw 'parentp t)))
-                    val)
-                   nil)))
-           org-export-registered-backends))
-    \(let ((new-list (mapcar 'car org-export-registered-backends)))
+             \(let ((name (org-export-backend-name backend)))
+               \(or (memq name val)
+                   \(catch 'parentp
+                     \(dolist (b val)
+                       \(and (org-export-derived-backend-p b name)
+                            \(throw 'parentp t)))))))
+           org-export--registered-backends))
+    \(let ((new-list (mapcar 'org-export-backend-name
+                            org-export--registered-backends)))
       \(dolist (backend val)
       \(dolist (backend val)
         \(cond
         \(cond
          \((not (load (format \"ox-%s\" backend) t t))
          \((not (load (format \"ox-%s\" backend) t t))
           \(message \"Problems while trying to load export back-end `%s'\"
           \(message \"Problems while trying to load export back-end `%s'\"
                    backend))
                    backend))
          \((not (memq backend new-list)) (push backend new-list))))
          \((not (memq backend new-list)) (push backend new-list))))
-      \(set-default var new-list)))
+      \(set-default 'org-export-backends new-list)))
 
 
 Adding a back-end to this list will also pull the back-end it
 Adding a back-end to this list will also pull the back-end it
 depends on, if any."
 depends on, if any."
@@ -488,21 +488,20 @@ depends on, if any."
 	   ;; Any back-end not required anymore (not present in VAL and not
 	   ;; Any back-end not required anymore (not present in VAL and not
 	   ;; a parent of any back-end in the new value) is removed from the
 	   ;; a parent of any back-end in the new value) is removed from the
 	   ;; list of registered back-ends.
 	   ;; list of registered back-ends.
-	   (setq org-export-registered-backends
+	   (setq org-export--registered-backends
 		 (org-remove-if-not
 		 (org-remove-if-not
 		  (lambda (backend)
 		  (lambda (backend)
-		    (or (memq backend val)
-			(catch 'parentp
-			  (mapc
-			   (lambda (b)
-			     (and (org-export-derived-backend-p b (car backend))
-				  (throw 'parentp t)))
-			   val)
-			  nil)))
-		  org-export-registered-backends))
+		    (let ((name (org-export-backend-name backend)))
+		      (or (memq name val)
+			  (catch 'parentp
+			    (dolist (b val)
+			      (and (org-export-derived-backend-p b name)
+				   (throw 'parentp t)))))))
+		  org-export--registered-backends))
 	   ;; Now build NEW-LIST of both new back-ends and required
 	   ;; Now build NEW-LIST of both new back-ends and required
 	   ;; parents.
 	   ;; parents.
-	   (let ((new-list (mapcar 'car org-export-registered-backends)))
+	   (let ((new-list (mapcar 'org-export-backend-name
+				   org-export--registered-backends)))
 	     (dolist (backend val)
 	     (dolist (backend val)
 	       (cond
 	       (cond
 		((not (load (format "ox-%s" backend) t t))
 		((not (load (format "ox-%s" backend) t t))
@@ -3765,9 +3764,9 @@ images at the same place."
 \\usepackage[usenames]{color}
 \\usepackage[usenames]{color}
 \\usepackage{amsmath}
 \\usepackage{amsmath}
 \\usepackage[mathscr]{eucal}
 \\usepackage[mathscr]{eucal}
-\\pagestyle{empty}             % do not remove
 \[PACKAGES]
 \[PACKAGES]
 \[DEFAULT-PACKAGES]
 \[DEFAULT-PACKAGES]
+\\pagestyle{empty}             % do not remove
 % The settings below are copied from fullpage.sty
 % The settings below are copied from fullpage.sty
 \\setlength{\\textwidth}{\\paperwidth}
 \\setlength{\\textwidth}{\\paperwidth}
 \\addtolength{\\textwidth}{-3cm}
 \\addtolength{\\textwidth}{-3cm}
@@ -4340,8 +4339,8 @@ If TABLE-TYPE is non-nil, also check for table.el-type tables."
 (defvar org-clock-heading ""
 (defvar org-clock-heading ""
   "The heading of the current clock entry.")
   "The heading of the current clock entry.")
 (defun org-clock-is-active ()
 (defun org-clock-is-active ()
-  "Return non-nil if clock is currently running.
-The return value is actually the clock marker."
+  "Return the buffer where the clock is currently running.
+Return nil if no clock is running."
   (marker-buffer org-clock-marker))
   (marker-buffer org-clock-marker))
 
 
 (eval-and-compile
 (eval-and-compile
@@ -4804,7 +4803,7 @@ Support for group tags is controlled by the option
 	   (if org-group-tags "on" "off")))
 	   (if org-group-tags "on" "off")))
 
 
 (defun org-set-regexps-and-options-for-tags ()
 (defun org-set-regexps-and-options-for-tags ()
-  "Precompute regular expressions used for tags in the current buffer."
+  "Precompute variables used for tags."
   (when (derived-mode-p 'org-mode)
   (when (derived-mode-p 'org-mode)
     (org-set-local 'org-file-tags nil)
     (org-set-local 'org-file-tags nil)
     (let ((re (org-make-options-regexp '("FILETAGS" "TAGS")))
     (let ((re (org-make-options-regexp '("FILETAGS" "TAGS")))
@@ -4836,42 +4835,52 @@ Support for group tags is controlled by the option
 				(mapcar 'org-add-prop-inherited ftags)))
 				(mapcar 'org-add-prop-inherited ftags)))
       (org-set-local 'org-tag-groups-alist nil)
       (org-set-local 'org-tag-groups-alist nil)
       ;; Process the tags.
       ;; Process the tags.
-      ;; FIXME
-      (when tags
-	(let (e tgs g)
-	  (while (setq e (pop tags))
-	    (cond
-	     ((equal e "{")
-	      (progn (push '(:startgroup) tgs)
-		     (when (equal (nth 1 tags) ":")
-		       (push (list (replace-regexp-in-string
-				    "(.+)$" "" (nth 0 tags)))
-			     org-tag-groups-alist)
-		       (setq g 0))))
-	     ((equal e ":") (push '(:grouptags) tgs))
-	     ((equal e "}") (push '(:endgroup) tgs) (if g (setq g nil)))
-	     ((equal e "\\n") (push '(:newline) tgs))
-	     ((string-match (org-re "^\\([[:alnum:]_@#%]+\\)(\\(.\\))$") e)
-	      (push (cons (match-string 1 e)
-			  (string-to-char (match-string 2 e))) tgs)
+      (when (and (not tags) org-tag-alist)
+	(setq tags
+	      (mapcar 
+	       (lambda (tg) (cond ((eq (car tg) :startgroup) "{")
+				  ((eq (car tg) :endgroup) "}")
+				  ((eq (car tg) :grouptags) ":")
+				  ((eq (car tg) :newline) "\n")
+				  (t (concat (car tg)
+					     (if (characterp (cdr tg))
+						 (format "(%s)" (char-to-string (cdr tg))) "")))))
+	       org-tag-alist)))
+      (let (e tgs g)
+	(while (setq e (pop tags))
+	  (cond
+	   ((equal e "{")
+	    (progn (push '(:startgroup) tgs)
+		   (when (equal (nth 1 tags) ":")
+		     (push (list (replace-regexp-in-string
+				  "(.+)$" "" (nth 0 tags)))
+			   org-tag-groups-alist)
+		     (setq g 0))))
+	   ((equal e ":") (push '(:grouptags) tgs))
+	   ((equal e "}") (push '(:endgroup) tgs) (if g (setq g nil)))
+	   ((equal e "\\n") (push '(:newline) tgs))
+	   ((string-match (org-re "^\\([[:alnum:]_@#%]+\\)(\\(.\\))$") e)
+	    (push (cons (match-string 1 e)
+			(string-to-char (match-string 2 e))) tgs)
+	    (if (and g (> g 0))
+		(setcar org-tag-groups-alist
+			(append (car org-tag-groups-alist)
+				(list (match-string 1 e)))))
+	    (if g (setq g (1+ g))))
+	   (t (push (list e) tgs)
 	      (if (and g (> g 0))
 	      (if (and g (> g 0))
 		  (setcar org-tag-groups-alist
 		  (setcar org-tag-groups-alist
-			  (append (car org-tag-groups-alist)
-				  (list (match-string 1 e)))))
-	      (if g (setq g (1+ g))))
-	     (t (push (list e) tgs)
-		(if (and g (> g 0))
-		    (setcar org-tag-groups-alist
-			    (append (car org-tag-groups-alist) (list e))))
-		(if g (setq g (1+ g))))))
-	  (org-set-local 'org-tag-alist nil)
-	  (while (setq e (pop tgs))
-	    (or (and (stringp (car e))
-		     (assoc (car 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))))))
-
+			  (append (car org-tag-groups-alist) (list e))))
+	      (if g (setq g (1+ g))))))
+	(org-set-local 'org-tag-alist nil)
+	(while (setq e (pop tgs))
+	  (or (and (stringp (car e))
+		   (assoc (car 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)))))
+
+(defvar org-ota nil)
 (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."
   (when (derived-mode-p 'org-mode)
   (when (derived-mode-p 'org-mode)
@@ -4901,13 +4910,15 @@ Support for group tags is controlled by the option
 	  (while
 	  (while
 	      (or (and
 	      (or (and
 		   ext-setup-or-nil
 		   ext-setup-or-nil
+		   (not org-ota)
 		   (let (ret)
 		   (let (ret)
 		     (with-temp-buffer
 		     (with-temp-buffer
 		       (insert ext-setup-or-nil)
 		       (insert ext-setup-or-nil)
-		       (let ((major-mode 'org-mode))
+		       (let ((major-mode 'org-mode) org-ota)
 			 (setq ret (save-match-data
 			 (setq ret (save-match-data
 				     (org-set-regexps-and-options-for-tags)))))
 				     (org-set-regexps-and-options-for-tags)))))
 		     ;; Append setupfile tags to existing tags
 		     ;; Append setupfile tags to existing tags
+		     (setq org-ota t)
 		     (setq org-file-tags
 		     (setq org-file-tags
 			   (delq nil (append org-file-tags (nth 0 ret)))
 			   (delq nil (append org-file-tags (nth 0 ret)))
 			   org-tag-alist
 			   org-tag-alist
@@ -5146,8 +5157,8 @@ Support for group tags is controlled by the option
 	    (mapcar (lambda (w) (substring w 0 -1))
 	    (mapcar (lambda (w) (substring w 0 -1))
 		    (list org-scheduled-string org-deadline-string
 		    (list org-scheduled-string org-deadline-string
 			  org-clock-string org-closed-string)))
 			  org-clock-string org-closed-string)))
-      (org-compute-latex-and-related-regexp)
-      (org-set-font-lock-defaults))))
+      (setq org-ota nil)
+      (org-compute-latex-and-related-regexp))))
 
 
 (defun org-file-contents (file &optional noerror)
 (defun org-file-contents (file &optional noerror)
   "Return the contents of FILE, as a string."
   "Return the contents of FILE, as a string."
@@ -5331,6 +5342,7 @@ The following commands are available:
     (setq buffer-display-table org-display-table))
     (setq buffer-display-table org-display-table))
   (org-set-regexps-and-options-for-tags)
   (org-set-regexps-and-options-for-tags)
   (org-set-regexps-and-options)
   (org-set-regexps-and-options)
+  (org-set-font-lock-defaults)
   (when (and org-tag-faces (not org-tags-special-faces-re))
   (when (and org-tag-faces (not org-tags-special-faces-re))
     ;; tag faces set outside customize.... force initialization.
     ;; tag faces set outside customize.... force initialization.
     (org-set-tag-faces 'org-tag-faces org-tag-faces))
     (org-set-tag-faces 'org-tag-faces org-tag-faces))
@@ -8196,8 +8208,8 @@ This is a short-hand for marking the subtree and then cutting it."
   (org-copy-subtree n 'cut))
   (org-copy-subtree n 'cut))
 
 
 (defun org-copy-subtree (&optional n cut force-store-markers nosubtrees)
 (defun org-copy-subtree (&optional n cut force-store-markers nosubtrees)
-  "Cut the current subtree into the clipboard.
-With prefix arg N, cut this many sequential subtrees.
+  "Copy the current subtree it in the clipboard.
+With prefix arg N, copy this many sequential subtrees.
 This is a short-hand for marking the subtree and then copying it.
 This is a short-hand for marking the subtree and then copying it.
 If CUT is non-nil, actually cut the subtree.
 If CUT is non-nil, actually cut the subtree.
 If FORCE-STORE-MARKERS is non-nil, store the relative locations
 If FORCE-STORE-MARKERS is non-nil, store the relative locations
@@ -11482,7 +11494,13 @@ and not actually move anything.
 
 
 With a double prefix arg \\[universal-argument] \\[universal-argument], \
 With a double prefix arg \\[universal-argument] \\[universal-argument], \
 go to the location where the last refiling operation has put the subtree.
 go to the location where the last refiling operation has put the subtree.
-With a prefix argument of `2', refile to the running clock.
+
+With a numeric prefix argument of `2', refile to the running clock.
+
+With a numeric prefix argument of `3', emulate `org-refile-keep'
+being set to `t' and copy to the target location, don't move it.
+Beware that keeping refiled entries may result in duplicated ID
+properties.
 
 
 RFLOC can be a refile location obtained in a different way.
 RFLOC can be a refile location obtained in a different way.
 
 
@@ -11504,8 +11522,8 @@ prefix argument (`C-u C-u C-u C-c C-w')."
 	   (regionp (org-region-active-p))
 	   (regionp (org-region-active-p))
 	   (region-start (and regionp (region-beginning)))
 	   (region-start (and regionp (region-beginning)))
 	   (region-end (and regionp (region-end)))
 	   (region-end (and regionp (region-end)))
-	   (region-length (and regionp (- region-end region-start)))
 	   (filename (buffer-file-name (buffer-base-buffer cbuf)))
 	   (filename (buffer-file-name (buffer-base-buffer cbuf)))
+	   (org-refile-keep (if (equal goto 3) t org-refile-keep))
 	   pos it nbuf file re level reversed)
 	   pos it nbuf file re level reversed)
       (setq last-command nil)
       (setq last-command nil)
       (when regionp
       (when regionp
@@ -11515,7 +11533,9 @@ prefix argument (`C-u C-u C-u C-c C-w')."
 	(unless (or (org-kill-is-subtree-p
 	(unless (or (org-kill-is-subtree-p
 		     (buffer-substring region-start region-end))
 		     (buffer-substring region-start region-end))
 		    (prog1 org-refile-active-region-within-subtree
 		    (prog1 org-refile-active-region-within-subtree
-		      (org-toggle-heading)))
+		      (let ((s (point-at-eol)))
+			(org-toggle-heading)
+			(setq region-end (+ (- (point-at-eol) s) region-end)))))
 	  (user-error "The region is not a (sequence of) subtree(s)")))
 	  (user-error "The region is not a (sequence of) subtree(s)")))
       (if (equal goto '(16))
       (if (equal goto '(16))
 	  (org-refile-goto-last-stored)
 	  (org-refile-goto-last-stored)
@@ -11562,7 +11582,7 @@ prefix argument (`C-u C-u C-u C-c C-w')."
 
 
 	  (setq nbuf (or (find-buffer-visiting file)
 	  (setq nbuf (or (find-buffer-visiting file)
 			 (find-file-noselect file)))
 			 (find-file-noselect file)))
-	  (if goto
+	  (if (and goto (not (equal goto 3)))
 	      (progn
 	      (progn
 		(org-pop-to-buffer-same-window nbuf)
 		(org-pop-to-buffer-same-window nbuf)
 		(goto-char pos)
 		(goto-char pos)
@@ -11597,8 +11617,7 @@ prefix argument (`C-u C-u C-u C-c C-w')."
 		  (if (not (bolp)) (newline))
 		  (if (not (bolp)) (newline))
 		  (org-paste-subtree level)
 		  (org-paste-subtree level)
 		  (when org-log-refile
 		  (when org-log-refile
-		    (org-add-log-setup 'refile nil nil 'findpos
-				       org-log-refile)
+		    (org-add-log-setup 'refile nil nil 'findpos org-log-refile)
 		    (unless (eq org-log-refile 'note)
 		    (unless (eq org-log-refile 'note)
 		      (save-excursion (org-add-log-note))))
 		      (save-excursion (org-add-log-note))))
 		  (and org-auto-align-tags
 		  (and org-auto-align-tags
@@ -11616,8 +11635,10 @@ prefix argument (`C-u C-u C-u C-c C-w')."
 		  (run-hooks 'org-after-refile-insert-hook))))
 		  (run-hooks 'org-after-refile-insert-hook))))
 	    (unless org-refile-keep
 	    (unless org-refile-keep
 	      (if regionp
 	      (if regionp
-		  (delete-region (point) (+ (point) region-length))
-		(org-cut-subtree)))
+		  (delete-region (point) (+ (point) (- region-end region-start)))
+		(delete-region
+		 (and (org-back-to-heading t) (point))
+		 (min (buffer-size) (org-end-of-subtree t t) (point)))))
 	    (when (featurep 'org-inlinetask)
 	    (when (featurep 'org-inlinetask)
 	      (org-inlinetask-remove-END-maybe))
 	      (org-inlinetask-remove-END-maybe))
 	    (setq org-markers-to-move nil)
 	    (setq org-markers-to-move nil)
@@ -11931,22 +11952,21 @@ This function can be used in a hook."
 
 
 ;;;; Completion
 ;;;; Completion
 
 
+(declare-function org-export-backend-name "org-export" (cl-x))
+(declare-function org-export-backend-options "org-export" (cl-x))
 (defun org-get-export-keywords ()
 (defun org-get-export-keywords ()
   "Return a list of all currently understood export keywords.
   "Return a list of all currently understood export keywords.
 Export keywords include options, block names, attributes and
 Export keywords include options, block names, attributes and
 keywords relative to each registered export back-end."
 keywords relative to each registered export back-end."
-  (delq nil
-	(let (keywords)
-	  (mapc
-	   (lambda (back-end)
-	     (let ((props (cdr back-end)))
-	       ;; Back-end name (for keywords, like #+LATEX:)
-	       (push (upcase (symbol-name (car back-end))) keywords)
-	       ;; Back-end options.
-	       (mapc (lambda (option) (push (cadr option) keywords))
-		     (plist-get (cdr back-end) :options-alist))))
-	   (org-bound-and-true-p org-export-registered-backends))
-	  keywords)))
+  (let (keywords)
+    (dolist (backend
+	     (org-bound-and-true-p org-export--registered-backends)
+	     (delq nil keywords))
+      ;; Back-end name (for keywords, like #+LATEX:)
+      (push (upcase (symbol-name (org-export-backend-name backend))) keywords)
+      (dolist (option-entry (org-export-backend-options backend))
+	;; Back-end options.
+	(push (nth 1 option-entry) keywords)))))
 
 
 (defconst org-options-keywords
 (defconst org-options-keywords
   '("ARCHIVE:" "AUTHOR:" "BIND:" "CATEGORY:" "COLUMNS:" "CREATOR:" "DATE:"
   '("ARCHIVE:" "AUTHOR:" "BIND:" "CATEGORY:" "COLUMNS:" "CREATOR:" "DATE:"
@@ -11956,30 +11976,21 @@ keywords relative to each registered export back-end."
     "TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS:"))
     "TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS:"))
 
 
 (defcustom org-structure-template-alist
 (defcustom org-structure-template-alist
-  '(("s" "#+BEGIN_SRC ?\n\n#+END_SRC"
-     "<src lang=\"?\">\n\n</src>")
-    ("e" "#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE"
-     "<example>\n?\n</example>")
-    ("q" "#+BEGIN_QUOTE\n?\n#+END_QUOTE"
-     "<quote>\n?\n</quote>")
-    ("v" "#+BEGIN_VERSE\n?\n#+END_VERSE"
-     "<verse>\n?\n</verse>")
-    ("V" "#+BEGIN_VERBATIM\n?\n#+END_VERBATIM"
-     "<verbatim>\n?\n</verbatim>")
-    ("c" "#+BEGIN_CENTER\n?\n#+END_CENTER"
-     "<center>\n?\n</center>")
+  '(("s" "#+BEGIN_SRC ?\n\n#+END_SRC" "<src lang=\"?\">\n\n</src>")
+    ("e" "#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE" "<example>\n?\n</example>")
+    ("q" "#+BEGIN_QUOTE\n?\n#+END_QUOTE" "<quote>\n?\n</quote>")
+    ("v" "#+BEGIN_VERSE\n?\n#+END_VERSE" "<verse>\n?\n</verse>")
+    ("V" "#+BEGIN_VERBATIM\n?\n#+END_VERBATIM" "<verbatim>\n?\n</verbatim>")
+    ("c" "#+BEGIN_CENTER\n?\n#+END_CENTER" "<center>\n?\n</center>")
     ("l" "#+BEGIN_LaTeX\n?\n#+END_LaTeX"
     ("l" "#+BEGIN_LaTeX\n?\n#+END_LaTeX"
      "<literal style=\"latex\">\n?\n</literal>")
      "<literal style=\"latex\">\n?\n</literal>")
-    ("L" "#+LaTeX: "
-     "<literal style=\"latex\">?</literal>")
+    ("L" "#+LaTeX: " "<literal style=\"latex\">?</literal>")
     ("h" "#+BEGIN_HTML\n?\n#+END_HTML"
     ("h" "#+BEGIN_HTML\n?\n#+END_HTML"
      "<literal style=\"html\">\n?\n</literal>")
      "<literal style=\"html\">\n?\n</literal>")
-    ("H" "#+HTML: "
-     "<literal style=\"html\">?</literal>")
-    ("a" "#+BEGIN_ASCII\n?\n#+END_ASCII")
-    ("A" "#+ASCII: ")
-    ("i" "#+INDEX: ?"
-     "#+INDEX: ?")
+    ("H" "#+HTML: " "<literal style=\"html\">?</literal>")
+    ("a" "#+BEGIN_ASCII\n?\n#+END_ASCII" "")
+    ("A" "#+ASCII: " "")
+    ("i" "#+INDEX: ?" "#+INDEX: ?")
     ("I" "#+INCLUDE: %file ?"
     ("I" "#+INCLUDE: %file ?"
      "<include file=%file markup=\"?\">"))
      "<include file=%file markup=\"?\">"))
   "Structure completion elements.
   "Structure completion elements.
@@ -11994,9 +12005,10 @@ the default when the /org-mtags.el/ module has been loaded.  See also the
 variable `org-mtags-prefer-muse-templates'."
 variable `org-mtags-prefer-muse-templates'."
   :group 'org-completion
   :group 'org-completion
   :type '(repeat
   :type '(repeat
-	  (string :tag "Key")
-	  (string :tag "Template")
-	  (string :tag "Muse Template")))
+	  (list
+	   (string :tag "Key")
+	   (string :tag "Template")
+	   (string :tag "Muse Template"))))
 
 
 (defun org-try-structure-completion ()
 (defun org-try-structure-completion ()
   "Try to complete a structure template before point.
   "Try to complete a structure template before point.
@@ -13812,7 +13824,6 @@ headlines matching this string."
 			      (abbreviate-file-name
 			      (abbreviate-file-name
 			       (or (buffer-file-name (buffer-base-buffer))
 			       (or (buffer-file-name (buffer-base-buffer))
 				   (buffer-name (buffer-base-buffer)))))))
 				   (buffer-name (buffer-base-buffer)))))))
-	 (case-fold-search nil)
 	 (org-map-continue-from nil)
 	 (org-map-continue-from nil)
          lspos tags tags-list
          lspos tags tags-list
 	 (tags-alist (list (cons 0 org-file-tags)))
 	 (tags-alist (list (cons 0 org-file-tags)))
@@ -13825,7 +13836,8 @@ headlines matching this string."
       (when (eq action 'sparse-tree)
       (when (eq action 'sparse-tree)
 	(org-overview)
 	(org-overview)
 	(org-remove-occur-highlights))
 	(org-remove-occur-highlights))
-      (while (re-search-forward re nil t)
+      (while (let (case-fold-search)
+	       (re-search-forward re nil t))
 	(setq org-map-continue-from nil)
 	(setq org-map-continue-from nil)
 	(catch :skip
 	(catch :skip
 	  (setq todo (if (match-end 1) (org-match-string-no-properties 2))
 	  (setq todo (if (match-end 1) (org-match-string-no-properties 2))
@@ -14178,9 +14190,10 @@ When DOWNCASE is non-nil, expand downcased TAGS."
 	(modify-syntax-entry ?@ "w" stable)
 	(modify-syntax-entry ?@ "w" stable)
 	(modify-syntax-entry ?_ "w" stable)
 	(modify-syntax-entry ?_ "w" stable)
 	(while (and tml
 	(while (and tml
-		    (string-match
-		     (concat "\\(?1:[+-]?\\)\\(?2:\\<"
-			     (regexp-opt tml) "\\>\\)") rtnmatch))
+		    (with-syntax-table stable
+		      (string-match
+		       (concat "\\(?1:[+-]?\\)\\(?2:\\<"
+			       (regexp-opt tml) "\\>\\)") rtnmatch)))
 	  (let* ((dir (match-string 1 rtnmatch))
 	  (let* ((dir (match-string 1 rtnmatch))
 		 (tag (match-string 2 rtnmatch))
 		 (tag (match-string 2 rtnmatch))
 		 (tag (if downcased (downcase tag) tag)))
 		 (tag (if downcased (downcase tag) tag)))
@@ -18495,14 +18508,17 @@ share a good deal of logic."
          "Invalid value of `org-latex-create-formula-image-program'")))
          "Invalid value of `org-latex-create-formula-image-program'")))
    string tofile options buffer))
    string tofile options buffer))
 
 
+(declare-function org-export-get-backend "ox" (name))
 (declare-function org-export--get-global-options "ox" (&optional backend))
 (declare-function org-export--get-global-options "ox" (&optional backend))
 (declare-function org-export--get-inbuffer-options "ox" (&optional backend))
 (declare-function org-export--get-inbuffer-options "ox" (&optional backend))
 (declare-function org-latex-guess-inputenc "ox-latex" (header))
 (declare-function org-latex-guess-inputenc "ox-latex" (header))
 (declare-function org-latex-guess-babel-language "ox-latex" (header info))
 (declare-function org-latex-guess-babel-language "ox-latex" (header info))
 (defun org-create-formula--latex-header ()
 (defun org-create-formula--latex-header ()
   "Return LaTeX header appropriate for previewing a LaTeX snippet."
   "Return LaTeX header appropriate for previewing a LaTeX snippet."
-  (let ((info (org-combine-plists (org-export--get-global-options 'latex)
-				  (org-export--get-inbuffer-options 'latex))))
+  (let ((info (org-combine-plists (org-export--get-global-options
+				   (org-export-get-backend 'latex))
+				  (org-export--get-inbuffer-options
+				   (org-export-get-backend 'latex)))))
     (org-latex-guess-babel-language
     (org-latex-guess-babel-language
      (org-latex-guess-inputenc
      (org-latex-guess-inputenc
       (org-splice-latex-header
       (org-splice-latex-header
@@ -18593,7 +18609,7 @@ share a good deal of logic."
                   (font-height (face-font 'default))
                   (font-height (face-font 'default))
                 (face-attribute 'default :height nil)))
                 (face-attribute 'default :height nil)))
 	 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
 	 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
-	 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
+	 (dpi (number-to-string (* scale (floor (if buffer fnh 120.)))))
 	 (fg (or (plist-get options (if buffer :foreground :html-foreground))
 	 (fg (or (plist-get options (if buffer :foreground :html-foreground))
 		 "black"))
 		 "black"))
 	 (bg (or (plist-get options (if buffer :background :html-background))
 	 (bg (or (plist-get options (if buffer :background :html-background))
@@ -19049,6 +19065,8 @@ BEG and END default to the buffer boundaries."
 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
 (org-defkey org-mode-map "\C-c#"    'org-update-statistics-cookies)
 (org-defkey org-mode-map "\C-c#"    'org-update-statistics-cookies)
 (org-defkey org-mode-map [remap open-line] 'org-open-line)
 (org-defkey org-mode-map [remap open-line] 'org-open-line)
+(org-defkey org-mode-map [remap forward-paragraph] 'org-forward-element)
+(org-defkey org-mode-map [remap backward-paragraph] 'org-backward-element)
 (org-defkey org-mode-map "\C-m"     'org-return)
 (org-defkey org-mode-map "\C-m"     'org-return)
 (org-defkey org-mode-map "\C-j"     'org-return-indent)
 (org-defkey org-mode-map "\C-j"     'org-return-indent)
 (org-defkey org-mode-map "\C-c?"    'org-table-field-info)
 (org-defkey org-mode-map "\C-c?"    'org-table-field-info)
@@ -22001,12 +22019,9 @@ hierarchy of headlines by UP levels before marking the subtree."
 	  (beginning-of-line 0))
 	  (beginning-of-line 0))
 	(cond
 	(cond
 	 ;; There was a list item above.
 	 ;; There was a list item above.
-	 ((save-excursion
-	    (and (ignore-errors (goto-char (org-in-item-p)))
-		 (goto-char
-		  (org-list-get-top-point (org-list-struct)))))
-	  (looking-at org-list-full-item-re)
-	  (setq column (length (match-string 0))))
+	 ((ignore-errors (goto-char (org-in-item-p)))
+	  (goto-char (org-list-get-top-point (org-list-struct)))
+	  (setq column (org-get-indentation)))
 	 ;; There was an heading above.
 	 ;; There was an heading above.
 	 ((looking-at "\\*+[ \t]+")
 	 ((looking-at "\\*+[ \t]+")
 	  (if (not org-adapt-indentation)
 	  (if (not org-adapt-indentation)
@@ -22299,20 +22314,41 @@ a footnote definition, try to fill the first paragraph within."
 			 (goto-char (org-element-property :end element))
 			 (goto-char (org-element-property :end element))
 			 (re-search-backward "^[ \t]*#\\+end_comment" nil t)
 			 (re-search-backward "^[ \t]*#\\+end_comment" nil t)
 			 (line-beginning-position))))
 			 (line-beginning-position))))
-	     (when (and (>= (point) beg) (< (point) end))
+	     (if (or (< (point) beg) (> (point) end)) t
 	       (fill-region-as-paragraph
 	       (fill-region-as-paragraph
-		(save-excursion
-		  (end-of-line)
-		  (re-search-backward "^[ \t]*$" beg 'move)
-		  (line-beginning-position))
-		(save-excursion
-		  (beginning-of-line)
-		  (re-search-forward "^[ \t]*$" end 'move)
-		  (line-beginning-position))
-		justify)))
-	   t)
+		(save-excursion (end-of-line)
+				(re-search-backward "^[ \t]*$" beg 'move)
+				(line-beginning-position))
+		(save-excursion (beginning-of-line)
+				(re-search-forward "^[ \t]*$" end 'move)
+				(line-beginning-position))
+		justify))))
 	  ;; Fill comments.
 	  ;; Fill comments.
-	  (comment (fill-comment-paragraph justify))
+	  (comment
+	   (let ((begin (org-element-property :post-affiliated element))
+		 (end (org-element-property :end element)))
+	     (when (and (>= (point) begin) (<= (point) end))
+	       (let ((begin (save-excursion
+			      (end-of-line)
+			      (if (re-search-backward "^[ \t]*#[ \t]*$" begin t)
+				  (progn (forward-line) (point))
+				begin)))
+		     (end (save-excursion
+			    (end-of-line)
+			    (if (re-search-forward "^[ \t]*#[ \t]*$" end 'move)
+				(1- (line-beginning-position))
+			      (skip-chars-backward " \r\t\n")
+			      (line-end-position)))))
+		 ;; Do not fill comments when at a blank line or at
+		 ;; affiliated keywords.
+		 (let ((fill-prefix (save-excursion
+				      (beginning-of-line)
+				      (looking-at "[ \t]*#")
+				      (concat (match-string 0) " "))))
+		   (when (> end begin)
+		     (save-excursion
+		       (fill-region-as-paragraph begin end justify))))))
+	     t))
 	  ;; Ignore every other element.
 	  ;; Ignore every other element.
 	  (otherwise t))))))
 	  (otherwise t))))))
 
 
@@ -23194,9 +23230,10 @@ Move to the next element at the same level, when possible."
 	 (let* ((elem (org-element-at-point))
 	 (let* ((elem (org-element-at-point))
 		(end (org-element-property :end elem))
 		(end (org-element-property :end elem))
 		(parent (org-element-property :parent elem)))
 		(parent (org-element-property :parent elem)))
-	   (if (and parent (= (org-element-property :contents-end parent) end))
-	       (goto-char (org-element-property :end parent))
-	     (goto-char end))))))
+	   (cond ((and parent (= (org-element-property :contents-end parent) end))
+		  (goto-char (org-element-property :end parent)))
+		 ((integer-or-marker-p end) (goto-char end))
+		 (t (message "No element at point")))))))
 
 
 (defun org-backward-element ()
 (defun org-backward-element ()
   "Move backward by one element.
   "Move backward by one element.
@@ -23222,6 +23259,7 @@ Move to the previous element at the same level, when possible."
 	   (cond
 	   (cond
 	    ;; Move to beginning of current element if point isn't
 	    ;; Move to beginning of current element if point isn't
 	    ;; there already.
 	    ;; there already.
+	    ((null beg) (message "No element at point"))
 	    ((/= (point) beg) (goto-char beg))
 	    ((/= (point) beg) (goto-char beg))
 	    (prev-elem (goto-char (org-element-property :begin prev-elem)))
 	    (prev-elem (goto-char (org-element-property :begin prev-elem)))
 	    ((org-before-first-heading-p) (goto-char (point-min)))
 	    ((org-before-first-heading-p) (goto-char (point-min)))
@@ -23573,6 +23611,8 @@ To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
     (setq current-prefix-arg nil)
     (setq current-prefix-arg nil)
     (org-agenda-maybe-redo)))
     (org-agenda-maybe-redo)))
 
 
+(defvar speedbar-file-key-map)
+(declare-function speedbar-add-supported-extension "speedbar" (extension))
 (eval-after-load "speedbar"
 (eval-after-load "speedbar"
   '(progn
   '(progn
      (speedbar-add-supported-extension ".org")
      (speedbar-add-supported-extension ".org")
@@ -23646,6 +23686,7 @@ To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
        (org-show-context 'bookmark-jump)))
        (org-show-context 'bookmark-jump)))
 
 
 ;; Make session.el ignore our circular variable
 ;; Make session.el ignore our circular variable
+(defvar session-globals-exclude)
 (eval-after-load "session"
 (eval-after-load "session"
   '(add-to-list 'session-globals-exclude 'org-mark-ring))
   '(add-to-list 'session-globals-exclude 'org-mark-ring))
 
 

+ 5 - 3
lisp/ox-ascii.el

@@ -665,11 +665,13 @@ caption keyword."
 	      element info nil 'org-ascii--has-caption-p))
 	      element info nil 'org-ascii--has-caption-p))
 	    (title-fmt (org-ascii--translate
 	    (title-fmt (org-ascii--translate
 			(case (org-element-type element)
 			(case (org-element-type element)
-			  (table "Table %d: %s")
-			  (src-block "Listing %d: %s"))
+			  (table "Table %d:")
+			  (src-block "Listing %d:"))
 			info)))
 			info)))
 	(org-ascii--fill-string
 	(org-ascii--fill-string
-	 (format title-fmt reference (org-export-data caption info))
+	 (concat (format title-fmt reference)
+		 " "
+		 (org-export-data caption info))
 	 (org-ascii--current-text-width element info) info)))))
 	 (org-ascii--current-text-width element info) info)))))
 
 
 (defun org-ascii--build-toc (info &optional n keyword)
 (defun org-ascii--build-toc (info &optional n keyword)

+ 37 - 30
lisp/ox-beamer.el

@@ -121,9 +121,9 @@
   (add-to-list 'org-latex-classes
   (add-to-list 'org-latex-classes
 	       '("beamer"
 	       '("beamer"
 		 "\\documentclass[presentation]{beamer}
 		 "\\documentclass[presentation]{beamer}
-     \[DEFAULT-PACKAGES]
-     \[PACKAGES]
-     \[EXTRA]"
+\[DEFAULT-PACKAGES]
+\[PACKAGES]
+\[EXTRA]"
 		 ("\\section{%s}" . "\\section*{%s}")
 		 ("\\section{%s}" . "\\section*{%s}")
 		 ("\\subsection{%s}" . "\\subsection*{%s}")
 		 ("\\subsection{%s}" . "\\subsection*{%s}")
 		 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
 		 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
@@ -194,12 +194,13 @@ open    The opening template for the environment, with the following escapes
         %A   the default action/overlay specification
         %A   the default action/overlay specification
         %o   the options argument of the template
         %o   the options argument of the template
         %h   the headline text
         %h   the headline text
-        %H   if there is headline text, that text in {} braces
-        %U   if there is headline text, that text in [] brackets
+        %r   the raw headline text (i.e. without any processing)
+        %H   if there is headline text, that raw text in {} braces
+        %U   if there is headline text, that raw text in [] brackets
 close   The closing string of the environment."
 close   The closing string of the environment."
   :group 'org-export-beamer
   :group 'org-export-beamer
   :version "24.4"
   :version "24.4"
-  :package-version '(Org . "8.0")
+  :package-version '(Org . "8.1")
   :type '(repeat
   :type '(repeat
 	  (list
 	  (list
 	   (string :tag "Environment")
 	   (string :tag "Environment")
@@ -543,6 +544,7 @@ used as a communication channel."
 			      (append org-beamer-environments-special
 			      (append org-beamer-environments-special
 				      org-beamer-environments-extra
 				      org-beamer-environments-extra
 				      org-beamer-environments-default))))
 				      org-beamer-environments-default))))
+	 (raw-title (org-element-property :raw-value headline))
 	 (title (org-export-data (org-element-property :title headline) info))
 	 (title (org-export-data (org-element-property :title headline) info))
 	 (options (let ((options (org-element-property :BEAMER_OPT headline)))
 	 (options (let ((options (org-element-property :BEAMER_OPT headline)))
 		    (if (not options) ""
 		    (if (not options) ""
@@ -608,8 +610,11 @@ used as a communication channel."
 		    (cons "A" "")))))
 		    (cons "A" "")))))
 	  (list (cons "o" options)
 	  (list (cons "o" options)
 		(cons "h" title)
 		(cons "h" title)
-		(cons "H" (if (equal title "") "" (format "{%s}" title)))
-		(cons "U" (if (equal title "") "" (format "[%s]" title))))))
+		(cons "r" raw-title)
+		(cons "H" (if (equal raw-title "") ""
+			    (format "{%s}" raw-title)))
+		(cons "U" (if (equal raw-title "") ""
+			    (format "[%s]" raw-title))))))
 	"\n"))
 	"\n"))
      contents
      contents
      ;; Block's closing string.
      ;; Block's closing string.
@@ -856,28 +861,30 @@ holding export options."
      (and (plist-get info :time-stamp-file)
      (and (plist-get info :time-stamp-file)
 	  (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
 	  (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
      ;; 2. Document class and packages.
      ;; 2. Document class and packages.
-     (let ((class (plist-get info :latex-class))
-	   (class-options (plist-get info :latex-class-options)))
-       (org-element-normalize-string
-	(let* ((header (nth 1 (assoc class org-latex-classes)))
-	       (document-class-string
-		(and (stringp header)
-		     (if (not class-options) header
-		       (replace-regexp-in-string
-			"^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
-			class-options header t nil 1)))))
-	  (if (not document-class-string)
-	      (user-error "Unknown LaTeX class `%s'" class)
-	    (org-latex-guess-babel-language
-	     (org-latex-guess-inputenc
-	      (org-splice-latex-header
-	       document-class-string
-	       org-latex-default-packages-alist
-	       org-latex-packages-alist nil
-	       (concat (plist-get info :latex-header)
-		       (plist-get info :latex-header-extra)
-		       (plist-get info :beamer-header-extra))))
-	     info)))))
+     (let* ((class (plist-get info :latex-class))
+	    (class-options (plist-get info :latex-class-options))
+	    (header (nth 1 (assoc class org-latex-classes)))
+	    (document-class-string
+	     (and (stringp header)
+		  (if (not class-options) header
+		    (replace-regexp-in-string
+		     "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
+		     class-options header t nil 1)))))
+       (if (not document-class-string)
+	   (user-error "Unknown LaTeX class `%s'" class)
+	 (org-latex-guess-babel-language
+	  (org-latex-guess-inputenc
+	   (org-element-normalize-string
+	    (org-splice-latex-header
+	     document-class-string
+	     org-latex-default-packages-alist
+	     org-latex-packages-alist nil
+	     (concat (org-element-normalize-string
+		      (plist-get info :latex-header))
+		     (org-element-normalize-string
+		      (plist-get info :latex-header-extra))
+		     (plist-get info :beamer-header-extra)))))
+	  info)))
      ;; 3. Insert themes.
      ;; 3. Insert themes.
      (let ((format-theme
      (let ((format-theme
 	    (function
 	    (function

+ 223 - 186
lisp/ox-html.el

@@ -117,6 +117,7 @@
     (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
     (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
     (:html-container "HTML_CONTAINER" nil org-html-container-element)
     (:html-container "HTML_CONTAINER" nil org-html-container-element)
     (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
     (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
+    (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
     (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
     (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
     (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
     (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
     (:html-mathjax "HTML_MATHJAX" nil "" space)
     (:html-mathjax "HTML_MATHJAX" nil "" space)
@@ -713,16 +714,14 @@ When nil, the links still point to the plain `.org' file."
 
 
 ;;;; Links :: Inline images
 ;;;; Links :: Inline images
 
 
-(defcustom org-html-inline-images 'maybe
+(defcustom org-html-inline-images t
   "Non-nil means inline images into exported HTML pages.
   "Non-nil means inline images into exported HTML pages.
 This is done using an <img> tag.  When nil, an anchor with href is used to
 This is done using an <img> tag.  When nil, an anchor with href is used to
-link to the image.  If this option is `maybe', then images in links with
-an empty description will be inlined, while images with a description will
-be linked only."
+link to the image."
   :group 'org-export-html
   :group 'org-export-html
-  :type '(choice (const :tag "Never" nil)
-		 (const :tag "Always" t)
-		 (const :tag "When there is no description" maybe)))
+  :version "24.4"
+  :package-version '(Org . "8.1")
+  :type 'boolean)
 
 
 (defcustom org-html-inline-image-rules
 (defcustom org-html-inline-image-rules
   '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
   '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
@@ -1186,6 +1185,13 @@ example."
   :group 'org-export-html
   :group 'org-export-html
   :type '(string :tag "File or URL"))
   :type '(string :tag "File or URL"))
 
 
+(defcustom org-html-link-use-abs-url nil
+  "Should we prepend relative links with HTML_LINK_HOME?"
+  :group 'org-export-html
+  :version "24.4"
+  :package-version '(Org . "8.1")
+  :type 'boolean)
+
 (defcustom org-html-home/up-format
 (defcustom org-html-home/up-format
   "<div id=\"org-div-home-and-up\">
   "<div id=\"org-div-home-and-up\">
  <a accesskey=\"h\" href=\"%s\"> UP </a>
  <a accesskey=\"h\" href=\"%s\"> UP </a>
@@ -1326,39 +1332,43 @@ attributes with a nil value will be omitted from the result."
                              "\"" "&quot;" (org-html-encode-plain-text item))))
                              "\"" "&quot;" (org-html-encode-plain-text item))))
                  (setcar output (format "%s=\"%s\"" key value))))))))
                  (setcar output (format "%s=\"%s\"" key value))))))))
 
 
-(defun org-html-format-inline-image (src info &optional
-					 caption label attr standalone-p)
-  "Format an inline image from SRC.
-CAPTION, LABEL and ATTR are optional arguments providing the
-caption, the label and the attribute of the image.
-When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
-  (let* ((id (if (not label) ""
-	       (format " id=\"%s\"" (org-export-solidify-link-text label))))
-	 (attr (concat attr
-		       (format " src=\"%s\"" src)
-		       (cond
-			((string-match "\\<alt=" (or attr "")) "")
-			((string-match "^ltxpng/" src)
-			 (format " alt=\"%s\""
-				 (org-html-encode-plain-text
-				  (org-find-text-property-in-string
-				   'org-latex-src src))))
-			(t (format " alt=\"%s\""
-				   (file-name-nondirectory src))))))
-	 (html5-fancy (and (org-html-html5-p info)
-			   (plist-get info :html-html5-fancy))))
-    (cond
-     (standalone-p
-      (let ((img (org-html-close-tag "img" attr info)))
-	(format (if html5-fancy
-		    "\n<figure%s>%s%s\n</figure>"
-		  "\n<div%s class=\"figure\">%s%s\n</div>")
-		id (format "\n<p>%s</p>" img)
-		(if (and caption (not (string= caption "")))
-		    (format (if html5-fancy
-				"\n<figcaption>%s</figcaption>"
-			      "\n<p>%s</p>") caption) ""))))
-     (t (org-html-close-tag "img" (concat attr id) info)))))
+(defun org-html--wrap-image (contents info &optional caption label)
+  "Wrap CONTENTS string within an appropriate environment for images.
+INFO is a plist used as a communication channel.  When optional
+arguments CAPTION and LABEL are given, use them for caption and
+\"id\" attribute."
+  (let ((html5-fancy (and (org-html-html5-p info)
+			  (plist-get info :html-html5-fancy))))
+    (format (if html5-fancy "\n<figure%s>%s%s\n</figure>"
+	      "\n<div%s class=\"figure\">%s%s\n</div>")
+	    ;; ID.
+	    (if (not (org-string-nw-p label)) ""
+	      (format " id=\"%s\"" (org-export-solidify-link-text label)))
+	    ;; Contents.
+	    (format "\n<p>%s</p>" contents)
+	    ;; Caption.
+	    (if (not (org-string-nw-p caption)) ""
+	      (format (if html5-fancy "\n<figcaption>%s</figcaption>"
+			"\n<p>%s</p>")
+		      caption)))))
+
+(defun org-html--format-image (source attributes info)
+  "Return \"img\" tag with given SOURCE and ATTRIBUTES.
+SOURCE is a string specifying the location of the image.
+ATTRIBUTES is a plist, as returned by
+`org-export-read-attribute'.  INFO is a plist used as
+a communication channel."
+  (org-html-close-tag
+   "img"
+   (org-html--make-attribute-string
+    (org-combine-plists
+     (list :src source
+	   :alt (if (string-match-p "^ltxpng/" source)
+		    (org-html-encode-plain-text
+		     (org-find-text-property-in-string 'org-latex-src source))
+		  (file-name-nondirectory source)))
+     attributes))
+   info))
 
 
 (defun org-html--textarea-block (element)
 (defun org-html--textarea-block (element)
   "Transcode ELEMENT into a textarea block.
   "Transcode ELEMENT into a textarea block.
@@ -1370,6 +1380,13 @@ ELEMENT is either a src block or an example block."
 	    (or (plist-get attr :height) (org-count-lines code))
 	    (or (plist-get attr :height) (org-count-lines code))
 	    code)))
 	    code)))
 
 
+(defun org-html--has-caption-p (element &optional info)
+  "Non-nil when ELEMENT has a caption affiliated keyword.
+INFO is a plist used as a communication channel.  This function
+is meant to be used as a predicate for `org-export-get-ordinal' or
+a value to `org-html-standalone-image-predicate'."
+  (org-element-property :caption element))
+
 ;;;; Table
 ;;;; Table
 
 
 (defun org-html-htmlize-region-for-paste (beg end)
 (defun org-html-htmlize-region-for-paste (beg end)
@@ -1911,9 +1928,13 @@ contents as a string, or nil if it is empty."
 	 (mapcar (lambda (headline)
 	 (mapcar (lambda (headline)
 		   (cons (org-html--format-toc-headline headline info)
 		   (cons (org-html--format-toc-headline headline info)
 			 (org-export-get-relative-level headline info)))
 			 (org-export-get-relative-level headline info)))
-		 (org-export-collect-headlines info depth))))
+		 (org-export-collect-headlines info depth)))
+	(outer-tag (if (and (org-html-html5-p info)
+			    (plist-get info :html-html5-fancy))
+		       "nav"
+		     "div")))
     (when toc-entries
     (when toc-entries
-      (concat "<div id=\"table-of-contents\">\n"
+      (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
 	      (format "<h%d>%s</h%d>\n"
 	      (format "<h%d>%s</h%d>\n"
 		      org-html-toplevel-hlevel
 		      org-html-toplevel-hlevel
 		      (org-html--translate "Table of Contents" info)
 		      (org-html--translate "Table of Contents" info)
@@ -1921,7 +1942,7 @@ contents as a string, or nil if it is empty."
 	      "<div id=\"text-table-of-contents\">"
 	      "<div id=\"text-table-of-contents\">"
 	      (org-html--toc-text toc-entries)
 	      (org-html--toc-text toc-entries)
 	      "</div>\n"
 	      "</div>\n"
-	      "</div>\n"))))
+	      (format "</%s>\n" outer-tag)))))
 
 
 (defun org-html--toc-text (toc-entries)
 (defun org-html--toc-text (toc-entries)
   "Return innards of a table of contents, as a string.
   "Return innards of a table of contents, as a string.
@@ -1966,16 +1987,17 @@ INFO is a plist used as a communication channel."
 					   headline-number "-"))))
 					   headline-number "-"))))
 	    ;; Body.
 	    ;; Body.
 	    (concat section-number
 	    (concat section-number
-		    (org-export-data-with-translations
+		    (org-export-data-with-backend
 		     (org-export-get-alt-title headline info)
 		     (org-export-get-alt-title headline info)
-		     ;; Ignore any footnote-reference, link,
-		     ;; radio-target and target in table of contents.
-		     (append
-		      '((footnote-reference . ignore)
-			(link . (lambda (link desc i) desc))
-			(radio-target . (lambda (radio desc i) desc))
-			(target . ignore))
-		      (org-export-backend-translate-table 'html))
+		     ;; Create an anonymous back-end that will ignore
+		     ;; any footnote-reference, link, radio-target and
+		     ;; target in table of contents.
+		     (org-export-create-backend
+		      :parent 'html
+		      :transcoders '((footnote-reference . ignore)
+				     (link . (lambda (object c i) c))
+				     (radio-target . (lambda (object c i) c))
+				     (target . ignore)))
 		     info)
 		     info)
 		    (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
 		    (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
 
 
@@ -1992,7 +2014,8 @@ of listings as a string, or nil if it is empty."
 		      org-html-toplevel-hlevel)
 		      org-html-toplevel-hlevel)
 	      "<div id=\"text-list-of-listings\">\n<ul>\n"
 	      "<div id=\"text-list-of-listings\">\n<ul>\n"
 	      (let ((count 0)
 	      (let ((count 0)
-		    (initial-fmt (org-html--translate "Listing %d:" info)))
+		    (initial-fmt (format "<span class=\"listing-number\">%s</span>"
+					 (org-html--translate "Listing %d:" info))))
 		(mapconcat
 		(mapconcat
 		 (lambda (entry)
 		 (lambda (entry)
 		   (let ((label (org-element-property :name entry))
 		   (let ((label (org-element-property :name entry))
@@ -2026,7 +2049,8 @@ of tables as a string, or nil if it is empty."
 		      org-html-toplevel-hlevel)
 		      org-html-toplevel-hlevel)
 	      "<div id=\"text-list-of-tables\">\n<ul>\n"
 	      "<div id=\"text-list-of-tables\">\n<ul>\n"
 	      (let ((count 0)
 	      (let ((count 0)
-		    (initial-fmt (org-html--translate "Table %d:" info)))
+		    (initial-fmt (format "<span class=\"table-number\">%s</span>"
+					 (org-html--translate "Table %d:" info))))
 		(mapconcat
 		(mapconcat
 		 (lambda (entry)
 		 (lambda (entry)
 		   (let ((label (org-element-property :name entry))
 		   (let ((label (org-element-property :name entry))
@@ -2213,15 +2237,13 @@ holding contextual information."
 	 (headline-label (or (org-element-property :CUSTOM_ID headline)
 	 (headline-label (or (org-element-property :CUSTOM_ID headline)
 			     (concat "sec-" (mapconcat 'number-to-string
 			     (concat "sec-" (mapconcat 'number-to-string
 						       headline-number "-"))))
 						       headline-number "-"))))
-	 (format-function (cond
-			   ((functionp format-function) format-function)
-			   ((functionp org-html-format-headline-function)
-			    (function*
-			     (lambda (todo todo-type priority text tags
-					   &allow-other-keys)
-			       (funcall org-html-format-headline-function
-					todo todo-type priority text tags))))
-			   (t 'org-html-format-headline))))
+	 (format-function
+	  (cond ((functionp format-function) format-function)
+		((functionp org-html-format-headline-function)
+		 (lambda (todo todo-type priority text tags &rest ignore)
+		   (funcall org-html-format-headline-function
+			    todo todo-type priority text tags)))
+		(t 'org-html-format-headline))))
     (apply format-function
     (apply format-function
 	   todo todo-type  priority text tags
 	   todo todo-type  priority text tags
 	   :headline-label headline-label :level level
 	   :headline-label headline-label :level level
@@ -2471,21 +2493,19 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
   (let ((processing-type (plist-get info :with-latex))
   (let ((processing-type (plist-get info :with-latex))
 	(latex-frag (org-remove-indentation
 	(latex-frag (org-remove-indentation
 		     (org-element-property :value latex-environment)))
 		     (org-element-property :value latex-environment)))
-	(caption (org-export-data
-		  (org-export-get-caption latex-environment) info))
-	(attr nil)			; FIXME
-	(label (org-element-property :name latex-environment)))
-    (cond
-     ((memq processing-type '(t mathjax))
-      (org-html-format-latex latex-frag 'mathjax))
-     ((eq processing-type 'dvipng)
-      (let* ((formula-link (org-html-format-latex
-			    latex-frag processing-type)))
-	(when (and formula-link
-		   (string-match "file:\\([^]]*\\)" formula-link))
-	  (org-html-format-inline-image
-	   (match-string 1 formula-link) info caption label attr t))))
-     (t latex-frag))))
+	(attributes (org-export-read-attribute :attr_html latex-environment)))
+    (case processing-type
+      ((t mathjax)
+       (org-html-format-latex latex-frag 'mathjax))
+      ((dvipng imagemagick)
+       (let ((formula-link (org-html-format-latex latex-frag processing-type)))
+	 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
+	   ;; Do not provide a caption or a name to be consistent with
+	   ;; `mathjax' handling.
+	   (org-html--wrap-image
+	    (org-html--format-image
+	     (match-string 1 formula-link) attributes info) info))))
+      (t latex-frag))))
 
 
 ;;;; Latex Fragment
 ;;;; Latex Fragment
 
 
@@ -2497,13 +2517,10 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
     (case processing-type
     (case processing-type
       ((t mathjax)
       ((t mathjax)
        (org-html-format-latex latex-frag 'mathjax))
        (org-html-format-latex latex-frag 'mathjax))
-      (dvipng
-       (let* ((formula-link (org-html-format-latex
-			     latex-frag processing-type)))
-	 (when (and formula-link
-		    (string-match "file:\\([^]]*\\)" formula-link))
-	   (org-html-format-inline-image
-	    (match-string 1 formula-link) info))))
+      ((dvipng imagemagick)
+       (let ((formula-link (org-html-format-latex latex-frag processing-type)))
+	 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
+	   (org-html--format-image (match-string 1 formula-link) nil info))))
       (t latex-frag))))
       (t latex-frag))))
 
 
 ;;;; Line Break
 ;;;; Line Break
@@ -2515,75 +2532,65 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 
 
 ;;;; Link
 ;;;; Link
 
 
-(defun org-html-link--inline-image (link desc info)
-  "Return HTML code for an inline image.
-
-LINK is the link pointing to the inline image.  INFO is a plist
-used as a communication channel.
-
-Inline images can have these attributes:
-
-#+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
-  (let* ((type (org-element-property :type link))
-	 (raw-path (org-element-property :path link))
-	 (path (cond ((member type '("http" "https"))
-		      (concat type ":" raw-path))
-		     ((file-name-absolute-p raw-path)
-		      (expand-file-name raw-path))
-		     (t raw-path)))
-	 (parent (org-export-get-parent-element link))
-	 (caption (org-export-data (org-export-get-caption parent) info))
-	 (label (org-element-property :name parent)))
-    ;; Return proper string, depending on DISPOSITION.
-    (org-html-format-inline-image
-     path info caption label
-     (org-html--make-attribute-string
-      (org-export-read-attribute :attr_html parent))
-     (org-html-standalone-image-p link info))))
+(defun org-html-inline-image-p (link info)
+  "Non-nil when LINK is meant to appear as an image.
+INFO is a plist used as a communication channel.  LINK is an
+inline image when it has no description and targets an image
+file (see `org-html-inline-image-rules' for more information), or
+if its description is a single link targeting an image file."
+  (if (not (org-element-contents link))
+      (org-export-inline-image-p link org-html-inline-image-rules)
+    (not
+     (let ((link-count 0))
+       (org-element-map (org-element-contents link)
+	   (cons 'plain-text org-element-all-objects)
+	 (lambda (obj)
+	   (case (org-element-type obj)
+	     (plain-text (org-string-nw-p obj))
+	     (link (if (= link-count 1) t
+		     (incf link-count)
+		     (not (org-export-inline-image-p
+			   obj org-html-inline-image-rules))))
+	     (otherwise t)))
+         info t)))))
 
 
 (defvar org-html-standalone-image-predicate)
 (defvar org-html-standalone-image-predicate)
-(defun org-html-standalone-image-p (element info &optional predicate)
-  "Test if ELEMENT is a standalone image for the purpose HTML export.
+(defun org-html-standalone-image-p (element info)
+  "Test if ELEMENT is a standalone image.
+
 INFO is a plist holding contextual information.
 INFO is a plist holding contextual information.
 
 
-Return non-nil, if ELEMENT is of type paragraph and it's sole
-content, save for whitespaces, is a link that qualifies as an
+Return non-nil, if ELEMENT is of type paragraph and its sole
+content, save for white spaces, is a link that qualifies as an
 inline image.
 inline image.
 
 
-Return non-nil, if ELEMENT is of type link and it's containing
-paragraph has no other content save for leading and trailing
-whitespaces.
+Return non-nil, if ELEMENT is of type link and its containing
+paragraph has no other content save white spaces.
 
 
 Return nil, otherwise.
 Return nil, otherwise.
 
 
-Bind `org-html-standalone-image-predicate' to constrain
-paragraph further.  For example, to check for only captioned
-standalone images, do the following.
+Bind `org-html-standalone-image-predicate' to constrain paragraph
+further.  For example, to check for only captioned standalone
+images, set it to:
 
 
-  \(setq org-html-standalone-image-predicate
-	\(lambda \(paragraph\)
-	  \(org-element-property :caption paragraph\)\)\)"
+  \(lambda (paragraph) (org-element-property :caption paragraph))"
   (let ((paragraph (case (org-element-type element)
   (let ((paragraph (case (org-element-type element)
 		     (paragraph element)
 		     (paragraph element)
-		     (link (and (org-export-inline-image-p
-				 element org-html-inline-image-rules)
-				(org-export-get-parent element)))
-		     (t nil))))
-    (when (eq (org-element-type paragraph) 'paragraph)
-      (when (or (not (and (boundp 'org-html-standalone-image-predicate)
-			  (functionp org-html-standalone-image-predicate)))
-		(funcall org-html-standalone-image-predicate paragraph))
-	(let ((contents (org-element-contents paragraph)))
-	  (loop for x in contents
-		with inline-image-count = 0
-		always (cond
-			((eq (org-element-type x) 'plain-text)
-			 (not (org-string-nw-p x)))
-			((eq (org-element-type x) 'link)
-			 (when (org-export-inline-image-p
-				x org-html-inline-image-rules)
-			   (= (incf inline-image-count) 1)))
-			(t nil))))))))
+		     (link (org-export-get-parent element)))))
+    (and (eq (org-element-type paragraph) 'paragraph)
+	 (or (not (and (boundp 'org-html-standalone-image-predicate)
+		       (functionp org-html-standalone-image-predicate)))
+	     (funcall org-html-standalone-image-predicate paragraph))
+	 (not (let ((link-count 0))
+		(org-element-map (org-element-contents paragraph)
+		    (cons 'plain-text org-element-all-objects)
+		  (lambda (obj) (case (org-element-type obj)
+			     (plain-text (org-string-nw-p obj))
+			     (link
+			      (or (> (incf link-count) 1)
+				  (not (org-html-inline-image-p obj info))))
+			     (otherwise t)))
+		  info 'first-match 'link))))))
 
 
 (defun org-html-link (link desc info)
 (defun org-html-link (link desc info)
   "Transcode a LINK object from Org to HTML.
   "Transcode a LINK object from Org to HTML.
@@ -2591,7 +2598,9 @@ standalone images, do the following.
 DESC is the description part of the link, or the empty string.
 DESC is the description part of the link, or the empty string.
 INFO is a plist holding contextual information.  See
 INFO is a plist holding contextual information.  See
 `org-export-data'."
 `org-export-data'."
-  (let* ((link-org-files-as-html-maybe
+  (let* ((home (org-trim (plist-get info :html-link-home)))
+	 (use-abs-url (plist-get info :html-link-use-abs-url))
+	 (link-org-files-as-html-maybe
 	  (function
 	  (function
 	   (lambda (raw-path info)
 	   (lambda (raw-path info)
 	     "Treat links to `file.org' as links to `file.html', if needed.
 	     "Treat links to `file.org' as links to `file.html', if needed.
@@ -2617,9 +2626,12 @@ INFO is a plist holding contextual information.  See
 		  (funcall link-org-files-as-html-maybe raw-path info))
 		  (funcall link-org-files-as-html-maybe raw-path info))
 	    ;; If file path is absolute, prepend it with protocol
 	    ;; If file path is absolute, prepend it with protocol
 	    ;; component - "file://".
 	    ;; component - "file://".
-	    (when (file-name-absolute-p raw-path)
-	      (setq raw-path
-		    (concat "file://" (expand-file-name raw-path))))
+	    (cond ((file-name-absolute-p raw-path)
+		   (setq raw-path
+			 (concat "file://" (expand-file-name
+					    raw-path))))
+		  ((and home use-abs-url)
+		   (setq raw-path (concat (file-name-as-directory home) raw-path))))
 	    ;; Add search option, if any.  A search option can be
 	    ;; Add search option, if any.  A search option can be
 	    ;; relative to a custom-id or a headline title.  Any other
 	    ;; relative to a custom-id or a headline title.  Any other
 	    ;; option is ignored.
 	    ;; option is ignored.
@@ -2639,25 +2651,28 @@ INFO is a plist holding contextual information.  See
 							numbers "-"))))))
 							numbers "-"))))))
 		    (t raw-path))))
 		    (t raw-path))))
 	   (t raw-path)))
 	   (t raw-path)))
-	 ;; Extract attributes from parent's paragraph. HACK: Only do
-	 ;; this for the first link in parent.  This is needed as long
-	 ;; as attributes cannot be set on a per link basis.
+	 ;; Extract attributes from parent's paragraph.  HACK: Only do
+	 ;; this for the first link in parent (inner image link for
+	 ;; inline images).  This is needed as long as attributes
+	 ;; cannot be set on a per link basis.
+	 (attributes-plist
+	  (let* ((parent (org-export-get-parent-element link))
+		 (link (let ((container (org-export-get-parent link)))
+			 (if (and (eq (org-element-type container) 'link)
+				  (org-html-inline-image-p link info))
+			     container
+			   link))))
+	    (and (eq (org-element-map parent 'link 'identity info t) link)
+		 (org-export-read-attribute :attr_html parent))))
 	 (attributes
 	 (attributes
-	  (let ((parent (org-export-get-parent-element link)))
-	    (if (not (eq (org-element-map parent 'link 'identity info t) link))
-		""
-	      (let ((att (org-html--make-attribute-string
-			  (org-export-read-attribute :attr_html parent))))
-		(cond ((not (org-string-nw-p att)) "")
-		      ((and desc (string-match (regexp-quote att) desc)) "")
-		      (t (concat " " att)))))))
+	  (let ((attr (org-html--make-attribute-string attributes-plist)))
+	    (if (org-string-nw-p attr) (concat " " attr) "")))
 	 protocol)
 	 protocol)
     (cond
     (cond
      ;; Image file.
      ;; Image file.
-     ((and (or (eq t org-html-inline-images)
-	       (and org-html-inline-images (not desc)))
+     ((and org-html-inline-images
 	   (org-export-inline-image-p link org-html-inline-image-rules))
 	   (org-export-inline-image-p link org-html-inline-image-rules))
-      (org-html-link--inline-image link desc info))
+      (org-html--format-image path attributes-plist info))
      ;; Radio target: Transcode target's contents and use them as
      ;; Radio target: Transcode target's contents and use them as
      ;; link's description.
      ;; link's description.
      ((string= type "radio")
      ((string= type "radio")
@@ -2688,8 +2703,6 @@ INFO is a plist holding contextual information.  See
 		   (or desc
 		   (or desc
 		       (org-export-data
 		       (org-export-data
 			(org-element-property :raw-link link) info))))
 			(org-element-property :raw-link link) info))))
-	  ;; Fuzzy link points to an invisible target.
-	  (keyword nil)
 	  ;; Link points to a headline.
 	  ;; Link points to a headline.
 	  (headline
 	  (headline
 	   (let ((href
 	   (let ((href
@@ -2723,21 +2736,24 @@ INFO is a plist holding contextual information.  See
 					       :title destination) info)))))
 					       :title destination) info)))))
 	     (format "<a href=\"#%s\"%s>%s</a>"
 	     (format "<a href=\"#%s\"%s>%s</a>"
 		     (org-export-solidify-link-text href) attributes desc)))
 		     (org-export-solidify-link-text href) attributes desc)))
-	  ;; Fuzzy link points to a target.  Do as above.
+	  ;; Fuzzy link points to a target or an element.
 	  (t
 	  (t
-	   (let ((path (org-export-solidify-link-text path)) number)
-	     (unless desc
-	       (setq number (cond
-			     ((org-html-standalone-image-p destination info)
-			      (org-export-get-ordinal
-			       (assoc 'link (org-element-contents destination))
-			       info 'link 'org-html-standalone-image-p))
-			     (t (org-export-get-ordinal destination info))))
-	       (setq desc (when number
-			    (if (atom number) (number-to-string number)
-			      (mapconcat 'number-to-string number ".")))))
-	     (format "<a href=\"#%s\"%s>%s</a>"
-		     path attributes (or desc "No description for this link")))))))
+	   (let* ((path (org-export-solidify-link-text path))
+		  (org-html-standalone-image-predicate 'org-html--has-caption-p)
+		  (number (cond
+			   (desc nil)
+			   ((org-html-standalone-image-p destination info)
+			    (org-export-get-ordinal
+			     (org-element-map destination 'link
+			       'identity info t)
+			     info 'link 'org-html-standalone-image-p))
+			   (t (org-export-get-ordinal
+			       destination info nil 'org-html--has-caption-p))))
+		  (desc (cond (desc)
+			      ((not number) "No description for this link")
+			      ((numberp number) (number-to-string number))
+			      (t (mapconcat 'number-to-string number ".")))))
+	     (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
      ;; Coderef: replace link with the reference name or the
      ;; Coderef: replace link with the reference name or the
      ;; equivalent line number.
      ;; equivalent line number.
      ((string= type "coderef")
      ((string= type "coderef")
@@ -2776,11 +2792,27 @@ the plist used as a communication channel."
      ((and (eq (org-element-type parent) 'item)
      ((and (eq (org-element-type parent) 'item)
 	   (= (org-element-property :begin paragraph)
 	   (= (org-element-property :begin paragraph)
 	      (org-element-property :contents-begin parent)))
 	      (org-element-property :contents-begin parent)))
-      ;; leading paragraph in a list item have no tags
+      ;; Leading paragraph in a list item have no tags.
       contents)
       contents)
      ((org-html-standalone-image-p paragraph info)
      ((org-html-standalone-image-p paragraph info)
-      ;; standalone image
-      contents)
+      ;; Standalone image.
+      (let ((caption
+	     (let ((raw (org-export-data
+			 (org-export-get-caption paragraph) info))
+		   (org-html-standalone-image-predicate
+		    'org-html--has-caption-p))
+	       (if (not (org-string-nw-p raw)) raw
+		 (concat
+                  "<span class=\"figure-number\">"
+		  (format (org-html--translate "Figure %d:" info)
+			  (org-export-get-ordinal
+			   (org-element-map paragraph 'link
+			     'identity info t)
+			   info nil 'org-html-standalone-image-p))
+		  "</span> " raw))))
+	    (label (org-element-property :name paragraph)))
+	(org-html--wrap-image contents info caption label)))
+     ;; Regular paragraph.
      (t (format "<p%s>\n%s</p>" extra contents)))))
      (t (format "<p%s>\n%s</p>" extra contents)))))
 
 
 ;;;; Plain List
 ;;;; Plain List
@@ -3145,13 +3177,15 @@ contextual information."
     (t
     (t
      (let* ((label (org-element-property :name table))
      (let* ((label (org-element-property :name table))
 	    (caption (org-export-get-caption table))
 	    (caption (org-export-get-caption table))
+	    (number (org-export-get-ordinal
+		     table info nil 'org-html--has-caption-p))
 	    (attributes
 	    (attributes
-	     (if (org-html-html5-p info) ""
-	       (org-html--make-attribute-string
-		(org-combine-plists
-		 (and label (list :id (org-export-solidify-link-text label)))
-		 (plist-get info :html-table-attributes)
-		 (org-export-read-attribute :attr_html table)))))
+	     (org-html--make-attribute-string
+	      (org-combine-plists
+	       (and label (list :id (org-export-solidify-link-text label)))
+	       (and (not (org-html-html5-p info))
+		    (plist-get info :html-table-attributes))
+	       (org-export-read-attribute :attr_html table))))
 	    (alignspec
 	    (alignspec
 	     (if (and (boundp 'org-html-format-table-no-css)
 	     (if (and (boundp 'org-html-format-table-no-css)
 		      org-html-format-table-no-css)
 		      org-html-format-table-no-css)
@@ -3183,7 +3217,10 @@ contextual information."
 		 (format (if org-html-table-caption-above
 		 (format (if org-html-table-caption-above
 			     "<caption align=\"above\">%s</caption>"
 			     "<caption align=\"above\">%s</caption>"
 			   "<caption align=\"bottom\">%s</caption>")
 			   "<caption align=\"bottom\">%s</caption>")
-			 (org-export-data caption info)))
+			 (concat
+			  "<span class=\"table-number\">"
+                          (format (org-html--translate "Table %d:" info) number)
+			  "</span> " (org-export-data caption info))))
 	       (funcall table-column-specs table info)
 	       (funcall table-column-specs table info)
 	       contents)))))
 	       contents)))))
 
 

+ 46 - 30
lisp/ox-latex.el

@@ -143,7 +143,9 @@
     ("la" . "latin")
     ("la" . "latin")
     ("ms" . "malay")
     ("ms" . "malay")
     ("nl" . "dutch")
     ("nl" . "dutch")
-    ("no-no" . "nynorsk")
+    ("nb" . "norsk")
+    ("nn" . "nynorsk")
+    ("no" . "norsk")
     ("pl" . "polish")
     ("pl" . "polish")
     ("pt" . "portuguese")
     ("pt" . "portuguese")
     ("ro" . "romanian")
     ("ro" . "romanian")
@@ -342,7 +344,6 @@ the toc:nil option, not to those generated with #+TOC keyword."
   :group 'org-export-latex
   :group 'org-export-latex
   :type 'boolean)
   :type 'boolean)
 
 
-
 ;;;; Headline
 ;;;; Headline
 
 
 (defcustom org-latex-format-headline-function
 (defcustom org-latex-format-headline-function
@@ -618,6 +619,7 @@ in order to mimic default behaviour:
 
 
 (defcustom org-latex-listings nil
 (defcustom org-latex-listings nil
   "Non-nil means export source code using the listings package.
   "Non-nil means export source code using the listings package.
+
 This package will fontify source code, possibly even with color.
 This package will fontify source code, possibly even with color.
 If you want to use this, you also need to make LaTeX use the
 If you want to use this, you also need to make LaTeX use the
 listings package, and if you want to have color, the color
 listings package, and if you want to have color, the color
@@ -625,8 +627,8 @@ package.  Just add these to `org-latex-packages-alist', for
 example using customize, or with something like:
 example using customize, or with something like:
 
 
   \(require 'ox-latex)
   \(require 'ox-latex)
-  \(add-to-list 'org-latex-packages-alist '\(\"\" \"listings\"))
-  \(add-to-list 'org-latex-packages-alist '\(\"\" \"color\"))
+  \(add-to-list 'org-latex-packages-alist '(\"\" \"listings\"))
+  \(add-to-list 'org-latex-packages-alist '(\"\" \"color\"))
 
 
 Alternatively,
 Alternatively,
 
 
@@ -638,12 +640,18 @@ the minted package to `org-latex-packages-alist', for example
 using customize, or with
 using customize, or with
 
 
   \(require 'ox-latex)
   \(require 'ox-latex)
-  \(add-to-list 'org-latex-packages-alist '\(\"\" \"minted\"))
+  \(add-to-list 'org-latex-packages-alist '(\"\" \"minted\"))
 
 
 In addition, it is necessary to install pygments
 In addition, it is necessary to install pygments
 \(http://pygments.org), and to configure the variable
 \(http://pygments.org), and to configure the variable
 `org-latex-pdf-process' so that the -shell-escape option is
 `org-latex-pdf-process' so that the -shell-escape option is
-passed to pdflatex."
+passed to pdflatex.
+
+The minted choice has possible repercussions on the preview of
+latex fragments (see `org-preview-latex-fragment').  If you run
+into previewing problems, please consult
+
+  http://orgmode.org/worg/org-tutorials/org-latex-preview.html"
   :group 'org-export-latex
   :group 'org-export-latex
   :type '(choice
   :type '(choice
 	  (const :tag "Use listings" t)
 	  (const :tag "Use listings" t)
@@ -881,8 +889,11 @@ For non-floats, see `org-latex--wrap-label'."
 		      (format "\\label{%s}"
 		      (format "\\label{%s}"
 			      (org-export-solidify-link-text label))))
 			      (org-export-solidify-link-text label))))
 	 (main (org-export-get-caption element))
 	 (main (org-export-get-caption element))
-	 (short (org-export-get-caption element t)))
+	 (short (org-export-get-caption element t))
+	 (caption-from-attr-latex (org-export-read-attribute :attr_latex element :caption)))
     (cond
     (cond
+     ((org-string-nw-p caption-from-attr-latex)
+      (concat caption-from-attr-latex "\n"))
      ((and (not main) (equal label-str "")) "")
      ((and (not main) (equal label-str "")) "")
      ((not main) (concat label-str "\n"))
      ((not main) (concat label-str "\n"))
      ;; Option caption format with short name.
      ;; Option caption format with short name.
@@ -1066,27 +1077,28 @@ holding export options."
      (and (plist-get info :time-stamp-file)
      (and (plist-get info :time-stamp-file)
 	  (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
 	  (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
      ;; Document class and packages.
      ;; Document class and packages.
-     (let ((class (plist-get info :latex-class))
-	   (class-options (plist-get info :latex-class-options)))
-       (org-element-normalize-string
-	(let* ((header (nth 1 (assoc class org-latex-classes)))
-	       (document-class-string
-		(and (stringp header)
-		     (if (not class-options) header
-		       (replace-regexp-in-string
-			"^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
-			class-options header t nil 1)))))
-	  (if (not document-class-string)
-	      (user-error "Unknown LaTeX class `%s'" class)
-	    (org-latex-guess-babel-language
-	     (org-latex-guess-inputenc
-	      (org-splice-latex-header
-	       document-class-string
-	       org-latex-default-packages-alist
-	       org-latex-packages-alist nil
-	       (concat (plist-get info :latex-header)
-		       (plist-get info :latex-header-extra))))
-	     info)))))
+     (let* ((class (plist-get info :latex-class))
+	    (class-options (plist-get info :latex-class-options))
+	    (header (nth 1 (assoc class org-latex-classes)))
+	    (document-class-string
+	     (and (stringp header)
+		  (if (not class-options) header
+		    (replace-regexp-in-string
+		     "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
+		     class-options header t nil 1)))))
+       (if (not document-class-string)
+	   (user-error "Unknown LaTeX class `%s'" class)
+	 (org-latex-guess-babel-language
+	  (org-latex-guess-inputenc
+	   (org-element-normalize-string
+	    (org-splice-latex-header
+	     document-class-string
+	     org-latex-default-packages-alist
+	     org-latex-packages-alist nil
+	     (concat (org-element-normalize-string
+		      (plist-get info :latex-header))
+		     (plist-get info :latex-header-extra)))))
+	  info)))
      ;; Possibly limit depth for headline numbering.
      ;; Possibly limit depth for headline numbering.
      (let ((sec-num (plist-get info :section-numbers)))
      (let ((sec-num (plist-get info :section-numbers)))
        (when (integerp sec-num)
        (when (integerp sec-num)
@@ -1655,7 +1667,9 @@ used as a communication channel."
 		  (cond ((and (not float) (plist-member attr :float)) nil)
 		  (cond ((and (not float) (plist-member attr :float)) nil)
 			((string= float "wrap") 'wrap)
 			((string= float "wrap") 'wrap)
 			((string= float "multicolumn") 'multicolumn)
 			((string= float "multicolumn") 'multicolumn)
-			((or float (org-element-property :caption parent))
+			((or float
+			     (org-element-property :caption parent)
+			     (org-string-nw-p (plist-get attr :caption)))
 			 'figure))))
 			 'figure))))
 	 (placement
 	 (placement
 	  (let ((place (plist-get attr :placement)))
 	  (let ((place (plist-get attr :placement)))
@@ -2333,7 +2347,9 @@ This function assumes TABLE has `org' as its `:type' property and
 			 ((and (not float) (plist-member attr :float)) nil)
 			 ((and (not float) (plist-member attr :float)) nil)
 			 ((string= float "sidewaystable") "sidewaystable")
 			 ((string= float "sidewaystable") "sidewaystable")
 			 ((string= float "multicolumn") "table*")
 			 ((string= float "multicolumn") "table*")
-			 ((or float (org-element-property :caption table))
+			 ((or float
+			      (org-element-property :caption table)
+			      (org-string-nw-p (plist-get attr :caption)))
 			  "table")))))
 			  "table")))))
 	 ;; Extract others display options.
 	 ;; Extract others display options.
 	 (fontsize (let ((font (plist-get attr :font)))
 	 (fontsize (let ((font (plist-get attr :font)))

+ 140 - 150
lisp/ox-odt.el

@@ -288,38 +288,37 @@ according to the default face identified by the `htmlfontify'.")
     ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
     ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
     ("value" "%e %n: %c" "value" "%n"))
     ("value" "%e %n: %c" "value" "%n"))
   "Specify how labels are applied and referenced.
   "Specify how labels are applied and referenced.
-This is an alist where each element is of the
-form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
-LABEL-REF-FMT).
 
 
-LABEL-ATTACH-FMT controls how labels and captions are attached to
-an entity.  It may contain following specifiers - %e, %n and %c.
-%e is replaced with the CATEGORY-NAME.  %n is replaced with
+This is an alist where each element is of the form:
+
+  \(STYLE-NAME ATTACH-FMT REF-MODE REF-FMT)
+
+ATTACH-FMT controls how labels and captions are attached to an
+entity.  It may contain following specifiers - %e and %c.  %e is
+replaced with the CATEGORY-NAME.  %n is replaced with
 \"<text:sequence ...> SEQNO </text:sequence>\".  %c is replaced
 \"<text:sequence ...> SEQNO </text:sequence>\".  %c is replaced
-with CAPTION. See `org-odt-format-label-definition'.
+with CAPTION.
 
 
-LABEL-REF-MODE and LABEL-REF-FMT controls how label references
-are generated.  The following XML is generated for a label
-reference - \"<text:sequence-ref
-text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
-</text:sequence-ref>\".  LABEL-REF-FMT may contain following
+REF-MODE and REF-FMT controls how label references are generated.
+The following XML is generated for a label reference -
+\"<text:sequence-ref text:reference-format=\"REF-MODE\" ...>
+REF-FMT </text:sequence-ref>\".  REF-FMT may contain following
 specifiers - %e and %n.  %e is replaced with the CATEGORY-NAME.
 specifiers - %e and %n.  %e is replaced with the CATEGORY-NAME.
-%n is replaced with SEQNO. See
-`org-odt-format-label-reference'.")
+%n is replaced with SEQNO.
+
+See also `org-odt-format-label'.")
 
 
 (defvar org-odt-category-map-alist
 (defvar org-odt-category-map-alist
   '(("__Table__" "Table" "value" "Table" org-odt--enumerable-p)
   '(("__Table__" "Table" "value" "Table" org-odt--enumerable-p)
     ("__Figure__" "Illustration" "value" "Figure" org-odt--enumerable-image-p)
     ("__Figure__" "Illustration" "value" "Figure" org-odt--enumerable-image-p)
     ("__MathFormula__" "Text" "math-formula" "Equation" org-odt--enumerable-formula-p)
     ("__MathFormula__" "Text" "math-formula" "Equation" org-odt--enumerable-formula-p)
     ("__DvipngImage__" "Equation" "value" "Equation" org-odt--enumerable-latex-image-p)
     ("__DvipngImage__" "Equation" "value" "Equation" org-odt--enumerable-latex-image-p)
-    ("__Listing__" "Listing" "value" "Listing" org-odt--enumerable-p)
-    ;; ("__Table__" "Table" "category-and-value")
-    ;; ("__Figure__" "Figure" "category-and-value")
-    ;; ("__DvipngImage__" "Equation" "category-and-value")
-    )
+    ("__Listing__" "Listing" "value" "Listing" org-odt--enumerable-p))
   "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
   "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
-This is a list where each entry is of the form \\(CATEGORY-HANDLE
-OD-VARIABLE LABEL-STYLE CATEGORY-NAME ENUMERATOR-PREDICATE\\).
+
+This is a list where each entry is of the form:
+
+  \(CATEGORY-HANDLE OD-VARIABLE LABEL-STYLE CATEGORY-NAME ENUMERATOR-PREDICATE)
 
 
 CATEGORY_HANDLE identifies the captionable entity in question.
 CATEGORY_HANDLE identifies the captionable entity in question.
 
 
@@ -331,15 +330,7 @@ the entity.  These counters are declared within
 LABEL-STYLE is a key into `org-odt-label-styles' and specifies
 LABEL-STYLE is a key into `org-odt-label-styles' and specifies
 how a given entity should be captioned and referenced.
 how a given entity should be captioned and referenced.
 
 
-CATEGORY-NAME is used for qualifying captions on export.  You can
-modify the CATEGORY-NAME used in the exported document by
-modifying `org-export-dictionary'.  For example, an embedded
-image in an English document is captioned as \"Figure 1: Orgmode
-Logo\", by default.  If you want the image to be captioned as
-\"Illustration 1: Orgmode Logo\" instead, install an entry in
-`org-export-dictionary' which translates \"Figure\" to
-\"Illustration\" when the language is \"en\" and encoding is
-`:utf-8'.
+CATEGORY-NAME is used for qualifying captions on export.
 
 
 ENUMERATOR-PREDICATE is used for assigning a sequence number to
 ENUMERATOR-PREDICATE is used for assigning a sequence number to
 the entity.  See `org-odt--enumerate'.")
 the entity.  See `org-odt--enumerate'.")
@@ -375,6 +366,7 @@ visually."
 
 
 ;;;; Document schema
 ;;;; Document schema
 
 
+(require 'rng-loc)
 (defcustom org-odt-schema-dir
 (defcustom org-odt-schema-dir
   (let* ((schema-dir
   (let* ((schema-dir
 	  (catch 'schema-dir
 	  (catch 'schema-dir
@@ -768,13 +760,14 @@ link's path."
   :type '(alist :key-type (string :tag "Type")
   :type '(alist :key-type (string :tag "Type")
 		:value-type (regexp :tag "Path")))
 		:value-type (regexp :tag "Path")))
 
 
-(defcustom org-odt-pixels-per-inch display-pixels-per-inch
+(defcustom org-odt-pixels-per-inch 96.0
   "Scaling factor for converting images pixels to inches.
   "Scaling factor for converting images pixels to inches.
 Use this for sizing of embedded images.  See Info node `(org)
 Use this for sizing of embedded images.  See Info node `(org)
 Images in ODT export' for more information."
 Images in ODT export' for more information."
   :type 'float
   :type 'float
   :group 'org-export-odt
   :group 'org-export-odt
-  :version "24.1")
+  :version "24.4"
+  :package-version '(Org . "8.1"))
 
 
 
 
 ;;;; Src Block
 ;;;; Src Block
@@ -1045,20 +1038,6 @@ See `org-odt--build-date-styles' for implementation details."
 	      (error "Extraction failed"))))
 	      (error "Extraction failed"))))
 	members))
 	members))
 
 
-(defun org-odt--suppress-some-translators (info types)
-  ;; See comments in `org-odt-format-label' and `org-odt-toc'.
-  (org-combine-plists
-   info (list
-	 ;; Override translators.
-	 :translate-alist
-	 (nconc (mapcar (lambda (type) (cons type (lambda (data contents info)
-						    contents))) types)
-		(plist-get info :translate-alist))
-	 ;; Reset data translation cache.  FIXME.
-	 ;; :exported-data nil
-	 )))
-
-
 ;;;; Target
 ;;;; Target
 
 
 (defun org-odt--target (text id)
 (defun org-odt--target (text id)
@@ -1174,20 +1153,19 @@ See `org-odt--build-date-styles' for implementation details."
   (let* ((title (org-export-translate "Table of Contents" :utf-8 info))
   (let* ((title (org-export-translate "Table of Contents" :utf-8 info))
 	 (headlines (org-export-collect-headlines
 	 (headlines (org-export-collect-headlines
 		     info (and (wholenump depth) depth)))
 		     info (and (wholenump depth) depth)))
-	 (translations (nconc (mapcar
-			       (lambda (type)
-				 (cons type (lambda (data contents info)
-					      contents)))
-			       (list 'radio-target))
-			      (plist-get info :translate-alist))))
+	 (backend (org-export-create-backend
+		   :parent (org-export-backend-name
+			    (plist-get info :back-end))
+		   :transcoders (mapcar
+				 (lambda (type) (cons type (lambda (d c i) c)))
+				 (list 'radio-target)))))
     (when headlines
     (when headlines
       (concat
       (concat
        (org-odt-begin-toc title depth)
        (org-odt-begin-toc title depth)
        (mapconcat
        (mapconcat
 	(lambda (headline)
 	(lambda (headline)
 	  (let* ((entry (org-odt-format-headline--wrap
 	  (let* ((entry (org-odt-format-headline--wrap
-			 headline translations info
-			 'org-odt-format-toc-headline))
+			 headline backend info 'org-odt-format-toc-headline))
 		 (level (org-export-get-relative-level headline info))
 		 (level (org-export-get-relative-level headline info))
 		 (style (format "Contents_20_%d" level)))
 		 (style (format "Contents_20_%d" level)))
 	    (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 	    (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
@@ -1753,18 +1731,22 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	(t
 	(t
 	 (let* ((raw (org-export-get-footnote-definition
 	 (let* ((raw (org-export-get-footnote-definition
 		      footnote-reference info))
 		      footnote-reference info))
-		(translations
-		 (cons (cons 'paragraph
-			     (lambda (p c i)
-			       (org-odt--format-paragraph
-				p c "Footnote" "OrgFootnoteCenter"
-				"OrgFootnoteQuotations")))
-		       (org-export-backend-translate-table 'odt)))
-		(def (let ((def (org-trim (org-export-data-with-translations
-					   raw translations info))))
-		       (if (eq (org-element-type raw) 'org-data) def
-			 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
-				 "Footnote" def)))))
+		(def
+		 (let ((def (org-trim
+			     (org-export-data-with-backend
+			      raw
+			      (org-export-create-backend
+			       :parent 'odt
+			       :transcoders
+			       '((paragraph . (lambda (p c i)
+						(org-odt--format-paragraph
+						 p c "Footnote"
+						 "OrgFootnoteCenter"
+						 "OrgFootnoteQuotations")))))
+			      info))))
+		   (if (eq (org-element-type raw) 'org-data) def
+		     (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
+			     "Footnote" def)))))
 	   (funcall --format-footnote-definition n def))))))))
 	   (funcall --format-footnote-definition n def))))))))
 
 
 
 
@@ -1797,13 +1779,12 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 			    "<text:span text:style-name=\"%s\">%s</text:span>"
 			    "<text:span text:style-name=\"%s\">%s</text:span>"
 			    "OrgTag" tag)) tags " : "))))))
 			    "OrgTag" tag)) tags " : "))))))
 
 
-(defun org-odt-format-headline--wrap (headline translations info
-						 &optional format-function
-						 &rest extra-keys)
-  "Transcode a HEADLINE element from Org to ODT.
-CONTENTS holds the contents of the headline.  INFO is a plist
-holding contextual information."
-  (setq translations (or translations (plist-get info :translate-alist)))
+(defun org-odt-format-headline--wrap (headline backend info
+					       &optional format-function
+					       &rest extra-keys)
+  "Transcode a HEADLINE element using BACKEND.
+INFO is a plist holding contextual information."
+  (setq backend (or backend (plist-get info :back-end)))
   (let* ((level (+ (org-export-get-relative-level headline info)))
   (let* ((level (+ (org-export-get-relative-level headline info)))
 	 (headline-number (org-export-get-headline-number headline info))
 	 (headline-number (org-export-get-headline-number headline info))
 	 (section-number (and (org-export-numbered-headline-p headline info)
 	 (section-number (and (org-export-numbered-headline-p headline info)
@@ -1811,13 +1792,13 @@ holding contextual information."
 					 headline-number ".")))
 					 headline-number ".")))
 	 (todo (and (plist-get info :with-todo-keywords)
 	 (todo (and (plist-get info :with-todo-keywords)
 		    (let ((todo (org-element-property :todo-keyword headline)))
 		    (let ((todo (org-element-property :todo-keyword headline)))
-		      (and todo (org-export-data-with-translations
-				 todo translations info)))))
+		      (and todo
+			   (org-export-data-with-backend todo backend info)))))
 	 (todo-type (and todo (org-element-property :todo-type headline)))
 	 (todo-type (and todo (org-element-property :todo-type headline)))
 	 (priority (and (plist-get info :with-priority)
 	 (priority (and (plist-get info :with-priority)
 			(org-element-property :priority headline)))
 			(org-element-property :priority headline)))
-	 (text (org-export-data-with-translations
-		(org-element-property :title headline) translations info))
+	 (text (org-export-data-with-backend
+		(org-element-property :title headline) backend info))
 	 (tags (and (plist-get info :with-tags)
 	 (tags (and (plist-get info :with-tags)
 		    (org-export-get-tags headline info)))
 		    (org-export-get-tags headline info)))
 	 (headline-label (concat "sec-" (mapconcat 'number-to-string
 	 (headline-label (concat "sec-" (mapconcat 'number-to-string
@@ -1827,7 +1808,7 @@ holding contextual information."
 			   ((functionp org-odt-format-headline-function)
 			   ((functionp org-odt-format-headline-function)
 			    (function*
 			    (function*
 			     (lambda (todo todo-type priority text tags
 			     (lambda (todo todo-type priority text tags
-					   &allow-other-keys)
+				      &allow-other-keys)
 			       (funcall org-odt-format-headline-function
 			       (funcall org-odt-format-headline-function
 					todo todo-type priority text tags))))
 					todo todo-type priority text tags))))
 			   (t 'org-odt-format-headline))))
 			   (t 'org-odt-format-headline))))
@@ -1956,7 +1937,7 @@ holding contextual information."
     (let ((format-function
     (let ((format-function
 	   (function*
 	   (function*
 	    (lambda (todo todo-type priority text tags
 	    (lambda (todo todo-type priority text tags
-			  &key contents &allow-other-keys)
+		     &key contents &allow-other-keys)
 	      (funcall org-odt-format-inlinetask-function
 	      (funcall org-odt-format-inlinetask-function
 		       todo todo-type priority text tags contents)))))
 		       todo todo-type priority text tags contents)))))
       (org-odt-format-headline--wrap
       (org-odt-format-headline--wrap
@@ -2122,6 +2103,16 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
     tag))
     tag))
 
 
 (defun org-odt-format-label (element info op)
 (defun org-odt-format-label (element info op)
+  "Return a label for ELEMENT.
+
+ELEMENT is a `link', `table', `src-block' or `paragraph' type
+element.  INFO is a plist used as a communication channel.  OP is
+either `definition' or `reference', depending on the purpose of
+the generated string.
+
+Return value is a string if OP is set to `reference' or a cons
+cell like CAPTION . SHORT-CAPTION) where CAPTION and
+SHORT-CAPTION are strings."
   (assert (memq (org-element-type element) '(link table src-block paragraph)))
   (assert (memq (org-element-type element) '(link table src-block paragraph)))
   (let* ((caption-from
   (let* ((caption-from
 	  (case (org-element-type element)
 	  (case (org-element-type element)
@@ -2161,15 +2152,14 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	 ;; will do.
 	 ;; will do.
 	 (short-caption
 	 (short-caption
 	  (let ((short-caption (or short-caption caption))
 	  (let ((short-caption (or short-caption caption))
-		(translations (nconc (mapcar
-				      (lambda (type)
-					(cons type (lambda (data contents info)
-						     contents)))
-				      org-element-all-objects)
-				     (plist-get info :translate-alist))))
+		(backend (org-export-create-backend
+			  :parent (org-export-backend-name
+				   (plist-get info :back-end))
+			  :transcoders
+			  (mapcar (lambda (type) (cons type (lambda (o c i) c)))
+				  org-element-all-objects))))
 	    (when short-caption
 	    (when short-caption
-	      (org-export-data-with-translations short-caption
-						 translations info)))))
+	      (org-export-data-with-backend short-caption backend info)))))
     (when (or label caption)
     (when (or label caption)
       (let* ((default-category
       (let* ((default-category
 	       (case (org-element-type element)
 	       (case (org-element-type element)
@@ -2199,8 +2189,8 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	    ;; Case 1: Handle Label definition.
 	    ;; Case 1: Handle Label definition.
 	    (definition
 	    (definition
 	      ;; Assign an internal label, if user has not provided one
 	      ;; Assign an internal label, if user has not provided one
-	      (setq label (or label (format  "%s-%s" default-category seqno)))
-	      (setq label (org-export-solidify-link-text label))
+	      (setq label (org-export-solidify-link-text
+			   (or label (format  "%s-%s" default-category seqno))))
 	      (cons
 	      (cons
 	       (concat
 	       (concat
 		;; Sneak in a bookmark.  The bookmark is used when the
 		;; Sneak in a bookmark.  The bookmark is used when the
@@ -2209,8 +2199,11 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 		(format "\n<text:bookmark text:name=\"%s\"/>" label)
 		(format "\n<text:bookmark text:name=\"%s\"/>" label)
 		;; Label definition: Typically formatted as below:
 		;; Label definition: Typically formatted as below:
 		;;     CATEGORY SEQ-NO: LONG CAPTION
 		;;     CATEGORY SEQ-NO: LONG CAPTION
+		;; with translation for correct punctuation.
 		(format-spec
 		(format-spec
-		 (cadr (assoc-string label-style org-odt-label-styles t))
+		 (org-export-translate
+		  (cadr (assoc-string label-style org-odt-label-styles t))
+		  :utf-8 info)
 		 `((?e . ,category)
 		 `((?e . ,category)
 		   (?n . ,(format
 		   (?n . ,(format
 			   "<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">%s</text:sequence>"
 			   "<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">%s</text:sequence>"
@@ -2786,63 +2779,58 @@ INFO is a plist holding contextual information.  See
      ;; Links pointing to a headline: Find destination and build
      ;; Links pointing to a headline: Find destination and build
      ;; appropriate referencing command.
      ;; appropriate referencing command.
      ((member type '("custom-id" "fuzzy" "id"))
      ((member type '("custom-id" "fuzzy" "id"))
-      (let* ((destination (if (string= type "fuzzy")
-			      (org-export-resolve-fuzzy-link link info)
-			    (org-export-resolve-id-link link info))))
-	(or
-	 ;; Case 1: Fuzzy link points nowhere.
-	 (when (null (org-element-type destination))
+      (let ((destination (if (string= type "fuzzy")
+			     (org-export-resolve-fuzzy-link link info)
+			   (org-export-resolve-id-link link info))))
+	(case (org-element-type destination)
+	  ;; Case 1: Fuzzy link points nowhere.
+	  ('nil
 	   (format "<text:span text:style-name=\"%s\">%s</text:span>"
 	   (format "<text:span text:style-name=\"%s\">%s</text:span>"
-		   "Emphasis" (or desc (org-export-data
-					(org-element-property
-					 :raw-link link) info))))
-	 ;; Case 2: Fuzzy link points to an invisible target.  Strip it.
-	 (when (eq (org-element-type destination) 'keyword) "")
-	 ;; Case 3: LINK points to a headline.
-	 (when (eq (org-element-type destination) 'headline)
-	   ;; Case 3.1: LINK has a custom description that is
-	   ;; different from headline's title.  Create a hyperlink.
-	   (when (and desc
-		      (let ((link-desc (org-element-contents link)))
-			(not (string= (org-element-interpret-data link-desc)
-				      (org-element-property :raw-value
-							    destination)))))
-	     (let* ((headline-no (org-export-get-headline-number
-				  destination info))
-		    (label (format "sec-%s" (mapconcat 'number-to-string
-						       headline-no "-"))))
-	       (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
-		       label desc))))
-	 ;; Case 4: LINK points to an Inline image, Math formula or a Table.
-	 (let ((label-reference (ignore-errors (org-odt-format-label
-						destination info 'reference))))
-	   (when label-reference
-	     (cond
-	      ;; Case 4.1: LINK has no description. Create a
-	      ;; cross-reference showing entity's sequence number.
-	      ((not desc) label-reference)
-	      ;; Case 4.2: LINK has description.  Insert a hyperlink
-	      ;; with user-provided description.
-	      (t (let* ((caption-from (case (org-element-type destination)
-					(link (org-export-get-parent-element
-					       destination))
-					(t destination)))
-			;; Get label and caption.
-			(label (org-element-property :name caption-from)))
-		   (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
-			   (org-export-solidify-link-text label) desc))))))
-	 ;; Case 5: Fuzzy link points to a TARGET.
-	 (when (eq (org-element-type destination) 'target)
-	   ;; Case 5.1: LINK has description.  Create a hyperlink.
-	   (when desc
+		   "Emphasis"
+		   (or desc
+		       (org-export-data (org-element-property :raw-link link)
+					info))))
+	  ;; Case 2: Fuzzy link points to a headline.
+	  (headline
+	   ;; If there's a description, create a hyperlink.
+	   ;; Otherwise, try to provide a meaningful description.
+	   (if (not desc) (org-odt-link--infer-description destination info)
+	     (let* ((headline-no
+		     (org-export-get-headline-number destination info))
+		    (label
+		     (format "sec-%s"
+			     (mapconcat 'number-to-string headline-no "-"))))
+	       (format
+		"<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
+		label desc))))
+	  ;; Case 3: Fuzzy link points to a target.
+	  (target
+	   ;; If there's a description, create a hyperlink.
+	   ;; Otherwise, try to provide a meaningful description.
+	   (if (not desc) (org-odt-link--infer-description destination info)
 	     (let ((label (org-element-property :value destination)))
 	     (let ((label (org-element-property :value destination)))
 	       (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
 	       (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
-		       (org-export-solidify-link-text label) desc))))
-	 ;; LINK has no description. It points to either a HEADLINE or
-	 ;; an ELEMENT with a #+NAME: LABEL attached to it.  LINK to
-	 ;; DESTINATION, but make a best effort to provide
-	 ;; a *meaningful* description.
-	 (org-odt-link--infer-description destination info))))
+		       (org-export-solidify-link-text label)
+		       desc))))
+	  ;; Case 4: Fuzzy link points to some element (e.g., an
+	  ;; inline image, a math formula or a table).
+	  (otherwise
+	   (let ((label-reference
+		  (ignore-errors (org-odt-format-label
+				  destination info 'reference))))
+	     (cond ((not label-reference)
+		    (org-odt-link--infer-description destination info))
+		   ;; LINK has no description.  Create
+		   ;; a cross-reference showing entity's sequence
+		   ;; number.
+		   ((not desc) label-reference)
+		   ;; LINK has description.  Insert a hyperlink with
+		   ;; user-provided description.
+		   (t
+		    (let ((label (org-element-property :name destination)))
+		      (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
+			      (org-export-solidify-link-text label)
+			      desc)))))))))
      ;; Coderef: replace link with the reference name or the
      ;; Coderef: replace link with the reference name or the
      ;; equivalent line number.
      ;; equivalent line number.
      ((string= type "coderef")
      ((string= type "coderef")
@@ -2967,7 +2955,8 @@ contextual information."
     (setq output (org-odt--encode-plain-text output t))
     (setq output (org-odt--encode-plain-text output t))
     ;; Handle smart quotes.  Be sure to provide original string since
     ;; Handle smart quotes.  Be sure to provide original string since
     ;; OUTPUT may have been modified.
     ;; OUTPUT may have been modified.
-    (setq output (org-export-activate-smart-quotes output :utf-8 info text))
+    (when (plist-get info :with-smart-quotes)
+      (setq output (org-export-activate-smart-quotes output :utf-8 info text)))
     ;; Convert special strings.
     ;; Convert special strings.
     (when (plist-get info :with-special-strings)
     (when (plist-get info :with-special-strings)
       (mapc
       (mapc
@@ -3783,9 +3772,10 @@ contextual information."
 	   (setq processing-type 'mathml)
 	   (setq processing-type 'mathml)
 	 (message "LaTeX to MathML converter not available.")
 	 (message "LaTeX to MathML converter not available.")
 	 (setq processing-type 'verbatim)))
 	 (setq processing-type 'verbatim)))
-      (dvipng
+      ((dvipng imagemagick)
        (unless (and (org-check-external-command "latex" "" t)
        (unless (and (org-check-external-command "latex" "" t)
-		    (org-check-external-command "dvipng" "" t))
+		    (org-check-external-command
+		     (if (eq processing-type 'dvipng) "dvipng" "convert") "" t))
 	 (message "LaTeX to PNG converter not available.")
 	 (message "LaTeX to PNG converter not available.")
 	 (setq processing-type 'verbatim)))
 	 (setq processing-type 'verbatim)))
       (otherwise
       (otherwise
@@ -3798,7 +3788,7 @@ contextual information."
     (message "Formatting LaTeX using %s" processing-type)
     (message "Formatting LaTeX using %s" processing-type)
 
 
     ;; Convert `latex-fragment's and `latex-environment's.
     ;; Convert `latex-fragment's and `latex-environment's.
-    (when (memq processing-type '(mathml dvipng))
+    (when (memq processing-type '(mathml dvipng imagemagick))
       (org-element-map tree '(latex-fragment latex-environment)
       (org-element-map tree '(latex-fragment latex-environment)
 	(lambda (latex-*)
 	(lambda (latex-*)
 	  (incf count)
 	  (incf count)
@@ -3807,13 +3797,13 @@ contextual information."
 		 (cache-dir (file-name-directory input-file))
 		 (cache-dir (file-name-directory input-file))
 		 (cache-subdir (concat
 		 (cache-subdir (concat
 				(case processing-type
 				(case processing-type
-				  (dvipng "ltxpng/")
+				  ((dvipng imagemagick) "ltxpng/")
 				  (mathml "ltxmathml/"))
 				  (mathml "ltxmathml/"))
 				(file-name-sans-extension
 				(file-name-sans-extension
 				 (file-name-nondirectory input-file))))
 				 (file-name-nondirectory input-file))))
 		 (display-msg
 		 (display-msg
 		  (case processing-type
 		  (case processing-type
-		    (dvipng (format "Creating LaTeX Image %d..." count))
+		    ((dvipng imagemagick) (format "Creating LaTeX Image %d..." count))
 		    (mathml (format "Creating MathML snippet %d..." count))))
 		    (mathml (format "Creating MathML snippet %d..." count))))
 		 ;; Get an Org-style link to PNG image or the MathML
 		 ;; Get an Org-style link to PNG image or the MathML
 		 ;; file.
 		 ;; file.

+ 36 - 28
lisp/ox-publish.el

@@ -449,10 +449,16 @@ matching the regexp SKIP-DIR when recursing through BASE-DIR."
 			  (not (string-match match fnd)))
 			  (not (string-match match fnd)))
 
 
 		(pushnew f org-publish-temp-files)))))
 		(pushnew f org-publish-temp-files)))))
-	(if org-sitemap-requested
-	    (sort (directory-files base-dir t (unless recurse match))
-		  'org-publish-compare-directory-files)
-	  (directory-files base-dir t (unless recurse match)))))
+	(let ((all-files (if (not recurse) (directory-files base-dir t match)
+			   ;; If RECURSE is non-nil, we want all files
+			   ;; matching MATCH and sub-directories.
+			   (org-remove-if-not
+			    (lambda (file)
+			      (or (file-directory-p file)
+				  (and match (string-match match file))))
+			    (directory-files base-dir t)))))
+	  (if (not org-sitemap-requested) all-files
+	    (sort all-files 'org-publish-compare-directory-files)))))
 
 
 (defun org-publish-get-base-files (project &optional exclude-regexp)
 (defun org-publish-get-base-files (project &optional exclude-regexp)
   "Return a list of all files in PROJECT.
   "Return a list of all files in PROJECT.
@@ -811,30 +817,32 @@ Default for SITEMAP-FILENAME is 'sitemap.org'."
 
 
 (defun org-publish-find-date (file)
 (defun org-publish-find-date (file)
   "Find the date of FILE in project.
   "Find the date of FILE in project.
-If FILE provides a DATE keyword use it else use the file system's
-modification time.  Return time in `current-time' format."
-  (let* ((org-inhibit-startup t)
-	 (visiting (find-buffer-visiting file))
-	 (file-buf (or visiting (find-file-noselect file nil)))
-	 (date (plist-get
-		(with-current-buffer file-buf
-		  (org-mode)
-		  (org-export-get-environment))
-		:date)))
-    (unless visiting (kill-buffer file-buf))
-    ;; DATE is either a timestamp object or a secondary string.  If it
-    ;; is a timestamp or if the secondary string contains a timestamp,
-    ;; convert it to internal format.  Otherwise, use FILE
-    ;; modification time.
-    (cond ((eq (org-element-type date) 'timestamp)
-	   (org-time-string-to-time (org-element-interpret-data date)))
-	  ((let ((ts (and (consp date) (assq 'timestamp date))))
-	     (and ts
-		  (let ((value (org-element-interpret-data ts)))
-		    (and (org-string-nw-p value)
-			 (org-time-string-to-time value))))))
-	  ((file-exists-p file) (nth 5 (file-attributes file)))
-	  (t (error "No such file: \"%s\"" file)))))
+This function assumes FILE is either a directory or an Org file.
+If FILE is an Org file and provides a DATE keyword use it.  In
+any other case use the file system's modification time.  Return
+time in `current-time' format."
+  (if (file-directory-p file) (nth 5 (file-attributes file))
+    (let* ((visiting (find-buffer-visiting file))
+	   (file-buf (or visiting (find-file-noselect file nil)))
+	   (date (plist-get
+		  (with-current-buffer file-buf
+		    (let ((org-inhibit-startup t)) (org-mode))
+		    (org-export-get-environment))
+		  :date)))
+      (unless visiting (kill-buffer file-buf))
+      ;; DATE is either a timestamp object or a secondary string.  If it
+      ;; is a timestamp or if the secondary string contains a timestamp,
+      ;; convert it to internal format.  Otherwise, use FILE
+      ;; modification time.
+      (cond ((eq (org-element-type date) 'timestamp)
+	     (org-time-string-to-time (org-element-interpret-data date)))
+	    ((let ((ts (and (consp date) (assq 'timestamp date))))
+	       (and ts
+		    (let ((value (org-element-interpret-data ts)))
+		      (and (org-string-nw-p value)
+			   (org-time-string-to-time value))))))
+	    ((file-exists-p file) (nth 5 (file-attributes file)))
+	    (t (error "No such file: \"%s\"" file))))))
 
 
 
 
 
 

Разница между файлами не показана из-за своего большого размера
+ 436 - 272
lisp/ox.el


+ 91 - 0
testing/examples/babel.org

@@ -359,3 +359,94 @@ Here is a call line with more than just the results exported.
   <<strip-export-1>>
   <<strip-export-1>>
   echo "1$i"
   echo "1$i"
 #+END_SRC
 #+END_SRC
+
+* use case of reading entry properties
+  :PROPERTIES:
+  :ID:       cc5fbc20-bca5-437a-a7b8-2b4d7a03f820
+  :END:
+
+Use case checked and documented with this test: During their
+evaluation the source blocks read values from properties from the
+entry where the call has been made unless the value is overridden with
+the optional argument of the caller.
+
+** section
+   :PROPERTIES:
+   :a:        1
+   :c:        3
+   :END:
+
+Note: Just export of a property can be done with a macro: {{{property(a)}}}.
+
+#+NAME: src_block_location_shell sect call
+#+CALL: src_block_location_shell()
+
+#+NAME: src_block_location_elisp sect call
+#+CALL: src_block_location_elisp()
+
+- sect inline call_src_block_location_shell()
+- sect inline call_src_block_location_elisp()
+
+*** subsection
+    :PROPERTIES:
+    :b:        2
+    :c:        4
+    :END:
+
+#+NAME: src_block_location_shell sub0 call
+#+CALL: src_block_location_shell()
+
+#+NAME: src_block_location_elisp sub0 call
+#+CALL: src_block_location_elisp()
+
+- sub0 inline call_src_block_location_shell()
+- sub0 inline call_src_block_location_elisp()
+
+#+NAME: src_block_location_shell sub1 call
+#+CALL: src_block_location_shell(c=5, e=6)
+
+#+NAME: src_block_location_elisp sub1 call
+#+CALL: src_block_location_elisp(c=5, e=6)
+
+- sub1 inline call_src_block_location_shell(c=5, e=6)
+- sub1 inline call_src_block_location_elisp(c=5, e=6)
+
+**** function definition
+
+#+NAME: src_block_location_shell
+#+HEADER: :var a=(or (org-entry-get org-babel-current-src-block-location "a" t) "0")
+#+HEADER: :var b=(or (org-entry-get org-babel-current-src-block-location "b" t) "0")
+#+HEADER: :var c=(or (org-entry-get org-babel-current-src-block-location "c" t) "0")
+#+HEADER: :var d=(or (org-entry-get org-babel-current-src-block-location "d" t) "0")
+#+HEADER: :var e=(or (org-entry-get org-babel-current-src-block-location "e" t) "0")
+#+BEGIN_SRC sh :shebang #!/bin/sh :exports results :results verbatim
+  printf "shell a:$a, b:$b, c:$c, d:$d, e:$e"
+#+END_SRC
+
+#+RESULTS: src_block_location_shell
+
+#+NAME: src_block_location_elisp
+#+HEADER: :var a='nil
+#+HEADER: :var b='nil
+#+HEADER: :var c='nil
+#+HEADER: :var d='nil
+#+HEADER: :var e='nil
+#+BEGIN_SRC emacs-lisp :exports results
+  (setq
+   a (or a (string-to-number
+            (or (org-entry-get org-babel-current-src-block-location "a" t)
+                "0")))
+   b (or b (string-to-number
+            (or (org-entry-get org-babel-current-src-block-location "b" t)
+                "0")))
+   c (or c (string-to-number
+            (or (org-entry-get org-babel-current-src-block-location "c" t)
+                "0")))
+   d (or d (string-to-number
+            (or (org-entry-get org-babel-current-src-block-location "e" t)
+                "0")))
+   e (or e (string-to-number
+            (or (org-entry-get org-babel-current-src-block-location "d" t)
+                "0"))))
+  (format "elisp a:%d, b:%d, c:%d, d:%d, e:%d" a b c d e)
+#+END_SRC

+ 42 - 0
testing/lisp/test-ob-exp.el

@@ -216,6 +216,48 @@ Here is one at the end of a line. =2=
       (should-not (string-match (regexp-quote "<<strip-export-1>>") result))
       (should-not (string-match (regexp-quote "<<strip-export-1>>") result))
       (should-not (string-match (regexp-quote "i=\"10\"") result)))))
       (should-not (string-match (regexp-quote "i=\"10\"") result)))))
 
 
+(ert-deftest ob-exp/use-case-of-reading-entry-properties ()
+  (org-test-at-id "cc5fbc20-bca5-437a-a7b8-2b4d7a03f820"
+    (org-narrow-to-subtree)
+    (let* ((case-fold-search nil)
+	   (result (org-test-with-expanded-babel-code (buffer-string)))
+	   (sect "a:1, b:0, c:3, d:0, e:0")
+	   (sub0 "a:1, b:2, c:4, d:0, e:0")
+	   (sub1 "a:1, b:2, c:5, d:0, e:6")
+	   (func sub0))
+      ;; entry "section"
+      (should (string-match (concat "_shell sect call\n: shell " sect "\n")
+			    result))
+      (should (string-match (concat "_elisp sect call\n: elisp " sect "\n")
+			    result))
+      (should (string-match (concat "\n- sect inline =shell " sect "=\n")
+			    result))
+      (should (string-match (concat "\n- sect inline =elisp " sect "=\n")
+			    result))
+      ;; entry "subsection", call without arguments
+      (should (string-match (concat "_shell sub0 call\n: shell " sub0 "\n")
+			    result))
+      (should (string-match (concat "_elisp sub0 call\n: elisp " sub0 "\n")
+			    result))
+      (should (string-match (concat "\n- sub0 inline =shell " sub0 "=\n")
+			    result))
+      (should (string-match (concat "\n- sub0 inline =elisp " sub0 "=\n")
+			    result))
+      ;; entry "subsection", call with arguments
+      (should (string-match (concat "_shell sub1 call\n: shell " sub1 "\n")
+			    result))
+      (should (string-match (concat "_elisp sub1 call\n: elisp " sub1 "\n")
+			    result))
+      (should (string-match (concat "\n- sub1 inline =shell " sub1 "=\n")
+			    result))
+      (should (string-match (concat "\n- sub1 inline =elisp " sub1 "=\n")
+			    result))
+      ;; entry "function definition"
+      (should (string-match (concat "_location_shell\n: shell " func "\n")
+			    result))
+      (should (string-match (concat "_location_elisp\n: elisp " func "\n")
+			    result)))))
+
 (ert-deftest ob-exp/export-from-a-temp-buffer ()
 (ert-deftest ob-exp/export-from-a-temp-buffer ()
   :expected-result :failed
   :expected-result :failed
   (org-test-with-temp-text
   (org-test-with-temp-text

+ 23 - 0
testing/lisp/test-ob.el

@@ -1144,6 +1144,29 @@ echo \"$data\"
 	    (org-babel-execute-src-block)
 	    (org-babel-execute-src-block)
 	    (buffer-string)))))
 	    (buffer-string)))))
 
 
+(ert-deftest test-ob/location-of-header-arg-eval ()
+  "Test location of header argument evaluation."
+  (org-test-with-temp-text "
+#+name: top-block
+#+begin_src emacs-lisp :var pt=(point)
+  pt
+#+end_src
+
+#+name: bottom-block
+#+begin_src emacs-lisp :var pt=top-block()
+  pt
+#+end_src
+"
+    ;; the value of the second block should be greater than the first
+    (should
+     (< (progn (re-search-forward org-babel-src-block-regexp nil t)
+	       (goto-char (match-beginning 0))
+	       (prog1 (save-match-data (org-babel-execute-src-block))
+		 (goto-char (match-end 0))))
+	(progn (re-search-forward org-babel-src-block-regexp nil t)
+	       (goto-char (match-beginning 0))
+	       (org-babel-execute-src-block))))))
+
 (provide 'test-ob)
 (provide 'test-ob)
 
 
 ;;; test-ob ends here
 ;;; test-ob ends here

+ 27 - 9
testing/lisp/test-org-element.el

@@ -1511,7 +1511,12 @@ Outside list"
 	 ;; Move to ending of outer list.
 	 ;; Move to ending of outer list.
 	 (progn (goto-char (car endings)) (looking-at "Outside list"))
 	 (progn (goto-char (car endings)) (looking-at "Outside list"))
 	 ;; Move to ending of inner list.
 	 ;; Move to ending of inner list.
-	 (progn (goto-char (nth 1 endings)) (looking-at "^$"))))))))
+	 (progn (goto-char (nth 1 endings)) (looking-at "^$")))))))
+  ;; Correctly compute end of list if it doesn't end at a line
+  ;; beginning.
+  (should
+   (org-test-with-temp-text "- list\n   \n   "
+     (= (org-element-property :end (org-element-at-point)) (point-max)))))
 
 
 
 
 ;;;; Planning
 ;;;; Planning
@@ -2139,30 +2144,38 @@ Outside list"
 (ert-deftest test-org-element/plain-list-interpreter ()
 (ert-deftest test-org-element/plain-list-interpreter ()
   "Test plain-list and item interpreters."
   "Test plain-list and item interpreters."
   (let ((org-list-two-spaces-after-bullet-regexp nil))
   (let ((org-list-two-spaces-after-bullet-regexp nil))
-    ;; 1. Unordered list.
+    ;; Unordered list.
     (should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
     (should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
-    ;; 2. Description list.
+    ;; Description list.
     (should
     (should
      (equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
      (equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
-    ;; 3. Ordered list.
+    ;; Ordered list.
     (should
     (should
      (equal (let ((org-plain-list-ordered-item-terminator t))
      (equal (let ((org-plain-list-ordered-item-terminator t))
 	      (org-test-parse-and-interpret "1. Item"))
 	      (org-test-parse-and-interpret "1. Item"))
 	    "1. Item\n"))
 	    "1. Item\n"))
-    ;; 4. Ordered list with counter.
+    (should
+     (equal (let ((org-plain-list-ordered-item-terminator ?\)))
+	      (org-test-parse-and-interpret "1) Item"))
+	    "1) Item\n"))
+    ;; Ordered list with counter.
     (should
     (should
      (equal (let ((org-plain-list-ordered-item-terminator t))
      (equal (let ((org-plain-list-ordered-item-terminator t))
 	      (org-test-parse-and-interpret "1. [@5] Item"))
 	      (org-test-parse-and-interpret "1. [@5] Item"))
 	    "5. [@5] Item\n"))
 	    "5. [@5] Item\n"))
-    ;; 5. List with check-boxes.
+    ;; List with check-boxes.
     (should
     (should
      (equal (org-test-parse-and-interpret
      (equal (org-test-parse-and-interpret
 	     "- [-] Item 1\n  - [X] Item 2\n  - [ ] Item 3")
 	     "- [-] Item 1\n  - [X] Item 2\n  - [ ] Item 3")
 	    "- [-] Item 1\n  - [X] Item 2\n  - [ ] Item 3\n"))
 	    "- [-] Item 1\n  - [X] Item 2\n  - [ ] Item 3\n"))
-    ;; 6. Item not starting with a paragraph.
+    ;; Item not starting with a paragraph.
     (should
     (should
      (equal (org-test-parse-and-interpret "-\n  | a | b |")
      (equal (org-test-parse-and-interpret "-\n  | a | b |")
-	    "- \n  | a | b |\n"))))
+	    "- \n  | a | b |\n"))
+    ;; Special case: correctly handle "*" bullets.
+    (should (org-test-parse-and-interpret " * item"))
+    ;; Special case: correctly handle empty items.
+    (should (org-test-parse-and-interpret "-"))))
 
 
 (ert-deftest test-org-element/quote-block-interpreter ()
 (ert-deftest test-org-element/quote-block-interpreter ()
   "Test quote block interpreter."
   "Test quote block interpreter."
@@ -2848,7 +2861,12 @@ Paragraph \\alpha."
 	   "- outer\n  #+begin_center\n  - inner\n  #+end_center"
 	   "- outer\n  #+begin_center\n  - inner\n  #+end_center"
 	 (search-forward "inner")
 	 (search-forward "inner")
 	 (beginning-of-line)
 	 (beginning-of-line)
-	 (org-element-type (org-element-at-point))))))
+	 (org-element-type (org-element-at-point)))))
+  ;; Do not error at eob on an empty line.
+  (should
+   (org-test-with-temp-text "* H\n"
+     (forward-line)
+     (or (org-element-at-point) t))))
 
 
 (ert-deftest test-org-element/context ()
 (ert-deftest test-org-element/context ()
   "Test `org-element-context' specifications."
   "Test `org-element-context' specifications."

+ 28 - 2
testing/lisp/test-org.el

@@ -69,7 +69,8 @@
 	      (goto-char (point-max))
 	      (goto-char (point-max))
 	      (call-interactively 'comment-dwim)
 	      (call-interactively 'comment-dwim)
 	      (buffer-string)))))
 	      (buffer-string)))))
-  ;; Region selected without comments: comment all non-blank lines.
+  ;; Region selected without comments: comment all lines if
+  ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
   (should
   (should
    (equal "# Comment 1\n\n# Comment 2"
    (equal "# Comment 1\n\n# Comment 2"
 	  (org-test-with-temp-text "Comment 1\n\nComment 2"
 	  (org-test-with-temp-text "Comment 1\n\nComment 2"
@@ -77,7 +78,18 @@
 	      (transient-mark-mode 1)
 	      (transient-mark-mode 1)
 	      (push-mark (point) t t)
 	      (push-mark (point) t t)
 	      (goto-char (point-max))
 	      (goto-char (point-max))
-	      (call-interactively 'comment-dwim)
+	      (let ((comment-empty-lines nil))
+		(call-interactively 'comment-dwim))
+	      (buffer-string)))))
+  (should
+   (equal "# Comment 1\n# \n# Comment 2"
+	  (org-test-with-temp-text "Comment 1\n\nComment 2"
+	    (progn
+	      (transient-mark-mode 1)
+	      (push-mark (point) t t)
+	      (goto-char (point-max))
+	      (let ((comment-empty-lines t))
+		(call-interactively 'comment-dwim))
 	      (buffer-string)))))
 	      (buffer-string)))))
   ;; In front of a keyword without region, insert a new comment.
   ;; In front of a keyword without region, insert a new comment.
   (should
   (should
@@ -199,6 +211,20 @@
 	    (let ((fill-column 20))
 	    (let ((fill-column 20))
 	      (org-fill-paragraph)
 	      (org-fill-paragraph)
 	      (buffer-string)))))
 	      (buffer-string)))))
+  ;; Do not mix consecutive comments when filling one of them.
+  (should
+   (equal "# A B\n\n# C"
+	  (org-test-with-temp-text "# A\n# B\n\n# C"
+	    (let ((fill-column 20))
+	      (org-fill-paragraph)
+	      (buffer-string)))))
+  ;; Use commented empty lines as separators when filling comments.
+  (should
+   (equal "# A B\n#\n# C"
+	  (org-test-with-temp-text "# A\n# B\n#\n# C"
+	    (let ((fill-column 20))
+	      (org-fill-paragraph)
+	      (buffer-string)))))
   ;; Do nothing at affiliated keywords.
   ;; Do nothing at affiliated keywords.
   (org-test-with-temp-text "#+NAME: para\nSome\ntext."
   (org-test-with-temp-text "#+NAME: para\nSome\ntext."
     (let ((fill-column 20))
     (let ((fill-column 20))

Разница между файлами не показана из-за своего большого размера
+ 405 - 286
testing/lisp/test-ox.el


Некоторые файлы не были показаны из-за большого количества измененных файлов