فهرست منبع

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

Bastien Guerry 14 سال پیش
والد
کامیت
22f34369fd
11فایلهای تغییر یافته به همراه327 افزوده شده و 223 حذف شده
  1. 5 5
      doc/org.texi
  2. 2 1
      lisp/ob-clojure.el
  3. 4 10
      lisp/ob-exp.el
  4. 41 17
      lisp/ob-ref.el
  5. 42 26
      lisp/ob.el
  6. 6 0
      lisp/org-exp.el
  7. 167 162
      lisp/org-list.el
  8. 35 0
      testing/examples/babel.org
  9. 10 2
      testing/lisp/test-ob-lob.el
  10. 8 0
      testing/lisp/test-ob-tangle.el
  11. 7 0
      testing/lisp/test-ob.el

+ 5 - 5
doc/org.texi

@@ -12393,16 +12393,16 @@ block should be included in tangled extraction of source code files.
 
 @itemize @bullet
 @item @code{tangle}
-The code block is exported to a source code file named after the
-basename (name w/o extension) of the Org-mode file.  E.g., @code{:tangle
-yes}.
+The code block is exported to a source code file named after the full path
+(including the directory) and file name (w/o extension) of the Org-mode file.
+E.g., @code{:tangle yes}.
 @item @code{no}
 The default.  The code block is not exported to a source code file. 
 E.g., @code{:tangle no}.
 @item other
 Any other string passed to the @code{:tangle} header argument is interpreted
-as a file basename to which the block will be exported.  E.g., @code{:tangle
-basename}.
+as a path (directory and file name relative to the directory of the Org-mode
+file) to which the block will be exported.  E.g., @code{:tangle path}.
 @end itemize
 
 @node mkdirp, comments, tangle, Specific header arguments

+ 2 - 1
lisp/ob-clojure.el

