Browse Source

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

Bastien 2 years ago
parent
commit
67ee27cec2
7 changed files with 169 additions and 169 deletions
  1. 6 6
      doc/org-manual.org
  2. 16 18
      lisp/org-capture.el
  3. 71 27
      lisp/org-colview.el
  4. 34 34
      lisp/org-protocol.el
  5. 3 2
      lisp/org.el
  6. 17 61
      lisp/ox-latex.el
  7. 22 21
      testing/lisp/test-org-capture.el

+ 6 - 6
doc/org-manual.org

@@ -3252,7 +3252,7 @@ current buffer:
      If the headline has a =CUSTOM_ID= property, store a link to this
      custom ID.  In addition or alternatively, depending on the value
      of ~org-link-to-org-use-id~, create and/or use a globally unique
-     ID property for the link[fn:30].  So using this command in Org
+     =ID= property for the link[fn:30].  So using this command in Org
      buffers potentially creates two links: a human-readable link from
      the custom ID, and one that is globally unique and works even if
      the entry is moved from file to file.  Later, when inserting the
@@ -7099,7 +7099,7 @@ You can also jump to the bookmark ~org-capture-last-stored~, which is
 automatically created unless you set ~org-capture-bookmark~ to ~nil~.
 
 To insert the capture at point in an Org buffer, call ~org-capture~
-with a ~C-0~ prefix argument.
+with a {{{kbd(C-0)}}} prefix argument.
 
 *** Capture templates
 :PROPERTIES:
@@ -7142,7 +7142,7 @@ the template for you like this:
 #+end_example
 
 #+texinfo: @noindent
-During expansion of the template, ~%a~ has been replaced by a link to
+During expansion of the template, =%a= has been replaced by a link to
 the location from where you called the capture command.  This can be
 extremely useful for deriving tasks from emails, for example.  You
 fill in the task definition, press {{{kbd(C-c C-c)}}} and Org returns
@@ -7996,7 +7996,7 @@ special command:
      #+vindex: org-refile-keep
      Refile and keep the entry in place.  Also see ~org-refile-keep~
      to make this the default behavior, and beware that this may
-     result in duplicated ~ID~ properties.
+     result in duplicated =ID= properties.
 
 - {{{kbd(C-0 C-c C-w)}}} or {{{kbd(C-u C-u C-u C-c C-w)}}} (~org-refile-cache-clear~) ::
 
@@ -21480,8 +21480,8 @@ the docstring of that variable.
 [fn:150] Symbolic links in ~org-directory~ need to have the same name
 as their targets.
 
-[fn:151] While creating the agendas, Org mode forces ID properties on
-all referenced entries, so that these entries can be uniquely
+[fn:151] While creating the agendas, Org mode forces =ID= properties
+on all referenced entries, so that these entries can be uniquely
 identified if Org Mobile flags them for further action.  To avoid
 setting properties configure the variable
 ~org-mobile-force-id-on-agenda-items~ to ~nil~.  Org mode then relies

+ 16 - 18
lisp/org-capture.el

