Browse Source

ob-ref: fixed error caused by missing count function, now using org-count

* lisp/ob-ref.el (org-babel-ref-resolve-reference): removed an error
  introduced while fixing compiler warnings -- required mirroring of
  the count cl-seqs function under the org-mode namespace.

* lisp/org.el (org-count): adding an org-mode version of the cl-seqs
  count function
Eric Schulte 14 years ago
parent
commit
2f178148f9
2 changed files with 15 additions and 6 deletions
  1. 4 6
      lisp/ob-ref.el
  2. 11 0
      lisp/org.el

+ 4 - 6
lisp/ob-ref.el

@@ -41,7 +41,7 @@
 ;; same file would be
 
 ;;  #+TBLNAME: sandbox
-;;  | 1 |       2 | 3 |
+;;  | 1 |         2 | 3 |
 ;;  | 4 | org-babel | 6 |
 ;;
 ;;  #+begin_src emacs-lisp :var table=sandbox
@@ -55,6 +55,7 @@
 
 (declare-function org-remove-if-not "org" (predicate seq))
 (declare-function org-at-table-p "org" (&optional table-type))
+(declare-function org-count "org" (CL-ITEM CL-SEQ))
 
 (defun org-babel-ref-variables (params)
   "Convert PARAMS to variable names and values.
@@ -108,13 +109,10 @@ return nil."
     (let ((case-fold-search t)
           type args new-refere new-referent result lob-info split-file split-ref
           index index-row index-col)
-      ;; if ref is indexed grab the indices -- beware nested indicies
+      ;; if ref is indexed grab the indices -- beware nested indices
       (when (and (string-match "\\[\\(.+\\)\\]" ref)
 		 (let ((str (substring ref 0 (match-beginning 0))))
-		   (= (length (org-remove-if-not
-			       (lambda (el) (equal ?( el)) (string-to-list "((eric))")))
-		      (length (org-remove-if-not
-			       (lambda (el) (equal ?) el)) (string-to-list "((eric))"))))))
+		   (= (org-count ?( str) (org-count ?) str))))
         (setq index (match-string 1 ref))
         (setq ref (substring ref 0 (match-beginning 0))))
       ;; assign any arguments to pass to source block

+ 11 - 0
lisp/org.el

@@ -18223,6 +18223,17 @@ for the search purpose."
     (setq list (delete (pop elts) list)))
   list)
 
+(defun org-count (cl-item cl-seq)
+  "Count the number of occurrences of ITEM in SEQ.
+Taken from `count' in cl-seq.el with all keyword arguments removed."
+  (let ((cl-end (length cl-seq)) (cl-start 0) (cl-count 0)  cl-x)
+    (when (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq)))
+    (while (< cl-start cl-end)
+      (setq cl-x (if (consp cl-seq) (pop cl-seq) (aref cl-seq cl-start)))
+      (if (equal cl-item cl-x) (setq cl-count (1+ cl-count)))
+      (setq cl-start (1+ cl-start)))
+    cl-count))
+
 (defun org-remove-if (predicate seq)
   "Remove everything from SEQ that fulfills PREDICATE."
   (let (res e)