@@ -78,7 +78,8 @@
   (require 'slime) (require 'swank-clojure)
   (with-temp-buffer
     (insert (org-babel-expand-body:clojure body params))
-    ((lambda (result) (condition-case nil (read (org-babel-script-escape result))
+    ((lambda (result) (condition-case nil
+		     (read (org-babel-script-escape result 'force))
 		   (error result)))
      (slime-eval
       `(swank:interactive-eval-region

+ 4 - 10
lisp/ob-exp.el

@@ -166,10 +166,11 @@ Example and verbatim code include escaped portions of
 an org-mode buffer code that should be treated as normal
 org-mode text."
   (or (org-in-indented-comment-line) 
-      (save-excursion
-	(save-match-data
+      (save-match-data
+	(save-excursion
 	  (goto-char (point-at-bol))
 	  (looking-at "[ \t]*:[ \t]")))
+      (org-in-verbatim-emphasis)
       (org-in-regexps-block-p "^[ \t]*#\\+begin_src" "^[ \t]*#\\+end_src")))
 
 (defvar org-babel-default-lob-header-args)
@@ -182,14 +183,7 @@ options are taken from `org-babel-default-header-args'."
     (goto-char start)
     (while (and (< (point) end)
 		(re-search-forward org-babel-lob-one-liner-regexp nil t))
-			     ; TODO: move this logic to `org-babel-lob-get-info'
-      (when (or		                        ; either this is:
-	     (not (match-string 12))	        ; not an inline call at all
-	     (let ((prefix (match-string 11)))
-	       (or (string= "" prefix)          ; is at the beginning of a line
-		   (let ((last (substring prefix (- (length prefix) 1))))
-		     (or (string= " " last)     ; or is preceded by whitespace
-			 (string= "\t" last))))))
+      (unless (and (match-string 12) (org-babel-in-example-or-verbatim))
 	(let* ((lob-info (org-babel-lob-get-info))
 	       (inlinep (match-string 11))
 	       (inline-start (match-end 11))

+ 41 - 17
lisp/ob-ref.el

@@ -81,6 +81,25 @@ the variable."
 		    (org-babel-ref-resolve ref))
 		out))))))
 
+(defun org-babel-ref-goto-headline-id (id)
+  (goto-char (point-min))
+  (let ((rx (regexp-quote id)))
+    (or (re-search-forward
+	 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" rx "[ \t]*$") nil t)
+	(condition-case nil (progn (org-id-goto id) t) (error nil)))))
+
+(defun org-babel-ref-headline-body ()
+  (save-restriction
+    (org-narrow-to-subtree)
+    (buffer-substring
+     (save-excursion (goto-char (point-min))
+		     (forward-line 1)
+		     (when (looking-at "[ \t]*:PROPERTIES:")
+		       (re-search-forward ":END:" nil)
+		       (forward-char))
+		     (point))
+     (point-max))))
+
 (defvar org-babel-library-of-babel)
 (defun org-babel-ref-resolve (ref)
   "Resolve the reference REF and return its value."
@@ -88,7 +107,7 @@ the variable."
   (save-excursion
     (let ((case-fold-search t)
           type args new-refere new-header-args new-referent result
-	  lob-info split-file split-ref index index-row index-col)
+	  lob-info split-file split-ref index index-row index-col id)
       ;; if ref is indexed grab the indices -- beware nested indices
       (when (and (string-match "\\[\\([^\\[]+\\)\\]$" ref)
 		 (let ((str (substring ref 0 (match-beginning 0))))
@@ -106,8 +125,8 @@ the variable."
 	    (setq args (mapcar (lambda (ref) (cons :var ref))
 			       (org-babel-ref-split-args new-referent))))
 	  (when (> (length new-header-args) 0)
-	    (setq args (append (org-babel-parse-header-arguments new-header-args)
-			       args)))
+	    (setq args (append (org-babel-parse-header-arguments
+				new-header-args) args)))
           (setq ref new-refere)))
       (when (string-match "^\\(.+\\):\\(.+\\)$" ref)
         (setq split-file (match-string 1 ref))
@@ -126,32 +145,37 @@ the variable."
 			   (re-search-backward res-rx nil t)))
 		  (re-search-forward src-rx nil t)
 		  (re-search-backward src-rx nil t)
+		  ;; check for local or global headlines by id
+		  (setq id (org-babel-ref-goto-headline-id ref))
 		  ;; check the Library of Babel
 		  (setq lob-info (cdr (assoc (intern ref)
 					     org-babel-library-of-babel)))))
-	    (unless lob-info (goto-char (match-beginning 0)))
+	    (unless (or lob-info id) (goto-char (match-beginning 0)))
 	  ;; ;; TODO: allow searching for names in other buffers
 	  ;; (setq id-loc (org-id-find ref 'marker)
 	  ;;       buffer (marker-buffer id-loc)
 	  ;;       loc (marker-position id-loc))
 	  ;; (move-marker id-loc nil)
 	  (error "reference '%s' not found in this buffer" ref))
-	(if lob-info
-	    (setq type 'lob)
-	  (while (not (setq type (org-babel-ref-at-ref-p)))
-	    (forward-line 1)
-	    (beginning-of-line)
-	    (if (or (= (point) (point-min)) (= (point) (point-max)))
-		(error "reference not found"))))
+	(cond
+	 (lob-info (setq type 'lob))
+	 (id (setq type 'id))
+	 (t (while (not (setq type (org-babel-ref-at-ref-p)))
+	      (forward-line 1)
+	      (beginning-of-line)
+	      (if (or (= (point) (point-min)) (= (point) (point-max)))
+		  (error "reference not found")))))
 	(let ((params (append args '((:results . "silent")))))
 	  (setq result
 		(case type
-		  ('results-line (org-babel-read-result))
-		  ('table (org-babel-read-table))
-		  ('list (org-babel-read-list))
-		  ('file (org-babel-read-link))
-		  ('source-block (org-babel-execute-src-block nil nil params))
-		  ('lob (org-babel-execute-src-block nil lob-info params)))))
+		  (results-line (org-babel-read-result))
+		  (table        (org-babel-read-table))
+		  (list         (org-babel-read-list))
+		  (file         (org-babel-read-link))
+		  (source-block (org-babel-execute-src-block nil nil params))
+		  (lob          (org-babel-execute-src-block
+				 nil lob-info params))
+		  (id           (org-babel-ref-headline-body)))))
 	(if (symbolp result)
 	    (format "%S" result)
 	  (if (and index (listp result))

+ 42 - 26
lisp/ob.el

@@ -68,6 +68,8 @@
 (declare-function org-babel-ref-split-args "ob-ref" (arg-string))
 (declare-function org-babel-ref-parse "ob-ref" (assignment))
 (declare-function org-babel-ref-resolve "ob-ref" (ref))
+(declare-function org-babel-ref-goto-headline-id "ob-ref" (id))
+(declare-function org-babel-ref-headline-body "ob-ref" ())
 (declare-function org-babel-lob-execute-maybe "ob-lob" ())
 (declare-function org-number-sequence "org-compat" (from &optional to inc))
 (declare-function org-at-item-p "org-list" ())
@@ -1893,28 +1895,33 @@ block but are passed literally to the \"example-block\"."
 		  ;; retrieve from the library of babel
 		  (nth 2 (assoc (intern source-name)
 				org-babel-library-of-babel))
+		  ;; return the contents of headlines literally
+		  (save-excursion
+		    (when (org-babel-ref-goto-headline-id source-name)
+		      (org-babel-ref-headline-body)))
 		  ;; find the expansion of reference in this buffer
-		  (or (mapconcat
-		       (lambda (i)
-			 (when (string= source-name
-					(or (cdr (assoc :noweb-ref (nth 2 i)))
-					    (nth 4 i)))
-			   (let ((body (org-babel-expand-noweb-references i)))
-			     (if comment
-				 ((lambda (cs) (concat (c-wrap (car cs)) "\n"
-						  body "\n" (c-wrap (cadr cs))))
-				  (org-babel-tangle-comment-links i))
-			       body))))
-		       (or blocks-in-buffer
-			   (setq blocks-in-buffer (blocks)))
-		       "")
-		      ;; possibly raise an error if named block doesn't exist
-		      (if (member lang org-babel-noweb-error-langs)
-			  (error "%s" (concat
-				       "<<" source-name ">> "
-				       "could not be resolved (see "
-				       "`org-babel-noweb-error-langs')"))
-			""))))
+		  (mapconcat
+		   (lambda (i)
+		     (when (string= source-name
+				    (or (cdr (assoc :noweb-ref (nth 2 i)))
+					(nth 4 i)))
+		       (let ((body (org-babel-expand-noweb-references i)))
+			 (if comment
+			     ((lambda (cs)
+				(concat (c-wrap (car cs)) "\n"
+					body "\n" (c-wrap (cadr cs))))
+			      (org-babel-tangle-comment-links i))
+			   body))))
+		   (or blocks-in-buffer
+		       (setq blocks-in-buffer (blocks)))
+		   "")
+		  ;; possibly raise an error if named block doesn't exist
+		  (if (member lang org-babel-noweb-error-langs)
+		      (error "%s" (concat
+				   "<<" source-name ">> "
+				   "could not be resolved (see "
+				   "`org-babel-noweb-error-langs')"))
+		    "")))
 	       "[\n\r]") (concat "\n" prefix)))))
         (nb-add (buffer-substring index (point-max)))))
     new-body))
