Browse Source

babel: replacing functions like "fifth" with "nth 4"

Eric Schulte 15 years ago
parent
commit
6fa2ab7eac

+ 2 - 2
lisp/babel/langs/ob-emacs-lisp.el

@@ -48,9 +48,9 @@
 (defun org-babel-expand-body:emacs-lisp (body params &optional processed-params)
   "Expand BODY according to PARAMS, return the expanded body."
   (let* ((processed-params (or processed-params (org-babel-process-params params)))
-         (vars (second processed-params))
+         (vars (nth 1 processed-params))
          (processed-params (org-babel-process-params params))
-         (result-params (third processed-params))
+         (result-params (nth 2 processed-params))
          (print-level nil) (print-length nil)
          (body (if (> (length vars) 0)
 		   (concat "(let ("

+ 3 - 3
lisp/babel/langs/ob-sh.el

@@ -42,7 +42,7 @@
 
 (defun org-babel-expand-body:sh (body params &optional processed-params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let ((vars (second (or processed-params (org-babel-process-params params))))
+  (let ((vars (nth 1 (or processed-params (org-babel-process-params params))))
         (sep (cdr (assoc :separator params))))
     (concat
    (mapconcat ;; define any variables
@@ -57,8 +57,8 @@
 function is called by `org-babel-execute-src-block'."
   (message "executing Shell source code block")
   (let* ((processed-params (org-babel-process-params params))
-         (session (org-babel-sh-initiate-session (first processed-params)))
-         (result-params (third processed-params)) 
+         (session (org-babel-sh-initiate-session (nth 0 processed-params)))
+         (result-params (nth 2 processed-params)) 
          (full-body (org-babel-expand-body:sh
                      body params processed-params))) ;; then the source block body
     (org-babel-reassemble-table

+ 18 - 18
lisp/babel/ob-exp.el

@@ -80,18 +80,18 @@ results - just like none only the block is run on export ensuring
 none ----- do not display either code or results upon export"
   (interactive)
   (message "org-babel-exp processing...")
-  (when (member (first headers) org-babel-interpreters)
+  (when (member (nth 0 headers) org-babel-interpreters)
     (save-excursion
       (goto-char (match-beginning 0))
       (let* ((info (org-babel-get-src-block-info))
-	     (params (third info)))
+	     (params (nth 2 info)))
 	;; expand noweb references in the original file
-	(setf (second info)
+	(setf (nth 1 info)
 	      (if (and (cdr (assoc :noweb params))
 		       (string= "yes" (cdr (assoc :noweb params))))
 		  (org-babel-expand-noweb-references
 		   info (get-file-buffer org-current-export-file))
-		(second info)))
+		(nth 1 info)))
 	(org-babel-exp-do-export info 'block)))))
 
 (defun org-babel-exp-inline-src-blocks (start end)
@@ -104,18 +104,18 @@ options and are taken from `org-babel-defualt-inline-header-args'."
     (while (and (< (point) end)
                 (re-search-forward org-babel-inline-src-block-regexp end t))
       (let* ((info (save-match-data (org-babel-parse-inline-src-block-match)))
-	     (params (third info))
+	     (params (nth 2 info))
 	     (replacement
 	      (save-match-data
 		(if (org-babel-in-example-or-verbatim)
 		    (buffer-substring (match-beginning 0) (match-end 0))
 		  ;; expand noweb references in the original file
-		  (setf (second info)
+		  (setf (nth 1 info)
 			(if (and (cdr (assoc :noweb params))
 				 (string= "yes" (cdr (assoc :noweb params))))
 			    (org-babel-expand-noweb-references
 			     info (get-file-buffer org-current-export-file))
-			  (second info)))
+			  (nth 1 info)))
 		  (org-babel-exp-do-export info 'inline)))))
 	(setq end (+ end (- (length replacement) (length (match-string 1)))))
 	(replace-match replacement t t nil 1)))))
@@ -176,13 +176,13 @@ options are taken from `org-babel-default-header-args'."
 (defun org-babel-exp-do-export (info type)
   "Return a string containing the exported content of the current
 code block respecting the value of the :exports header argument."
-  (flet ((silently () (let ((session (cdr (assoc :session (third info)))))
+  (flet ((silently () (let ((session (cdr (assoc :session (nth 2 info)))))
 			(when (and session
 				   (not (equal "none" session))
-				   (not (assoc :noeval (third info))))
+				   (not (assoc :noeval (nth 2 info))))
 			  (org-babel-exp-results info type 'silent))))
 	 (clean () (org-babel-remove-result info)))
-    (case (intern (or (cdr (assoc :exports (third info))) "code"))
+    (case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
       ('none (silently) (clean) "")
       ('code (silently) (clean) (org-babel-exp-code info type))
       ('results (org-babel-exp-results info type))
@@ -195,13 +195,13 @@ code block respecting the value of the :exports header argument."
 for exportation by org-mode.  This function is called by
 `org-babel-exp-do-export'.  The code block will not be
 evaluated."
-  (let ((lang (first info))
-        (body (second info))
-        (switches (fourth info))
-        (name (fifth info))
+  (let ((lang (nth 0 info))
+        (body (nth 1 info))
+        (switches (nth 3 info))
+        (name (nth 4 info))
         (args (mapcar
 	       #'cdr
-	       (remove-if-not (lambda (el) (eq :var (car el))) (third info)))))
+	       (remove-if-not (lambda (el) (eq :var (car el))) (nth 2 info)))))
     (case type
       ('inline (format "=%s=" body))
       ('block
@@ -233,8 +233,8 @@ suitable for exportation by org-mode.  This function is called by
 `org-babel-exp-do-export'.  The code block will be evaluated.
 Optional argument SILENT can be used to inhibit insertion of
 results into the buffer."
-  (let ((lang (first info))
-	(body (second info))
+  (let ((lang (nth 0 info))
+	(body (nth 1 info))
 	(params
 	 ;; lets ensure that we lookup references in the original file
 	 (mapcar
@@ -247,7 +247,7 @@ results into the buffer."
 				  "=" org-current-export-file
 				  ":" (match-string 2 (cdr pair))))
 	      pair))
-	  (third info))))
+	  (nth 2 info))))
     (case type
       ('inline
         (let ((raw (org-babel-execute-src-block

+ 3 - 3
lisp/babel/ob-lob.el

@@ -50,7 +50,7 @@ add files to this list use the `org-babel-lob-ingest' command."
   (interactive "f")
   (org-babel-map-source-blocks file
     (let* ((info (org-babel-get-src-block-info))
-	   (source-name (intern (fifth info))))
+	   (source-name (intern (nth 4 info))))
       (when source-name
         (setq org-babel-library-of-babel
               (cons (cons source-name info)
@@ -76,7 +76,7 @@ src-block and if so then run the appropriate source block from
 the Library."
   (interactive)
   (let ((info (org-babel-lob-get-info)))
-    (if (first info) (progn (org-babel-lob-execute info) t) nil)))
+    (if (nth 0 info) (progn (org-babel-lob-execute info) t) nil)))
 
 (add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-lob-execute-maybe)
 
@@ -109,7 +109,7 @@ the word 'call'."
 		  (org-babel-clean-text-properties
 		   (concat ":var results=" (mapconcat #'identity (butlast info) " ")))))))
     (org-babel-execute-src-block
-     nil (list "emacs-lisp" "results" params nil nil (third info)))))
+     nil (list "emacs-lisp" "results" params nil nil (nth 2 info)))))
 
 (provide 'ob-lob)
 ;;; ob-lob.el ends here

+ 2 - 2
lisp/babel/ob-table.el

@@ -82,7 +82,7 @@ rather than a single \"$\" (i.e. \"$$2\" instead of \"$2\" in the
 example above."
   (let ((variables (mapcar
                     (lambda (var)
-                      (if (and (= 3 (length var)) (eq (second var) '$))
+                      (if (and (= 3 (length var)) (eq (nth 1 var) '$))
                           (list (car var) (format "\"%s\"" (last var)))
                         var))
                     variables)))
@@ -95,7 +95,7 @@ example above."
                                 ,source-block
                                 "("
                                 (mapconcat (lambda (var-spec)
-                                             (format "%S=%s" (first var-spec) (second var-spec)))
+                                             (format "%S=%s" (nth 0 var-spec) (nth 1 var-spec)))
                                            ',variables ", ")
                                 ")")))))
            (org-babel-execute-src-block

+ 16 - 16
lisp/babel/ob-tangle.el

@@ -55,7 +55,7 @@ file using `load-file'."
   (flet ((age (file)
               (time-to-seconds
                (time-subtract (current-time)
-                              (sixth (or (file-attributes (file-truename file))
+                              (nth 5 (or (file-attributes (file-truename file))
                                          (file-attributes file)))))))
     (let* ((base-name (file-name-sans-extension file))
            (exported-file (concat base-name ".el")))
@@ -109,14 +109,14 @@ exported source code blocks by language."
 			      lang)
 			  "-mode")))
                 (lang-specs (cdr (assoc lang org-babel-tangle-langs)))
-                (ext (first lang-specs))
-                (she-bang (second lang-specs))
-                (commentable (and (fboundp lang-f) (not (third lang-specs))))
+                (ext (nth 0 lang-specs))
+                (she-bang (nth 1 lang-specs))
+                (commentable (and (fboundp lang-f) (not (nth 2 lang-specs))))
                 she-banged)
            (mapc
             (lambda (spec)
               (flet ((get-spec (name)
-                               (cdr (assoc name (third spec)))))
+                               (cdr (assoc name (nth 2 spec)))))
                 (let* ((tangle (get-spec :tangle))
                        (she-bang (if (> (length (get-spec :shebang)) 0)
                                      (get-spec :shebang)
@@ -189,11 +189,11 @@ code blocks by language."
                           (org-babel-clean-text-properties
 			   (car (pop org-stored-links)))))
              (info (org-babel-get-src-block-info))
-             (source-name (intern (or (fifth info)
+             (source-name (intern (or (nth 4 info)
                                       (format "block-%d" block-counter))))
-             (src-lang (first info))
+             (src-lang (nth 0 info))
 	     (expand-cmd (intern (concat "org-babel-expand-body:" src-lang)))
-             (params (third info))
+             (params (nth 2 info))
              by-lang)
         (unless (string= (cdr (assoc :tangle params)) "no") ;; skip
           (unless (and lang (not (string= lang src-lang))) ;; limit by language
@@ -219,8 +219,8 @@ code blocks by language."
 						(cdr (assoc :noweb params))))
                                           (org-babel-expand-noweb-references
 					   info)
-					(second info)))
-                                     (third
+					(nth 1 info)))
+                                     (nth 2
 				      (cdr (assoc src-lang
 						  org-babel-tangle-langs))))
                                by-lang)) blocks))))))
@@ -248,14 +248,14 @@ form
 					   (progn (insert text) (point)))
                            (end-of-line nil)
                            (insert "\n"))))
-    (let ((link (first spec))
-          (source-name (second spec))
-          (body (fourth spec))
-          (commentable (not (if (> (length (cdr (assoc :comments (third spec))))
+    (let ((link (nth 0 spec))
+          (source-name (nth 1 spec))
+          (body (nth 3 spec))
+          (commentable (not (if (> (length (cdr (assoc :comments (nth 2 spec))))
 				   0)
-                                (string= (cdr (assoc :comments (third spec)))
+                                (string= (cdr (assoc :comments (nth 2 spec)))
 					 "no")
-                              (fifth spec)))))
+                              (nth 4 spec)))))
       (insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name))
       (insert (format "\n%s\n" (replace-regexp-in-string
 				"^," "" (org-babel-chomp body))))

+ 29 - 29
lisp/babel/ob.el

@@ -82,8 +82,8 @@ function is called when `org-edit-special' is called with a
 prefix argument from inside of a source-code block."
   (when current-prefix-arg
     (let* ((info (org-babel-get-src-block-info))
-           (lang (first info))
-           (params (third info))
+           (lang (nth 0 info))
+           (params (nth 2 info))
            (session (cdr (assoc :session params))))
       (when (and info session) ;; we are in a source-code block with a session
         (funcall
@@ -246,9 +246,9 @@ the header arguments specified at the front of the source code
 block."
   (interactive)
   (let* ((info (or info (org-babel-get-src-block-info)))
-         (lang (first info))
-	 (params (setf (third info)
-                       (sort (org-babel-merge-params (third info) params)
+         (lang (nth 0 info))
+	 (params (setf (nth 2 info)
+                       (sort (org-babel-merge-params (nth 2 info) params)
                              (lambda (el1 el2) (string< (symbol-name (car el1))
                                                    (symbol-name (car el2)))))))
          (new-hash
@@ -256,11 +256,11 @@ block."
                    (string= "yes" (cdr (assoc :cache params))))
               (org-babel-sha1-hash info)))
          (old-hash (org-babel-result-hash info))
-         (body (setf (second info)
+         (body (setf (nth 1 info)
 		     (if (and (cdr (assoc :noweb params))
                               (string= "yes" (cdr (assoc :noweb params))))
                          (org-babel-expand-noweb-references info)
-		       (second info))))
+		       (nth 1 info))))
          (result-params (split-string (or (cdr (assoc :results params)) "")))
          (result-type (cond ((member "output" result-params) 'output)
 			    ((member "value" result-params) 'value)
@@ -310,15 +310,15 @@ org-babel-expand-body:lang function." body)
 arguments, and pop open the results in a preview buffer."
   (interactive)
   (let* ((info (or info (org-babel-get-src-block-info)))
-         (lang (first info))
-	 (params (setf (third info)
-                       (sort (org-babel-merge-params (third info) params)
+         (lang (nth 0 info))
+	 (params (setf (nth 2 info)
+                       (sort (org-babel-merge-params (nth 2 info) params)
                              (lambda (el1 el2) (string< (symbol-name (car el1))
                                                    (symbol-name (car el2)))))))
-         (body (setf (second info)
+         (body (setf (nth 1 info)
 		     (if (and (cdr (assoc :noweb params))
                               (string= "yes" (cdr (assoc :noweb params))))
-			 (org-babel-expand-noweb-references info) (second info))))
+			 (org-babel-expand-noweb-references info) (nth 1 info))))
          (cmd (intern (concat "org-babel-expand-body:" lang)))
          (expanded (funcall (if (fboundp cmd) cmd 'org-babel-expand-body:generic)
                             body params)))
@@ -331,9 +331,9 @@ header arguments for the source block before entering the
 session.  After loading the body this pops open the session."
   (interactive)
   (let* ((info (or info (org-babel-get-src-block-info)))
-         (lang (first info))
-         (body (second info))
-         (params (third info))
+         (lang (nth 0 info))
+         (body (nth 1 info))
+         (params (nth 2 info))
          (session (cdr (assoc :session params))))
     (unless (member lang org-babel-interpreters)
       (error "Language is not in `org-babel-interpreters': %s" lang))
@@ -350,9 +350,9 @@ for the source block before entering the session. Copy the body
 of the source block to the kill ring."
   (interactive)
   (let* ((info (or info (org-babel-get-src-block-info)))
-         (lang (first info))
-         (body (second info))
-         (params (third info))
+         (lang (nth 0 info))
+         (body (nth 1 info))
+         (params (nth 2 info))
          (session (cdr (assoc :session params)))
 	 (dir (cdr (assoc :dir params)))
 	 (default-directory
@@ -463,8 +463,8 @@ added to the header-arguments-alist."
 					 (lambda (ref) (cons :var ref))
 					 (org-babel-ref-split-args args))))))
 		(unless header-vars-only
-		  (setf (third info)
-			(org-babel-merge-params (sixth info) (third info)))))
+		  (setf (nth 2 info)
+			(org-babel-merge-params (nth 5 info) (nth 2 info)))))
 	    (setq info (append info (list nil nil))))
 	  (append info (list indent)))
       (if (save-excursion ;; inline source block
@@ -478,8 +478,8 @@ added to the header-arguments-alist."
   (interactive)
   (let* ((info (or info (org-babel-get-src-block-info)))
          (hash (sha1 (format "%s-%s" (mapconcat (lambda (arg) (format "%S" arg))
-                                                (third info) ":")
-                             (second info)))))
+                                                (nth 2 info) ":")
+                             (nth 1 info)))))
     (when (interactive-p) (message hash))
     hash))
 
@@ -747,7 +747,7 @@ Return a list (session vars result-params result-type colnames rownames)."
   "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."
-  (if (equal 'hline (second table))
+  (if (equal 'hline (nth 1 table))
       (cons (cddr table) (car table))
     (cons (cdr table) (car table))))
 
@@ -800,7 +800,7 @@ of the vars, cnames and rnames."
       (lambda (var)
         (when (listp (cdr var))
           (when (and (not (equal colnames "no"))
-                     (or colnames (and (equal (second (cdr var)) 'hline)
+                     (or colnames (and (equal (nth 1 (cdr var)) 'hline)
                                        (not (member 'hline (cddr (cdr var)))))))
             (let ((both (org-babel-get-colnames (cdr var))))
               (setq cnames (cons (cons (car var) (cdr both))
@@ -894,8 +894,8 @@ following the source block."
     (let* ((on-lob-line (progn (beginning-of-line 1)
 			       (looking-at org-babel-lob-one-liner-regexp)))
 	   (name (if on-lob-line
-		     (first (org-babel-lob-get-info))
-		   (fifth (or info (org-babel-get-src-block-info)))))
+		     (nth 0 (org-babel-lob-get-info))
+		   (nth 4 (or info (org-babel-get-src-block-info)))))
 	   (head (unless on-lob-line (org-babel-where-is-src-block-head))) end)
       (when head (goto-char head))
       (or (and name (org-babel-find-named-result name))
@@ -1031,7 +1031,7 @@ code ---- the results are extracted in the syntax of the source
 	(let ((existing-result (org-babel-where-is-src-block-result
 				t info hash indent))
 	      (results-switches
-               (cdr (assoc :results_switches (third info))))
+               (cdr (assoc :results_switches (nth 2 info))))
 	      beg end)
 	  (when existing-result
 	    (goto-char existing-result)
@@ -1283,8 +1283,8 @@ these arguments are not evaluated in the current source-code
 block but are passed literally to the \"example-block\"."
   (let* ((parent-buffer (or parent-buffer (current-buffer)))
          (info (or info (org-babel-get-src-block-info)))
-         (lang (first info))
-         (body (second info))
+         (lang (nth 0 info))
+         (body (nth 1 info))
          (new-body "") index source-name evaluate prefix)
     (flet ((nb-add (text)
                    (setq new-body (concat new-body text))))