From 618eb91e12bb1474765401b18890631850dc3850 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Thu, 1 Mar 2012 11:28:46 -0700 Subject: [PATCH 01/15] fully remove contrib/ from the test infrastucture --- testing/org-test.el | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/testing/org-test.el b/testing/org-test.el index 3696db126..df06e65b8 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -224,12 +224,8 @@ otherwise place the point at the beginning of the inserted text." (defjump org-test-jump (("lisp/\\1.el" . "testing/lisp/test-\\1.el") ("lisp/\\1.el" . "testing/lisp/\\1.el/test.*.el") - ("contrib/lisp/\\1.el" . "testing/contrib/lisp/test-\\1.el") - ("contrib/lisp/\\1.el" . "testing/contrib/lisp/\\1.el/test.*.el") ("testing/lisp/test-\\1.el" . "lisp/\\1.el") - ("testing/lisp/\\1.el" . "lisp/\\1.el/test.*.el") - ("testing/contrib/lisp/test-\\1.el" . "contrib/lisp/\\1.el") - ("testing/contrib/lisp/test-\\1.el" . "contrib/lisp/\\1.el/test.*.el")) + ("testing/lisp/\\1.el" . "lisp/\\1.el/test.*.el")) (concat org-base-dir "/") "Jump between org-mode files and their tests." (lambda (path) @@ -313,8 +309,7 @@ otherwise place the point at the beginning of the inserted text." :expected-result :failed (should nil)))))))) (directory-files base 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*\\.el$")))) - (rld (expand-file-name "lisp" org-test-dir)) - (rld (expand-file-name "lisp" (expand-file-name "contrib" org-test-dir))))) + (rld (expand-file-name "lisp" org-test-dir)))) (defun org-test-current-defun () "Test the current function." From a3a48f698f103c3f37b1d166ce0e0b1716312056 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Thu, 1 Mar 2012 11:37:04 -0700 Subject: [PATCH 02/15] ensure that test constants are loaded by org-test.el --- testing/org-test.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/org-test.el b/testing/org-test.el index df06e65b8..f2555849b 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -30,6 +30,8 @@ ;;;; Code: +(require 'org-test-ob-consts) + (let* ((org-test-dir (expand-file-name (file-name-directory (or load-file-name buffer-file-name)))) From 9e3b41d1a4187ec6236d9ba15c0879f8a4ac723c Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Thu, 1 Mar 2012 11:37:37 -0700 Subject: [PATCH 03/15] Fixed bug in examplization * lisp/ob.el (org-babel-examplize-region): Fixed bug in examplization. --- lisp/ob.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/ob.el b/lisp/ob.el index 6b62c6335..6507b50d4 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1955,7 +1955,8 @@ file's directory then expand relative links." (defun org-babel-examplize-region (beg end &optional results-switches) "Comment out region using the inline '==' or ': ' org example quote." (interactive "*r") - (flet ((chars-between (b e) (string-match "[\\S]" (buffer-substring b e)))) + (flet ((chars-between (b e) + (not (string-match "^[\\s]*$" (buffer-substring b e))))) (if (or (chars-between (save-excursion (goto-char beg) (point-at-bol)) beg) (chars-between end (save-excursion (goto-char end) (point-at-eol)))) (save-excursion From 3e6f5620c67628a7e95a733a7226b9f435918e6f Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Thu, 1 Mar 2012 13:04:15 -0700 Subject: [PATCH 04/15] Fixed call line matching regular expressions * lisp/ob-lob.el (org-babel-block-lob-one-liner-regexp): Less greedy regular expressions. (org-babel-inline-lob-one-liner-regexp): Less greedy regular expressions. --- lisp/ob-lob.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/ob-lob.el b/lisp/ob-lob.el index 181eee22b..58440f0e4 100644 --- a/lisp/ob-lob.el +++ b/lisp/ob-lob.el @@ -65,14 +65,14 @@ To add files to this list use the `org-babel-lob-ingest' command." (defconst org-babel-block-lob-one-liner-regexp (concat - "^\\([ \t]*\\)#\\+call:[ \t]+\\([^\(\)\n]+?\\)\\(\\[\\(.*\\)\\]\\|\\(\\)\\)" - "\(\\([^\n]*\\)\)\\(\\[.+\\]\\|\\)[ \t]*\\(\\([^\n]*\\)\\)?") + "^\\([ \t]*?\\)#\\+call:[ \t]+\\([^\(\)\n]+?\\)\\(\\[\\(.*\\)\\]\\|\\(\\)\\)" + "\(\\([^\n]*?\\)\)\\(\\[.+\\]\\|\\)[ \t]*\\(\\([^\n]*\\)\\)?") "Regexp to match non-inline calls to predefined source block functions.") (defconst org-babel-inline-lob-one-liner-regexp (concat - "\\([^\n]*\\)call_\\([^\(\)\n]+?\\)\\(\\[\\(.*\\)\\]\\|\\(\\)\\)" - "\(\\([^\n]*\\)\)\\(\\[\\(.*?\\)\\]\\)?") + "\\([^\n]*?\\)call_\\([^\(\)\n]+?\\)\\(\\[\\(.*?\\)\\]\\|\\(\\)\\)" + "\(\\([^\n]*?\\)\)\\(\\[\\(.*?\\)\\]\\)?") "Regexp to match inline calls to predefined source block functions.") (defconst org-babel-lob-one-liner-regexp From 5bcf0c16dae8d9ef2ed7da6279a904d5d8184b70 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Thu, 1 Mar 2012 13:15:00 -0700 Subject: [PATCH 05/15] Don't miss a code block when there are confounding spaces after the result name. * lisp/ob.el (org-babel-find-named-result): Don't miss a code block when there are confounding spaces after the result name. --- lisp/ob.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/ob.el b/lisp/ob.el index 6507b50d4..701e923d4 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1495,7 +1495,7 @@ buffer or nil if no such result exists." (catch 'is-a-code-block (when (re-search-forward (concat org-babel-result-regexp - "[ \t]" (regexp-quote name) "[ \t\n\f\v\r]") nil t) + "[ \t]" (regexp-quote name) "[ \t\n\f\v\r]+") nil t) (when (and (string= "name" (downcase (match-string 1))) (or (looking-at org-babel-src-block-regexp) (looking-at org-babel-multi-line-header-regexp))) From b65725e039b97748a6386192025ace8b5ee8d510 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Fri, 2 Mar 2012 13:10:12 +0530 Subject: [PATCH 06/15] org-e-html/org-e-odt: Support for code numbering --- EXPERIMENTAL/org-e-html.el | 72 +++++++++++++++++++--------------- EXPERIMENTAL/org-e-odt.el | 80 ++++++++++++++++++++------------------ 2 files changed, 83 insertions(+), 69 deletions(-) diff --git a/EXPERIMENTAL/org-e-html.el b/EXPERIMENTAL/org-e-html.el index 4849db2b6..02ba2ef04 100644 --- a/EXPERIMENTAL/org-e-html.el +++ b/EXPERIMENTAL/org-e-html.el @@ -1855,35 +1855,33 @@ contextual information." ;; (defun org-odt-format-source-code-or-example-colored ;; (lines lang caption textareap cols rows num cont rpllbl fmt)) +(defun org-e-html-format-source-line-with-line-number-and-label (line) + (let ((ref (org-find-text-property-in-string 'org-coderef line)) + (num (org-find-text-property-in-string 'org-loc line))) + (when num + (setq line (format "%d: %s (%s)" + num line ref))) + (when ref + (setq line + (format + "%s (%s)" + ref line ref))) + line)) + (defun org-e-html-format-source-code-or-example-plain (lines lang caption textareap cols rows num cont rpllbl fmt) - (setq lines - (concat - "
\n"
-	 (cond
-	  (textareap
-	   (concat
-	    (format "

\n\n

\n")) - (t - (with-temp-buffer - (insert lines) - (goto-char (point-min)) - (while (re-search-forward "[<>&]" nil t) - (replace-match (cdr (assq (char-before) - '((?&."&")(?<."<")(?>.">")))) - t t)) - (buffer-string)))) - "
\n")) - - (unless textareap - (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt))) - - ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines) - ;; (setq lines (replace-match "\\1" t nil lines))) - - lines) + (format + "\n
\n%s\n
" + (cond + (textareap + (format "

\n\n

\n" + cols rows lines)) + (t (mapconcat + (lambda (line) + (org-e-html-format-source-line-with-line-number-and-label + (org-e-html-encode-plain-text line))) + (org-split-string lines "\n") + "\n"))))) (defun org-e-html-format-source-code-or-example-colored (lines lang caption textareap cols rows num cont rpllbl fmt) @@ -1925,7 +1923,11 @@ contextual information." lines ""))) (unless textareap - (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt))) + (setq lines + (mapconcat + (lambda (line) + (org-e-html-format-source-line-with-line-number-and-label line)) + (org-split-string lines "\n") "\n"))) ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines) ;; (setq lines (replace-match "\\1" t nil lines))) @@ -2008,7 +2010,7 @@ INDENT was the original indentation of the block." "Transcode a EXAMPLE-BLOCK element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (let* ((options (or (org-element-property :options example-block) "")) - (value (org-export-handle-code example-block info))) + (value (org-export-handle-code example-block info nil nil t))) ;; (org-e-html--wrap-label ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value)) (org-e-html--wrap-label @@ -2590,8 +2592,14 @@ INFO is a plist holding contextual information. See ;; Coderef: replace link with the reference name or the ;; equivalent line number. ((string= type "coderef") - (format (org-export-get-coderef-format path (or desc "")) - (org-export-resolve-coderef path info))) + (let ((fragment (concat "coderef-" path))) + (format "%s" fragment + (format (concat "class=\"coderef\"" + " onmouseover=\"CodeHighlightOn(this, '%s');\"" + " onmouseout=\"CodeHighlightOff(this, '%s');\"") + fragment fragment) + (format (org-export-get-coderef-format path (or desc "%s")) + (org-export-resolve-coderef path info))))) ;; Link type is handled by a special function. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols)))) (funcall protocol (org-link-unescape path) desc 'html)) @@ -2808,7 +2816,7 @@ holding contextual information." CONTENTS holds the contents of the item. INFO is a plist holding contextual information." (let* ((lang (org-element-property :language src-block)) - (code (org-export-handle-code src-block info)) + (code (org-export-handle-code src-block info nil nil t)) (caption (org-element-property :caption src-block)) (label (org-element-property :name src-block))) ;; FIXME: Handle caption diff --git a/EXPERIMENTAL/org-e-odt.el b/EXPERIMENTAL/org-e-odt.el index fc768781b..9cbf9299e 100644 --- a/EXPERIMENTAL/org-e-odt.el +++ b/EXPERIMENTAL/org-e-odt.el @@ -566,7 +566,7 @@ styles congruent with the ODF-1.2 specification." (let ((xref-format "text")) (when (numberp desc) (setq desc (format "%d" desc) xref-format "number")) - (org-e-odt-format-tags + (org-e-odt-format-tags-simple '("" . "") desc xref-format href))) @@ -575,7 +575,7 @@ styles congruent with the ODF-1.2 specification." '("" . "") desc href (or attr ""))) (t - (org-e-odt-format-tags + (org-e-odt-format-tags-simple '("" . "") desc href (or attr ""))))) @@ -625,17 +625,18 @@ styles congruent with the ODF-1.2 specification." (defun org-e-odt-format-source-line-with-line-number-and-label - (line rpllbl num fontifier par-style) - - (let ((keep-label (not (numberp rpllbl))) - (ref (org-find-text-property-in-string 'org-coderef line))) - (setq line (concat line (and keep-label ref (format "(%s)" ref)))) + (line fontifier par-style) + (let (;; (keep-label (not (numberp rpllbl))) + (ref (org-find-text-property-in-string 'org-coderef line)) + (num (org-find-text-property-in-string 'org-loc line))) + (setq line (concat line (and ref (format "(%s)" ref)))) (setq line (funcall fontifier line)) (when ref (setq line (org-e-odt-format-target line (concat "coderef-" ref)))) (setq line (org-e-odt-format-stylized-paragraph par-style line)) (if (not num) line - (org-e-odt-format-tags '("" . "") line)))) + (org-e-odt-format-tags + '("" . "") line)))) (defun org-e-odt-format-source-code-or-example-plain (lines lang caption textareap cols rows num cont rpllbl fmt) @@ -649,7 +650,7 @@ off." (lambda (line) (incf i) (org-e-odt-format-source-line-with-line-number-and-label - line rpllbl num 'org-e-odt-encode-plain-text + line 'org-e-odt-encode-plain-text (if (= i line-count) "OrgFixedWidthBlockLastLine" "OrgFixedWidthBlock"))) lines "\n"))) @@ -701,8 +702,7 @@ Update styles.xml with styles that were collected as part of (goto-char (match-beginning 0)) (insert "\n\n" styles "\n"))))) -(defun org-e-odt-format-source-code-or-example-colored - (lines lang caption textareap cols rows num cont rpllbl fmt) +(defun org-e-odt-format-source-code-or-example-colored (lines lang caption) "Format source or example blocks using `htmlfontify-string'. Use this routine when `org-export-e-odt-fontify-srcblocks' option is turned on." @@ -740,37 +740,37 @@ is turned on." (lambda (line) (incf i) (org-e-odt-format-source-line-with-line-number-and-label - line rpllbl num 'htmlfontify-string + line 'htmlfontify-string (if (= i line-count) "OrgSrcBlockLastLine" "OrgSrcBlock"))) lines "\n"))))) (defun org-e-odt-format-source-code-or-example (lines lang - &optional - caption textareap - cols rows num cont - rpllbl fmt) + &optional caption ; FIXME + ) "Format source or example blocks for export. Use `org-e-odt-format-source-code-or-example-plain' or `org-e-odt-format-source-code-or-example-colored' depending on the value of `org-export-e-odt-fontify-srcblocks." (setq ;; lines (org-export-number-lines - ;; lines 0 0 num cont rpllbl fmt 'preprocess) FIXME - lines (funcall - (or (and org-export-e-odt-fontify-srcblocks - (or (featurep 'htmlfontify) - ;; htmlfontify.el was introduced in Emacs 23.2 - ;; So load it with some caution - (require 'htmlfontify nil t)) - (fboundp 'htmlfontify-string) - 'org-e-odt-format-source-code-or-example-colored) - 'org-e-odt-format-source-code-or-example-plain) - lines lang caption textareap cols rows num cont rpllbl fmt)) - (if (not num) lines - (let ((extra (format " text:continue-numbering=\"%s\"" - (if cont "true" "false")))) - (org-e-odt-format-tags - '("" - . "") lines extra)))) + ;; lines 0 0 num cont rpllbl fmt 'preprocess) FIXME + lines (funcall + (or (and org-export-e-odt-fontify-srcblocks + (or (featurep 'htmlfontify) + ;; htmlfontify.el was introduced in Emacs 23.2 + ;; So load it with some caution + (require 'htmlfontify nil t)) + (fboundp 'htmlfontify-string) + 'org-e-odt-format-source-code-or-example-colored) + 'org-e-odt-format-source-code-or-example-plain) + lines lang caption)) + (let ((num (org-find-text-property-in-string 'org-loc lines))) + (if (not num) lines + (let* ((cont (not (equal num 1))) + (extra (format " text:continue-numbering=\"%s\"" + (if cont "true" "false")))) + (org-e-odt-format-tags + '("" + . "") lines extra))))) (defun org-e-odt-remap-stylenames (style-name) (or @@ -1341,6 +1341,9 @@ ATTR is a string of other attributes of the a element." (defun org-e-odt-format-tags (tag text &rest args) (apply 'org-e-odt-format-tags-1 tag text "\n" "\n" args)) +(defun org-e-odt-format-tags-simple (tag text &rest args) + (apply 'org-e-odt-format-tags-1 tag text nil nil args)) + (defun org-e-odt-init-outfile () (unless (executable-find "zip") ;; Not at all OSes ship with zip by default @@ -3440,7 +3443,7 @@ contextual information." "Transcode a EXAMPLE-BLOCK element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (let* ((options (or (org-element-property :options example-block) "")) - (value (org-export-handle-code example-block info))) + (value (org-export-handle-code example-block info nil nil t))) (org-e-odt--wrap-label example-block (org-e-odt-format-source-code-or-example value nil)))) @@ -3989,8 +3992,11 @@ INFO is a plist holding contextual information. See ;; Coderef: replace link with the reference name or the ;; equivalent line number. ((string= type "coderef") - (format (org-export-get-coderef-format path (or desc "")) - (org-export-resolve-coderef path info))) + (let* ((fmt (org-export-get-coderef-format path (or desc "%s"))) + (res (org-export-resolve-coderef path info)) + (org-e-odt-suppress-xref nil) + (href (org-xml-format-href (concat "#coderef-" path)))) + (format fmt (org-e-odt-format-link res href)))) ;; Link type is handled by a special function. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols)))) (funcall protocol (org-link-unescape path) desc 'html)) @@ -4178,7 +4184,7 @@ holding contextual information." CONTENTS holds the contents of the item. INFO is a plist holding contextual information." (let* ((lang (org-element-property :language src-block)) - (code (org-export-handle-code src-block info)) + (code (org-export-handle-code src-block info nil nil t)) (caption (org-element-property :caption src-block)) (label (org-element-property :name src-block))) ;; FIXME: Handle caption From aa5db9dd65ebb3117a894c5bf170b0c589b4221a Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 2 Mar 2012 15:14:23 +0100 Subject: [PATCH 07/15] test-org: Fix a broken test * testing/lisp/test-org.el (test-org-export/fuzzy-links): Fix the "No link found" error. --- testing/lisp/test-org.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index abf11e869..5edc40178 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -103,13 +103,13 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/" ;; 1. Fuzzy link goes in priority to a matching target. (org-test-with-temp-text "#+TARGET: Test\n#+NAME: Test\n|a|b|\n<>\n* Test\n[[Test]]" - (goto-line 4) + (goto-line 6) (org-open-at-point) (should (looking-at "<>"))) ;; 2. Fuzzy link should then go to a matching target keyword. (org-test-with-temp-text "#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]" - (goto-line 4) + (goto-line 5) (org-open-at-point) (should (looking-at "#\\+TARGET: Test"))) ;; 3. Then fuzzy link points to an element with a given name. From 77e66226f7670f90dc7ddab538997c0c99b15694 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Fri, 2 Mar 2012 20:59:40 +0530 Subject: [PATCH 08/15] org-e-html: Fix a typo --- EXPERIMENTAL/org-e-html.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXPERIMENTAL/org-e-html.el b/EXPERIMENTAL/org-e-html.el index 02ba2ef04..bb5c80d8f 100644 --- a/EXPERIMENTAL/org-e-html.el +++ b/EXPERIMENTAL/org-e-html.el @@ -1859,7 +1859,7 @@ contextual information." (let ((ref (org-find-text-property-in-string 'org-coderef line)) (num (org-find-text-property-in-string 'org-loc line))) (when num - (setq line (format "%d: %s (%s)" + (setq line (format "%d: %s (%s)" num line ref))) (when ref (setq line From e1ac0cb9cd6f1f7c0f7de892d5a720dfad27ff68 Mon Sep 17 00:00:00 2001 From: David Maus Date: Fri, 2 Mar 2012 17:28:17 +0100 Subject: [PATCH 09/15] org-bbdb: Check for BBDB version depending on available functions * org-bbdb.el (org-bbdb-old): Replace `defvar' after loading 'bbdb to check for old or new version by a check for the required function in `org-bbdb-open' and `org-bbdb-store-link'. (org-bbdb-store-link, org-bbdb-open): Check which version of bbdb is to be used. This is a follow up of ddf4f1e7a95608b2223dee7170ecd4a51788def4. Instead of depending on the loading of bbdb we do a check for the required function in `org-bbdb-open' and `org-bbdb-store-link'. --- lisp/org-bbdb.el | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lisp/org-bbdb.el b/lisp/org-bbdb.el index 1162a8dd1..bc5b96f43 100644 --- a/lisp/org-bbdb.el +++ b/lisp/org-bbdb.el @@ -118,10 +118,6 @@ (defvar date) ;; dynamically scoped from Org -;; Support for version 2.35 -(eval-after-load 'bbdb - '(defvar org-bbdb-old (fboundp 'bbdb-record-get-field-internal))) - ;; Customization (defgroup org-bbdb-anniversaries nil @@ -201,7 +197,7 @@ date year)." ;; This is BBDB, we make this link! (let* ((rec (bbdb-current-record)) (name (bbdb-record-name rec)) - (company (if org-bbdb-old + (company (if (fboundp 'bbdb-record-getprop) (bbdb-record-getprop rec 'company) (car (bbdb-record-get-field rec 'organization)))) (link (org-make-link "bbdb:" name))) @@ -222,10 +218,10 @@ italicized, in all other cases it is left unchanged." (defun org-bbdb-open (name) "Follow a BBDB link to NAME." - (require 'bbdb) + (require 'bbdb-com) (let ((inhibit-redisplay (not debug-on-error)) (bbdb-electric-p nil)) - (if org-bbdb-old + (if (fboundp 'bbdb-name) (org-bbdb-open-old) (org-bbdb-open-new)))) From 000afe01abbd3b8b3416a12a91e33f8e9f51b9a1 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Fri, 2 Mar 2012 12:36:48 -0700 Subject: [PATCH 10/15] improve cache documentation when session evaluation is used * doc/org.texi (cache): Improve cache documentation when session evaluation is used. --- doc/org.texi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 316e621f4..61e6707b0 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -13716,8 +13716,11 @@ used. The @code{:cache} header argument controls the use of in-buffer caching of the results of evaluating code blocks. It can be used to avoid re-evaluating -unchanged code blocks. This header argument can have one of two -values: @code{yes} or @code{no}. +unchanged code blocks. Note that the @code{:cache} header argument will not +attempt to cache results when the @code{:session} header argument is used, +because the results of the code block execution may be stored in the session +outside of the Org-mode buffer. The @code{:cache} header argument can have +one of two values: @code{yes} or @code{no}. @itemize @bullet @item @code{no} From 6b91eb9e657ab0a91c2df6d0081b302af20f083a Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 2 Mar 2012 22:37:12 +0100 Subject: [PATCH 11/15] org-footnote: Fix normalization of inline footnotes with no footnote section * lisp/org-footnote.el (org-footnote-normalize): Fix normalization of inline footnotes with no footnote section. * testing/lisp/test-org-footnote.el: New test file. Thanks to Samuel Wales for reporting this. --- lisp/org-footnote.el | 42 ++--- testing/lisp/test-org-footnote.el | 260 ++++++++++++++++++++++++++++++ 2 files changed, 283 insertions(+), 19 deletions(-) create mode 100644 testing/lisp/test-org-footnote.el diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 25376f586..71c010148 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -676,8 +676,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': ;; If EXPORT-PROPS isn't nil, also add `org-footnote' ;; property to it, so it can be easily recognized by ;; exporters. - (if sort-only - (goto-char (nth 2 ref)) + (if sort-only (goto-char (nth 2 ref)) (delete-region (nth 1 ref) (nth 2 ref)) (goto-char (nth 1 ref)) (let ((new-ref (format "[%d]" marker))) @@ -706,7 +705,10 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': '(:todo-keywords t :tags t :priority t)))) (org-export-preprocess-string def parameters)) def) - inlinep pos) ref-table))))) + ;; Reference beginning position is a marker + ;; to preserve it during further buffer + ;; modifications. + inlinep (copy-marker pos)) ref-table))))) ;; 2. Find and remove the footnote section, if any. Also ;; determine where footnotes shall be inserted (INS-POINT). (cond @@ -722,10 +724,9 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': (skip-chars-backward " \r\t\n") (forward-line) (unless (bolp) (newline))) - ;; No footnote section set: Footnotes will be added before next - ;; headline. - ((eq major-mode 'org-mode) - (org-with-limited-levels (outline-next-heading))) + ;; No footnote section set: Footnotes will be added at the end + ;; of the section containing their first reference. + ((eq major-mode 'org-mode)) (t ;; Remove any left-over tag in the buffer, if one is set up. (when org-footnote-tag-for-non-org-mode-files @@ -758,18 +759,21 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': (lambda (x) (cond ;; When only sorting, ignore inline footnotes. - ((and sort-only (nth 3 x)) nil) + ;; Also clear position marker. + ((and sort-only (nth 3 x)) + (set-marker (nth 4 x) nil) nil) ;; No definition available: provide one. ((not (nth 2 x)) - (append (butlast x 2) - (list (format "DEFINITION NOT FOUND: %s" (car x)) - (nth 3 x)))) + (append + (list (car x) (nth 1 x) + (format "DEFINITION NOT FOUND: %s" (car x))) + (nthcdr 3 x))) (t x))) ref-table))) (setq ref-table (nreverse ref-table)) ;; 4. Remove left-over definitions in the buffer. - (mapc (lambda (x) (unless (nth 3 x) - (org-footnote-delete-definitions (car x)))) + (mapc (lambda (x) + (unless (nth 3 x) (org-footnote-delete-definitions (car x)))) ref-table) ;; 5. Insert the footnotes again in the buffer, at the ;; appropriate spot. @@ -791,11 +795,6 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': (skip-chars-backward " \t\n\r") (delete-region (point) ins-point) (unless (bolp) (newline)) - ;; Keep one blank line between footnotes and signature. - (when (and (derived-mode-p 'message-mode) - (save-excursion - (re-search-forward message-signature-separator nil t))) - (open-line 1)) (when org-footnote-tag-for-non-org-mode-files (insert "\n" org-footnote-tag-for-non-org-mode-files "\n"))) ((and org-footnote-section (not export-props)) @@ -808,6 +807,8 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': (insert (mapconcat (lambda (x) + ;; Clean markers. + (set-marker (nth 4 x) nil) (format "\n[%s] %s" (nth (if sort-only 0 1) x) (nth 2 x))) ref-table "\n")) (unless (eobp) (insert "\n\n")) @@ -819,7 +820,10 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': ((not sort-only) (mapc (lambda (x) - (goto-char (nth 4 x)) + (let ((pos (nth 4 x))) + (goto-char pos) + ;; Clean marker. + (set-marker pos nil)) (org-footnote-goto-local-insertion-point) (insert (format "\n[%s] %s\n" (nth 1 x) (nth 2 x)))) ref-table)) diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el new file mode 100644 index 000000000..52e553808 --- /dev/null +++ b/testing/lisp/test-org-footnote.el @@ -0,0 +1,260 @@ +;;; test-org-footnote.el --- Tests for org-footnote.el + +;; Copyright (C) 2012 Nicolas Goaziou + +;; Author: Nicolas Goaziou + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(ert-deftest test-org-footnote/normalize-in-org () + "Test specifications for `org-footnote-normalize' in an Org buffer." + ;; 1. With a non-nil `org-footnote-section'. + (let ((org-footnote-section "Footnotes") + (org-blank-before-new-entry '((heading . auto)))) + ;; 1.1. Normalize each type of footnote: standard, labelled, + ;; numbered, inline, anonymous. + (org-test-with-temp-text + "Paragraph[fn:1][fn:label][1][fn:inline:Inline][fn::Anonymous] + +* Footnotes + +\[fn:1] Standard + +\[fn:label] Labelled + +\[1] Numbered" + (org-footnote-normalize) + (should + (equal (buffer-string) + "Paragraph[1][2][3][4][5] + +* Footnotes + +\[1] Standard + +\[2] Labelled + +\[3] Numbered + +\[4] Inline + +\[5] Anonymous + + +"))) + ;; 1.2. When no footnote section is present, create it. Follow + ;; `org-blank-before-new-entry' specifications when doing so. + (org-test-with-temp-text "Paragraph[fn:1]\n\n[fn:1] Definition" + (org-footnote-normalize) + (should (equal (buffer-string) + "Paragraph[1]\n\n* Footnotes\n\n[1] Definition"))) + (org-test-with-temp-text "Paragraph[fn:1]\n* Head1\n[fn:1] Definition" + (let ((org-blank-before-new-entry '((heading)))) + (org-footnote-normalize)) + (should (equal (buffer-string) + "Paragraph[1]\n* Head1\n* Footnotes\n\n[1] Definition"))) + ;; 1.3. When the footnote section is misplaced, move it at the end + ;; of the buffer. + (org-test-with-temp-text "* Head1 +Body[fn:1] +* Footnotes +\[fn:1] Definition 1 +* Head2" + (org-footnote-normalize) + (should + (equal (buffer-string) + "* Head1 +Body[1] +* Head2 + +* Footnotes + +\[1] Definition 1")))) + ;; 2. With a nil `org-footnote-section'. + (let ((org-footnote-section nil)) + ;; 2.1. Normalize each type of footnote: standard, labelled, + ;; numbered, inline, anonymous. + (org-test-with-temp-text + "Paragraph[fn:1][fn:label][1][fn:inline:Inline][fn::Anonymous] + +\[fn:1] Standard + +\[fn:label] Labelled + +\[1] Numbered" + (org-footnote-normalize) + (should + (equal (buffer-string) + "Paragraph[1][2][3][4][5] + +\[1] Standard + +\[2] Labelled + +\[3] Numbered + +\[4] Inline + +\[5] Anonymous + +"))) + ;; 2.2. Put each footnote definition at the end of the section + ;; containing its first reference. + (org-test-with-temp-text + "* Head 1 +Text[fn:1:Def1] +* Head 2 +Text[fn:1] +* Head 3 +Text[fn:2:Def2]" + (org-footnote-normalize) + (should + (equal (buffer-string) + "* Head 1 +Text[1] + +\[1] Def1 +* Head 2 +Text[1] +* Head 3 +Text[2] + +\[2] Def2 +"))))) + +(ert-deftest test-org-footnote/normalize-outside-org () + "Test `org-footnote-normalize' specifications for buffers not in Org mode." + ;; 1. In a non-Org buffer, footnotes definitions are always put at + ;; its end. + (let ((org-footnote-tag-for-non-org-mode-files nil)) + (with-temp-buffer + (insert "Paragraph[fn:1][fn:label][1][fn:inline:Inline][fn::Anonymous] + +\[fn:1] Standard + +\[fn:label] Labelled + +\[1] Numbered + +Some additional text.") + (org-footnote-normalize) + (should + (equal (buffer-string) + "Paragraph[1][2][3][4][5] + +Some additional text. + +\[1] Standard + +\[2] Labelled + +\[3] Numbered + +\[4] Inline + +\[5] Anonymous")))) + ;; 2. With a special tag. + (let ((org-footnote-tag-for-non-org-mode-files "Footnotes:")) + ;; 2.1. The tag must be inserted before the footnotes, separated + ;; from the rest of the text with a blank line. + (with-temp-buffer + (insert "Paragraph[fn:1][fn::Anonymous] + +\[fn:1] Standard + +Some additional text.") + (org-footnote-normalize) + (should + (equal (buffer-string) + "Paragraph[1][2] + +Some additional text. + +Footnotes: + +\[1] Standard + +\[2] Anonymous"))) + ;; 2.2. Any tag already inserted in the buffer should be removed + ;; prior to footnotes insertion. + (with-temp-buffer + (insert "Text[fn:1] +Footnotes: + +Additional text. + +Footnotes: + +\[fn:1] Definition") + (org-footnote-normalize) + (should + (equal (buffer-string) + "Text[1] + +Additional text. + +Footnotes: + +\[1] Definition")))) + ;; 3. As an exception, in `message-mode' buffer, if a signature is + ;; present, insert footnotes before it. + (let ((org-footnote-tag-for-non-org-mode-files nil) + (message-signature-separator "^-- $")) + (with-temp-buffer + (insert "Body[fn::def] +-- +Fake signature +-- +Signature") + (let ((major-mode 'message-mode)) (org-footnote-normalize)) + (should + (equal (buffer-string) + "Body[1] +-- +Fake signature + +\[1] def + +-- +Signature"))))) + +(ert-deftest test-org-footnote/sort () + "Test footnotes definitions sorting." + (let ((org-footnote-section nil)) + (org-test-with-temp-text + "Text[fn:1][fn::inline][fn:2][fn:label] + +\[fn:label] C + +\[fn:1] A + +\[fn:2] B" + (org-footnote-normalize 'sort) + (should + (equal (buffer-string) + "Text[fn:1][fn::inline][fn:2][fn:label] + +\[fn:1] A + +\[fn:2] B + +\[fn:label] C + +"))))) + + +(provide 'test-org-footnote) +;;; test-org-footnote.el ends here From c8020dd42e8b7d8d433948bacd1ac2b03fed2dc2 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 3 Mar 2012 13:00:46 +0100 Subject: [PATCH 12/15] org-footnote: Clean-up `org-footnote-normalize' * lisp/org-footnote.el (org-footnote-normalize): Remove an useless part of the function. (org-insert-footnote-reference-near-definition): Remove function. --- lisp/org-footnote.el | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 71c010148..9325d1767 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -817,7 +817,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': (when export-props (setq org-export-footnotes-seen ref-table))) ;; Each footnote definition has to be inserted at the end of ;; the section where its first reference belongs. - ((not sort-only) + (t (mapc (lambda (x) (let ((pos (nth 4 x))) @@ -826,24 +826,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': (set-marker pos nil)) (org-footnote-goto-local-insertion-point) (insert (format "\n[%s] %s\n" (nth 1 x) (nth 2 x)))) - ref-table)) - ;; Else, insert each definition at the end of the section - ;; containing their first reference. Happens only in Org files - ;; with no special footnote section, and only when doing - ;; sorting. - (t (mapc 'org-insert-footnote-reference-near-definition - ref-table)))))) - -(defun org-insert-footnote-reference-near-definition (entry) - "Find first reference of footnote ENTRY and insert the definition there. -ENTRY is (fn-label num-mark definition)." - (when (car entry) - (goto-char (point-min)) - (let ((ref (org-footnote-get-next-reference (car entry)))) - (when ref - (goto-char (nth 2 ref)) - (org-footnote-goto-local-insertion-point) - (insert (format "\n[%s] %s\n" (car entry) (nth 2 entry))))))) + ref-table)))))) (defun org-footnote-goto-local-insertion-point () "Find insertion point for footnote, just before next outline heading." From 155ab73f7767afbf45cf67566d7808dd6684797b Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 3 Mar 2012 13:07:59 +0100 Subject: [PATCH 13/15] org-footnote: Small fix to previous commit * lisp/org-footnote.el (org-footnote-normalize): Do not normalize labels when sort-only is non-nil. --- lisp/org-footnote.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 9325d1767..2433d88cc 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -825,7 +825,9 @@ Additional note on `org-footnote-insert-pos-for-preprocessor': ;; Clean marker. (set-marker pos nil)) (org-footnote-goto-local-insertion-point) - (insert (format "\n[%s] %s\n" (nth 1 x) (nth 2 x)))) + (insert (format "\n[%s] %s\n" + (if sort-only (car x) (nth 1 x)) + (nth 2 x)))) ref-table)))))) (defun org-footnote-goto-local-insertion-point () From 9915dc89056045839e87cc4149f39646a7796c47 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sat, 3 Mar 2012 07:35:12 -0700 Subject: [PATCH 14/15] fix code block replacement with results * lisp/ob.el (org-babel-find-named-result): Fix code block replacement with results. --- lisp/ob.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/ob.el b/lisp/ob.el index 38ae553bf..d4e8de89b 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1536,7 +1536,8 @@ buffer or nil if no such result exists." (concat org-babel-result-regexp "[ \t]" (regexp-quote name) "[ \t\n\f\v\r]+") nil t) (when (and (string= "name" (downcase (match-string 1))) - (or (looking-at org-babel-src-block-regexp) + (or (beginning-of-line 1) + (looking-at org-babel-src-block-regexp) (looking-at org-babel-multi-line-header-regexp))) (throw 'is-a-code-block (org-babel-find-named-result name (point)))) (beginning-of-line 0) (point))))) From 6fd14fe6832184dc6976ea91a5ca01551d53fb8c Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sat, 3 Mar 2012 07:43:49 -0700 Subject: [PATCH 15/15] adding a test to protect the "results don't replace code block" functionality --- testing/lisp/test-ob.el | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 6581d69ce..b01e4b2ba 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -1032,6 +1032,36 @@ Line 3\" * next heading")) +(ert-deftest test-ob/results-do-not-replace-code-blocks () + (org-test-with-temp-text "Block two has a space after the name. + + #+name: foo + #+begin_src emacs-lisp + 1 + #+end_src emacs-lisp + +#+name: foo +#+begin_src emacs-lisp + 2 +#+end_src + +#+name: foo +#+begin_src emacs-lisp + 3 +#+end_src + +#+RESULTS: foo +: foo +" + (dolist (num '(1 2 3)) + ;; execute the block + (goto-char (point-min)) + (org-babel-next-src-block num) (org-babel-execute-src-block) + ;; check the results + (goto-char (point-max)) + (move-beginning-of-line 0) + (should (looking-at (format ": %d" num)))))) + (provide 'test-ob) ;;; test-ob ends here