@@ -1928,14 +1935,17 @@ block but are passed literally to the \"example-block\"."
   "Strip protective commas from bodies of source blocks."
   (replace-regexp-in-string "^,#" "#" body))
 
-(defun org-babel-script-escape (str)
+(defun org-babel-script-escape (str &optional force)
   "Safely convert tables into elisp lists."
   (let (in-single in-double out)
     ((lambda (escaped) (condition-case nil (org-babel-read escaped) (error escaped)))
-     (if (and (stringp str)
-	      (> (length str) 2)
-	      (string-equal "[" (substring str 0 1))
-	      (string-equal "]" (substring str -1)))
+     (if (or force
+	     (and (stringp str)
+		  (> (length str) 2)
+		  (or (and (string-equal "[" (substring str 0 1))
+			   (string-equal "]" (substring str -1)))
+		      (and (string-equal "{" (substring str 0 1))
+			   (string-equal "}" (substring str -1))))))
 	 (org-babel-read
 	  (concat
 	   "'"
@@ -1951,6 +1961,12 @@ block but are passed literally to the \"example-block\"."
 		   (93 (if (or in-double in-single) ; ]
 			   (cons 93 out)
 			 (cons 41 out)))
+		   (123 (if (or in-double in-single) ; {
+			    (cons 123 out)
+			  (cons 40 out)))
+		   (125 (if (or in-double in-single) ; }
+			    (cons 125 out)
+			  (cons 41 out)))
 		   (44 (if (or in-double in-single) ; ,
 			   (cons 44 out) (cons 32 out)))
 		   (39 (if in-double	; '

+ 6 - 0
lisp/org-exp.el

@@ -1708,6 +1708,12 @@ from the buffer."
 		(add-text-properties
 		 beg-content end-content
 		 `(org-protected t original-indentation ,ind org-native-text t))
+		;; strip protective commas
+		(save-excursion
+		  (save-match-data
+		    (goto-char beg-content)
+		    (while (re-search-forward "^[ \t]*\\(,\\)" end-content t)
+		      (replace-match "" nil nil nil 1))))
 		(delete-region (match-beginning 0) (match-end 0))
 		(save-excursion
 		  (goto-char beg)

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 167 - 162
lisp/org-list.el


+ 35 - 0
testing/examples/babel.org

@@ -157,6 +157,12 @@ This is an inline call call_echo(input="testing") embedded in prose.
 This is an inline call call_echo(input="testing")[:results vector] embedded in prose.
 #+call: lob-minus(8, 4)
 call_echo("testing")
+call_concat(1,2,3)
+
+#+source: concat
+#+begin_src emacs-lisp :var a=0 :var b=0 :var c=0
+  (format "%S%S%S" a b c)
+#+end_src
 
 * exporting an lob call line
   :PROPERTIES:
@@ -184,6 +190,9 @@ paragraph.
 And, a call with raw results call_double(4)[:results raw] should not
 have quoted results.
 
+The following 2*5=call_double(5) should export even when prefixed by
+an = sign.
+
 * parsing header arguments
   :PROPERTIES:
   :ID:       7eb0dc6e-1c53-4275-88b3-b22f3113b9c3
@@ -235,3 +244,29 @@ have quoted results.
 #+begin_src sh :noweb-ref fullest-disk
   |awk '{print $2}'
 #+end_src
+* resolving sub-trees as references
+  :PROPERTIES:
+  :ID:       2409e8ba-7b5f-4678-8888-e48aa02d8cb4
+  :results:  silent
+  :END:
+
+#+begin_src emacs-lisp :var text=d4faa7b3-072b-4dcf-813c-dd7141c633f3
+  (length text)
+#+end_src
+
+#+begin_src org :noweb yes
+  <<simple-subtree>>
+  <<d4faa7b3-072b-4dcf-813c-dd7141c633f3>>
+#+end_src
+
+** simple subtree with custom ID
+   :PROPERTIES:
+   :CUSTOM_ID: simple-subtree
+   :END:
+this is simple
+
+** simple subtree with global ID
+   :PROPERTIES:
+   :ID:       d4faa7b3-072b-4dcf-813c-dd7141c633f3
+   :END:
+has length 14

+ 10 - 2
testing/lisp/test-ob-lob.el

@@ -59,7 +59,9 @@
     (should (= 4 (org-babel-lob-execute (org-babel-lob-get-info))))
     (forward-line 1)
     (should (string= "testing" (org-babel-lob-execute
-				(org-babel-lob-get-info))))))
+				(org-babel-lob-get-info))))
+    (forward-line 1)
+    (should (string= "123" (org-babel-lob-execute (org-babel-lob-get-info))))))
 
 (ert-deftest test-ob-lob/export-lob-lines ()
   "Test the export of a variety of library babel call lines."
@@ -81,7 +83,13 @@
 	;; 6 should also be inline
 	(should (re-search-forward "6" nil t))
 	(should (re-search-forward (regexp-quote "</code>") (point-at-eol) t))
-	(should (re-search-backward (regexp-quote "<code>") (point-at-bol) t))))))
+	(should (re-search-backward (regexp-quote "<code>") (point-at-bol) t))
+	;; 8 should not be quoted
+	(should (re-search-forward "8" nil t))
+	(should (not (= ?= (char-after (point)))))
+	(should (not (= ?= (char-before (- (point) 1)))))
+	;; 10 should export
+	(should (re-search-forward "10" nil t))))))
 
 (provide 'test-ob-lob)
 

+ 8 - 0
testing/lisp/test-ob-tangle.el

@@ -69,6 +69,14 @@
 	(should (re-search-forward (regexp-quote tangled) nil t)))
       (delete-file "babel.sh"))))
 
+(ert-deftest ob-tangle/expand-headers-as-noweb-references ()
+  "Test that references to headers are expanded during noweb expansion."
+  (org-test-at-id "2409e8ba-7b5f-4678-8888-e48aa02d8cb4"
+    (org-babel-next-src-block 2)
+    (let ((expanded (org-babel-expand-noweb-references)))
+      (should (string-match (regexp-quote "simple") expanded))
+      (should (string-match (regexp-quote "length 14") expanded)))))
+
 (provide 'test-ob-tangle)
 
 ;;; test-ob-tangle.el ends here

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

@@ -206,6 +206,13 @@
       (should(equal '(:result-type . output) (assoc :result-type params)))
       (should(equal '(num . 9) (cdr (assoc :var params)))))))
 
+(ert-deftest test-org-babel/parse-header-args ()
+  (org-test-at-id "2409e8ba-7b5f-4678-8888-e48aa02d8cb4"
+    (should (string-match (regexp-quote "this is simple")
+			  (org-babel-ref-resolve "simple-subtree")))
+    (org-babel-next-src-block)
+    (should (= 14 (org-babel-execute-src-block)))))
+
 (provide 'test-ob)
 
 ;;; test-ob ends here

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است