@@ -662,7 +662,7 @@ of the day at point (if any) or the current HH:MM time."
 	    (org-capture-put :template (org-capture-fill-template))
 	  ((error quit)
 	   (if (get-buffer "*Capture*") (kill-buffer "*Capture*"))
-	   (error "Capture abort: %s" error)))
+	   (error "Capture abort: %s" (error-message-string error))))
 
 	(setq org-capture-clock-keep (org-capture-get :clock-keep))
 	(if (equal goto 0)
@@ -672,26 +672,24 @@ of the day at point (if any) or the current HH:MM time."
 	      (org-capture-place-template
 	       (eq (car (org-capture-get :target)) 'function))
 	    ((error quit)
-	     (if (and (buffer-base-buffer (current-buffer))
-		      (string-prefix-p "CAPTURE-" (buffer-name)))
-		 (kill-buffer (current-buffer)))
+	     (when (and (buffer-base-buffer (current-buffer))
+			(string-prefix-p "CAPTURE-" (buffer-name)))
+	       (kill-buffer (current-buffer)))
 	     (set-window-configuration (org-capture-get :return-to-wconf))
 	     (error "Capture template `%s': %s"
 		    (org-capture-get :key)
-		    (nth 1 error))))
-	  (if (and (derived-mode-p 'org-mode)
-		   (org-capture-get :clock-in))
-	      (condition-case nil
-		  (progn
-		    (if (org-clock-is-active)
-			(org-capture-put :interrupted-clock
-					 (copy-marker org-clock-marker)))
-		    (org-clock-in)
-		    (setq-local org-capture-clock-was-started t))
-		(error
-		 "Could not start the clock in this capture buffer")))
-	  (if (org-capture-get :immediate-finish)
-	      (org-capture-finalize)))))))))
+		    (error-message-string error))))
+	  (when (and (derived-mode-p 'org-mode) (org-capture-get :clock-in))
+	    (condition-case nil
+		(progn
+		  (when (org-clock-is-active)
+		    (org-capture-put :interrupted-clock
+				     (copy-marker org-clock-marker)))
+		  (org-clock-in)
+		  (setq-local org-capture-clock-was-started t))
+	      (error "Could not start the clock in this capture buffer")))
+	  (when (org-capture-get :immediate-finish)
+	    (org-capture-finalize)))))))))
 
 (defun org-capture-get-template ()
   "Get the template from a file or a function if necessary."

+ 71 - 27
lisp/org-colview.el

@@ -233,21 +233,27 @@ See `org-columns-summary-types' for details.")
     "--"
     ["Quit" org-columns-quit t]))
 
-(defun org-columns--displayed-value (spec value)
+(defun org-columns--displayed-value (spec value &optional no-star)
   "Return displayed value for specification SPEC in current entry.
+
 SPEC is a column format specification as stored in
 `org-columns-current-fmt-compiled'.  VALUE is the real value to
-display, as a string."
+display, as a string.
+
+When NO-STAR is non-nil, do not add asterisks before displayed
+value for ITEM property."
   (or (and (functionp org-columns-modify-value-for-display-function)
 	   (funcall org-columns-modify-value-for-display-function
 		    (nth 1 spec)	;column name
 		    value))
       (pcase spec
 	(`("ITEM" . ,_)
-	 (concat (make-string (1- (org-current-level))
-			      (if org-hide-leading-stars ?\s ?*))
-		 "* "
-		 (org-columns-compact-links value)))
+	 (let ((stars
+		(and (not no-star)
+		     (concat (make-string (1- (org-current-level))
+					  (if org-hide-leading-stars ?\s ?*))
+			     "* "))))
+	   (concat stars (org-columns-compact-links value))))
 	(`(,_ ,_ ,_ ,_ nil) value)
 	;; If PRINTF is set, assume we are displaying a number and
 	;; obey to the format string.
@@ -280,7 +286,11 @@ possible to override it with optional argument COMPILED-FMT."
 					  (get-text-property (point) 'duration))
 					 'face 'org-warning))
 			"")))
-	    (list spec v (org-columns--displayed-value spec v))))))
+	    ;; A non-nil COMPILED-FMT means we're calling from Org
+	    ;; Agenda mode, where we do not want leading stars for
+	    ;; ITEM.  Hence the optional argument for
+	    ;; `org-columns--displayed-value'.
+	    (list spec v (org-columns--displayed-value spec v compiled-fmt))))))
      (or compiled-fmt org-columns-current-fmt-compiled))))
 
 (defun org-columns--set-widths (cache)
@@ -331,7 +341,11 @@ Return nil if no collect function is associated to OPERATOR."
     (_ (error "Invalid definition for operator %S" operator))))
 
 (defun org-columns--overlay-text (value fmt width property original)
-  "Return text "
+  "Return decorated VALUE string for columns overlay display.
+FMT is a format string.  WIDTH is the width of the column, as an
+integer.  PROPERTY is the property being displayed, as a string.
+ORIGINAL is the real string, i.e., before it is modified by
+`org-columns--displayed-value'."
   (format fmt
           (let ((v (org-columns-add-ellipses value width)))
             (pcase property
@@ -1289,17 +1303,17 @@ When PRINTF is non-nil, use it to format the result."
    times))
 
 (defun org-columns--summary-min-age (ages _)
-  "Compute the minimum time among AGES."
+  "Compute the minimum age among AGES."
   (org-columns--format-age
    (apply #'min (mapcar #'org-columns--age-to-minutes ages))))
 
 (defun org-columns--summary-max-age (ages _)
-  "Compute the maximum time among AGES."
+  "Compute the maximum age among AGES."
   (org-columns--format-age
    (apply #'max (mapcar #'org-columns--age-to-minutes ages))))
 
 (defun org-columns--summary-mean-age (ages _)
-  "Compute the minimum time among AGES."
+  "Compute the mean age among AGES."
   (org-columns--format-age
    (/ (apply #'+ (mapcar #'org-columns--age-to-minutes ages))
       (float (length ages)))))
@@ -1386,24 +1400,54 @@ an inline src-block."
 ;;;###autoload
 (defun org-dblock-write:columnview (params)
   "Write the column view table.
+
 PARAMS is a property list of parameters:
 
-:id       the :ID: property of the entry where the columns view
-	  should be built.  When the symbol `local', call locally.
-	  When `global' call column view with the cursor at the beginning
-	  of the buffer (usually this means that the whole buffer switches
-	  to column view).  When \"file:path/to/file.org\", invoke column
-	  view at the start of that file.  Otherwise, the ID is located
-	  using `org-id-find'.
-:hlines   When t, insert a hline before each item.  When a number, insert
-	  a hline before each level <= that number.
-:indent   When non-nil, indent each ITEM field according to its level.
-:vlines   When t, make each column a colgroup to enforce vertical lines.
-:maxlevel When set to a number, don't capture headlines below this level.
-:match    When set to a string, use this as a tags/property match filter.
-:skip-empty-rows
-	  When t, skip rows where all specifiers other than ITEM are empty.
-:format   When non-nil, specify the column view format to use."
+`:id' (mandatory)
+
+    The ID property of the entry where the columns view should be
+    built.  When the symbol `local', call locally.  When `global'
+    call column view with the cursor at the beginning of the
+    buffer (usually this means that the whole buffer switches to
+    column view).  When \"file:path/to/file.org\", invoke column
+    view at the start of that file.  Otherwise, the ID is located
+    using `org-id-find'.
+
+`:exclude-tags'
+
+    List of tags to exclude from column view table.
+
+`:format'
+
+    When non-nil, specify the column view format to use.
+
+`:hlines'
+
+    When non-nil, insert a hline before each item.  When
+    a number, insert a hline before each level inferior or equal
+    to that number.
+
+`:indent'
+
+    When non-nil, indent each ITEM field according to its level.
+
+`:match'
+
+    When set to a string, use this as a tags/property match filter.
+
+`:maxlevel'
+
+    When set to a number, don't capture headlines below this level.
+
+`:skip-empty-rows'
+
+    When non-nil, skip rows where all specifiers other than ITEM
+    are empty.
+
+`:vlines'
+
+    When non-nil, make each column a column group to enforce
+    vertical lines."
   (let ((table
 	 (let ((id (plist-get params :id))
 	       view-file view-pos)

+ 34 - 34
lisp/org-protocol.el

@@ -122,6 +122,7 @@
 (declare-function server-edit "server" (&optional arg))
 
 (defvar org-capture-link-is-already-stored)
+(defvar org-capture-templates)
 
 (defgroup org-protocol nil
   "Intercept calls from emacsclient to trigger custom actions.
@@ -468,43 +469,33 @@ You may specify the template with a template= query parameter, like this:
   javascript:location.href = \\='org-protocol://capture?template=b\\='+ ...
 
 Now template ?b will be used."
-  (when (and (boundp 'org-stored-links)
-	     (org-protocol-do-capture info))
-    (message "Item captured."))
-  nil)
-
-(defun org-protocol-convert-query-to-plist (query)
-  "Convert QUERY key=value pairs in the URL to a property list."
-  (when query
-    (apply 'append (mapcar (lambda (x)
-			     (let ((c (split-string x "=")))
-			       (list (intern (concat ":" (car c))) (cadr c))))
-			   (split-string query "&")))))
-
-(defvar org-capture-templates)
-(defun org-protocol-do-capture (info)
-  "Perform the actual capture based on INFO."
-  (let* ((temp-parts (org-protocol-parse-parameters info))
-	 (parts
-	  (cond
-	   ((and (listp info) (symbolp (car info))) info)
-	   ((= (length (car temp-parts)) 1) ;; First parameter is exactly one character long
-	    (org-protocol-assign-parameters temp-parts '(:template :url :title :body)))
-	   (t
-	    (org-protocol-assign-parameters temp-parts '(:url :title :body)))))
+  (let* ((parts
+	  (pcase (org-protocol-parse-parameters info)
+	    ;; New style links are parsed as a plist.
+	    ((let `(,(pred keywordp) . ,_) info) info)
+	    ;; Old style links, with or without template key, are
+	    ;; parsed as a list of strings.
+	    (p
+	     (let ((k (if (= 1 (length (car p)))
+			  '(:template :url :title :body)
+			'(:url :title :body))))
+	       (org-protocol-assign-parameters p k)))))
 	 (template (or (plist-get parts :template)
 		       org-protocol-default-template-key))
-	 (url (and (plist-get parts :url) (org-protocol-sanitize-uri (plist-get parts :url))))
-	 (type (and url (string-match "^\\([a-z]+\\):" url) (match-string 1 url)))
+	 (url (and (plist-get parts :url)
+		   (org-protocol-sanitize-uri (plist-get parts :url))))
+	 (type (and url
+		    (string-match "^\\([a-z]+\\):" url)
+		    (match-string 1 url)))
 	 (title (or (plist-get parts :title) ""))
 	 (region (or (plist-get parts :body) ""))
-	 (orglink (if url
-		      (org-make-link-string
-		       url (if (string-match "[^[:space:]]" title) title url))
-		    title))
-	 (org-capture-link-is-already-stored t)) ;; avoid call to org-store-link
-    (setq org-stored-links
-	  (cons (list url title) org-stored-links))
+	 (orglink
+	  (if (null url) title
+	    (org-make-link-string url (or (org-string-nw-p title) url))))
+	 ;; Avoid call to `org-store-link'.
+	 (org-capture-link-is-already-stored t))
+    ;; Only store link if there's a URL to insert later on.
+    (when url (push (list url title) org-stored-links))
     (org-store-link-props :type type
 			  :link url
 			  :description title
@@ -512,7 +503,16 @@ Now template ?b will be used."
 			  :initial region
 			  :query parts)
     (raise-frame)
-    (funcall 'org-capture nil template)))
+    (org-capture nil template))
+  (message "Item captured."))
+
+(defun org-protocol-convert-query-to-plist (query)
+  "Convert QUERY key=value pairs in the URL to a property list."
+  (when query
+    (apply 'append (mapcar (lambda (x)
+			     (let ((c (split-string x "=")))
+			       (list (intern (concat ":" (car c))) (cadr c))))
+			   (split-string query "&")))))
 
 (defun org-protocol-open-source (fname)
   "Process an org-protocol://open-source?url= style URL with FNAME.

+ 3 - 2
lisp/org.el

@@ -9178,10 +9178,11 @@ sub-tree if optional argument INHERIT is non-nil."
 
 (defun org-store-link-functions ()
   "Return a list of functions that are called to create and store a link.
-The functions defined in the :store property of
+
+The functions are defined in the `:store' property of
 `org-link-parameters'.
 
-Each function will be called in turn until one returns a non-nil
+Each function is called in turn until one returns a non-nil
 value.  Each function should check if it is responsible for
 creating this link (for example by looking at the major mode).
 If not, it must exit and return nil.  If yes, it should return

+ 17 - 61
lisp/ox-latex.el

@@ -2768,24 +2768,21 @@ channel."
 DATA is a parse tree or a secondary string.  INFO is a plist
 containing export options.  Modify DATA by side-effect and return it."
   (let ((valid-object-p
-	 ;; Non-nil when OBJ can be added to the latex math block B.
-	 (lambda (obj b)
-	   (pcase (org-element-type obj)
-	     (`entity (org-element-property :latex-math-p obj))
+	 ;; Non-nil when OBJECT can be added to a latex math block.
+	 (lambda (object)
+	   (pcase (org-element-type object)
+	     (`entity (org-element-property :latex-math-p object))
 	     (`latex-fragment
-	      (let ((value (org-element-property :value obj)))
+	      (let ((value (org-element-property :value object)))
 		(or (string-prefix-p "\\(" value)
-		    (string-match-p "\\`\\$[^$]" value))))
-	     ((and type (or `subscript `superscript))
-	      (not (memq type (mapcar #'org-element-type
-				      (org-element-contents b)))))))))
-    (org-element-map data '(entity latex-fragment subscript superscript)
+		    (string-match-p "\\`\\$[^$]" value))))))))
+    (org-element-map data '(entity latex-fragment)
       (lambda (object)
 	;; Skip objects already wrapped.
 	(when (and (not (eq (org-element-type
 			     (org-element-property :parent object))
 			    'latex-math-block))
-		   (funcall valid-object-p object nil))
+		   (funcall valid-object-p object))
 	  (let ((math-block (list 'latex-math-block nil))
 		(next-elements (org-export-get-next-element object info t))
 		(last object))
@@ -2797,20 +2794,17 @@ containing export options.  Modify DATA by side-effect and return it."
 	      ;; MATH-BLOCK swallows consecutive math objects.
 	      (catch 'exit
 		(dolist (next next-elements)
-		  (unless (funcall valid-object-p next math-block)
-		    (throw 'exit nil))
+		  (unless (funcall valid-object-p next) (throw 'exit nil))
 		  (org-element-extract-element next)
 		  (org-element-adopt-elements math-block next)
 		  ;; Eschew the case: \beta$x$ -> \(\betax\).
-		  (unless (memq (org-element-type next)
-				'(subscript superscript))
-		    (org-element-put-property last :post-blank 1))
+		  (org-element-put-property last :post-blank 1)
 		  (setq last next)
 		  (when (> (or (org-element-property :post-blank next) 0) 0)
 		    (throw 'exit nil)))))
 	    (org-element-put-property
 	     math-block :post-blank (org-element-property :post-blank last)))))
-      info nil '(subscript superscript latex-math-block) t)
+      info nil '(latex-math-block) t)
     ;; Return updated DATA.
     data))
 
@@ -3065,56 +3059,18 @@ holding contextual information."
 
 ;;;; Subscript
 
-(defun org-latex--script-size (object info)
-  "Transcode a subscript or superscript object.
-OBJECT is an Org object.  INFO is a plist used as a communication
-channel."
-  (let ((output ""))
-    (org-element-map (org-element-contents object)
-	(cons 'plain-text org-element-all-objects)
-      (lambda (obj)
-	(cl-case (org-element-type obj)
-	  ((entity latex-fragment)
-	   (let ((data (org-trim (org-export-data obj info))))
-	     (string-match
-	      "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
-	      data)
-	     (setq output
-		   (concat output
-			   (match-string 1 data)
-			   (let ((blank (org-element-property :post-blank obj)))
-			     (and blank (> blank 0) "\\ "))))))
-	  (plain-text
-	   (setq output
-		 (format "%s\\text{%s}" output (org-export-data obj info))))
-	  (otherwise
-	   (setq output
-		 (concat output
-			 (org-export-data obj info)
-			 (let ((blank (org-element-property :post-blank obj)))
-			   (and blank (> blank 0) "\\ ")))))))
-      info nil org-element-recursive-objects)
-    ;; Result.  Do not wrap into curly brackets if OUTPUT is a single
-    ;; character.
-    (concat (if (eq (org-element-type object) 'subscript) "_" "^")
-	    (and (> (length output) 1) "{")
-	    output
-	    (and (> (length output) 1) "}"))))
-
-(defun org-latex-subscript (subscript _contents info)
+(defun org-latex-subscript (_subscript contents _info)
   "Transcode a SUBSCRIPT object from Org to LaTeX.
-CONTENTS is the contents of the object.  INFO is a plist holding
-contextual information."
-  (org-latex--script-size subscript info))
+CONTENTS is the contents of the object."
+  (format "\\textsubscript{%s}" contents))
 
 
 ;;;; Superscript
 
-(defun org-latex-superscript (superscript _contents info)
+(defun org-latex-superscript (_superscript contents _info)
   "Transcode a SUPERSCRIPT object from Org to LaTeX.
-CONTENTS is the contents of the object.  INFO is a plist holding
-contextual information."
-  (org-latex--script-size superscript info))
+CONTENTS is the contents of the object."
+  (format "\\textsuperscript{%s}" contents))
 
 
 ;;;; Table

+ 22 - 21
testing/lisp/test-org-capture.el

@@ -167,7 +167,7 @@
 	(org-capture-kill))
       (buffer-string))))
   (should
-   (equal "- A\n  - B"
+   (equal "- A\n  - B\n"
 	  (org-test-with-temp-text-in-file "- A\n  - B"
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates
@@ -176,7 +176,7 @@
 	      (org-capture-kill))
 	    (buffer-string))))
   (should
-   (equal "| a |\n| b |"
+   (equal "| a |\n| b |\n"
 	  (org-test-with-temp-text-in-file "| a |\n| b |"
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates
@@ -230,7 +230,7 @@
   ;; Insert item in the first plain list found at the target location.
   (should
    (equal
-    "* A\n- list 1\n- X\n\n\n1. list 2"
+    "* A\n- list 1\n- X\n\n\n1. list 2\n"
     (org-test-with-temp-text-in-file "* A\n- list 1\n\n\n1. list 2"
       (let* ((file (buffer-file-name))
 	     (org-capture-templates
@@ -240,7 +240,7 @@
       (buffer-string))))
   (should
    (equal
-    "Text\n- list 1\n- X\n\n\n1. list 2"
+    "Text\n- list 1\n- X\n\n\n1. list 2\n"
     (org-test-with-temp-text-in-file "Text\n- list 1\n\n\n1. list 2"
       (let* ((file (buffer-file-name))
 	     (org-capture-templates
@@ -274,7 +274,7 @@
   ;; When `:prepend' is non-nil, insert new item as the first item.
   (should
    (equal
-    "* A\n- X\n- 1\n- 2"
+    "* A\n- X\n- 1\n- 2\n"
     (org-test-with-temp-text-in-file "* A\n- 1\n- 2"
       (let* ((file (buffer-file-name))
 	     (org-capture-templates
@@ -298,7 +298,7 @@
   ;; When targeting a specific location, one can insert in a sub-list.
   (should
    (equal
-    "* A\n- skip\n  - here\n  - X\n- skip"
+    "* A\n- skip\n  - here\n  - X\n- skip\n"
     (org-test-with-temp-text-in-file "* A\n- skip\n  - here\n- skip"
       (let* ((file (buffer-file-name))
 	     (org-capture-templates
@@ -309,7 +309,7 @@
   ;; Obey `:empty-lines' when creating a new list.
   (should
    (equal
-    "\n- X\n\n\n* H"
+    "\n- X\n\n\n* H\n"
     (org-test-with-temp-text-in-file "\n* H"
       (let* ((file (buffer-file-name))
 	     (org-capture-templates
@@ -322,7 +322,7 @@
   ;; only if the value doesn't break the list.
   (should
    (equal
-    "- A\n\n- X\nText"
+    "- A\n\n- X\nText\n"
     (org-test-with-temp-text-in-file "- A\nText"
       (let* ((file (buffer-file-name))
 	     (org-capture-templates
@@ -332,7 +332,7 @@
       (buffer-string))))
   (should
    (equal
-    "Text\n- X\n\n- A"
+    "Text\n- X\n\n- A\n"
     (org-test-with-temp-text-in-file "Text\n- A"
       (let* ((file (buffer-file-name))
 	     (org-capture-templates
@@ -343,7 +343,7 @@
       (buffer-string))))
   (should-not
    (equal
-    "- A\n\n\n- X"
+    "- A\n\n\n- X\n"
     (org-test-with-temp-text-in-file "- A"
       (let* ((file (buffer-file-name))
 	     (org-capture-templates
@@ -354,7 +354,7 @@
   ;; Preserve list type when pre-pending.
   (should
    (equal
-    "1. X\n2. A"
+    "1. X\n2. A\n"
     (org-test-with-temp-text-in-file "1. A"
       (let* ((file (buffer-file-name))
 	     (org-capture-templates
@@ -417,7 +417,8 @@
 | a |
 | x |
 
-| b |"
+| b |
+"
 	  (org-test-with-temp-text-in-file "Text\n\n| a |\n\n| b |"
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates
@@ -483,7 +484,7 @@
 	    (buffer-string))))
   ;; Properly insert row with formulas.
   (should
-   (equal "| 1 |\n| 2 |\n#+TBLFM: "
+   (equal "| 1 |\n| 2 |\n#+TBLFM: \n"
 	  (org-test-with-temp-text-in-file "| 1 |\n#+TBLFM: "
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates
@@ -504,7 +505,7 @@
   ;; When `:prepend' is non-nil, add it as the first row after the
   ;; header, if there is one, or the first row otherwise.
   (should
-   (equal "| a |\n|---|\n| x |\n| b |"
+   (equal "| a |\n|---|\n| x |\n| b |\n"
 	  (org-test-with-temp-text-in-file "| a |\n|---|\n| b |"
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates
@@ -513,7 +514,7 @@
 	      (org-capture nil "t"))
 	    (buffer-string))))
   (should
-   (equal "| x |\n| a |"
+   (equal "| x |\n| a |\n"
 	  (org-test-with-temp-text-in-file "| a |"
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates
@@ -523,7 +524,7 @@
 	    (buffer-string))))
   ;; When `:table-line-pos' is set and is meaningful, obey it.
   (should
-   (equal "| a |\n|---|\n| b |\n| x |\n|---|\n| c |"
+   (equal "| a |\n|---|\n| b |\n| x |\n|---|\n| c |\n"
 	  (org-test-with-temp-text-in-file "| a |\n|---|\n| b |\n|---|\n| c |"
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates
@@ -532,7 +533,7 @@
 	      (org-capture nil "t"))
 	    (buffer-string))))
   (should
-   (equal "| a |\n|---|\n| x |\n| b |\n|---|\n| c |"
+   (equal "| a |\n|---|\n| x |\n| b |\n|---|\n| c |\n"
 	  (org-test-with-temp-text-in-file "| a |\n|---|\n| b |\n|---|\n| c |"
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates
@@ -595,7 +596,7 @@
 	      (org-capture nil "t")
 	      (buffer-string)))))
   (should
-   (equal "Foo\nSome text."
+   (equal "Foo\nSome text.\n"
 	  (org-test-with-temp-text-in-file "Some text."
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates
@@ -607,7 +608,7 @@
   ;; entry, past any meta-data, or at its end, depending on
   ;; `:prepend'.
   (should
-   (equal "* A\nSCHEDULED: <2012-03-29 Thu>\nSome text.\nFoo\n* B"
+   (equal "* A\nSCHEDULED: <2012-03-29 Thu>\nSome text.\nFoo\n* B\n"
 	  (org-test-with-temp-text-in-file
 	      "* A\nSCHEDULED: <2012-03-29 Thu>\nSome text.\n* B"
 	    (let* ((file (buffer-file-name))
@@ -617,7 +618,7 @@
 	      (org-capture nil "t")
 	      (buffer-string)))))
   (should
-   (equal "* A\nSCHEDULED: <2012-03-29 Thu>\nFoo\nSome text.\n* B"
+   (equal "* A\nSCHEDULED: <2012-03-29 Thu>\nFoo\nSome text.\n* B\n"
 	  (org-test-with-temp-text-in-file
 	      "* A\nSCHEDULED: <2012-03-29 Thu>\nSome text.\n* B"
 	    (let* ((file (buffer-file-name))
@@ -629,7 +630,7 @@
   ;; At an exact position, in the middle of a line, make sure to
   ;; insert text on a line on its own.
   (should
-   (equal "A\nX\nB"
+   (equal "A\nX\nB\n"
 	  (org-test-with-temp-text-in-file "AB"
 	    (let* ((file (buffer-file-name))
 		   (org-capture-templates