From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [babel][bug] org-babel-balanced-split (with Emacs-22) Date: Tue, 03 Jan 2012 11:46:17 -0700 Message-ID: <8739bwtyiu.fsf@gmx.com> References: <87hb0cu1bb.fsf@gmx.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:50069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ri9NW-0000ti-MX for emacs-orgmode@gnu.org; Tue, 03 Jan 2012 13:46:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ri9NS-0006Bo-UQ for emacs-orgmode@gnu.org; Tue, 03 Jan 2012 13:46:30 -0500 Received: from mailout-us.gmx.com ([74.208.5.67]:59156) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Ri9NR-00068k-VI for emacs-orgmode@gnu.org; Tue, 03 Jan 2012 13:46:26 -0500 In-Reply-To: (Martyn Jago's message of "Tue, 03 Jan 2012 18:32:56 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Martyn Jago Cc: emacs-orgmode@gnu.org Martyn Jago writes: > Eric Schulte writes: > >> Martyn Jago writes: >> >>> Martyn Jago writes: >>> >>> [...] >>> >>> The problem appears to be associated with the way `member' works: >>> >>> - on Emacs 23+ the following doesn't generate an error >>> - on Emacs 22 it generates "Wrong type argument: listp, 58" >>> >>> #+begin_src emacs-lisp >>> >>> (member 116 58) >>> >>> #+end_src >>> >>> `org-babel-balanced-split' appears to rely on not generating an error >>> when the `member' LIST parameter is actually a number. >>> >> >> Ah, I see where this comes in, does the included alternative definition >> of this function fix the issue on Emacs22? If so I'll apply this change >> to the repository. >> >> Thanks, >> >> (defun org-babel-balanced-split (string alts) >> "Split STRING on instances of ALTS. >> ALTS is a cons of two character options where each option may be >> either the numeric code of a single character or a list of >> character alternatives. For example to split on balanced >> instances of \"[ \t]:\" set ALTS to '((32 9) . 58)." >> (flet ((matches (ch spec) (or (and (numberp spec) (= spec ch)) >> (not (numberp spec) (member ch spec)))) > > [...] > > Hi Eric > > I fixed a typo on your fix, and added a regression test, and it now > works on Emacs 22. Thanks! > Great, both the test case and a fixed version of this function are now applied to the git repository. Thanks, > > Best, Martyn > > (defun org-babel-balanced-split (string alts) > "Split STRING on instances of ALTS. > ALTS is a cons of two character options where each option may be > either the numeric code of a single character or a list of > character alternatives. For example to split on balanced > instances of \"[ \t]:\" set ALTS to '((32 9) . 58)." > (flet ((matches (ch spec) (or (and (numberp spec) (= spec ch)) > (and (not (numberp spec)) > (member ch spec)))) > (matched (ch last) > (if (consp alts) > (and (matches ch (cdr alts)) > (matches last (car alts))) > (matches ch alts)))) > (let ((balance 0) (quote nil) (partial nil) (lst nil) (last 0)) > (mapc (lambda (ch) ; split on [], (), "" balanced instances of [ \t]: > (setq balance (+ balance > (cond ((or (equal 91 ch) (equal 40 ch)) 1) > ((or (equal 93 ch) (equal 41 ch)) -1) > (t 0)))) > (when (and (equal 34 ch) (not (equal 92 last))) > (setq quote (not quote))) > (setq partial (cons ch partial)) > (when (and (= balance 0) (not quote) (matched ch last)) > (setq lst (cons (apply #'string (nreverse > (if (consp alts) > (cddr partial) > (cdr partial)))) > lst)) > (setq partial nil)) > (setq last ch)) > (string-to-list string)) > (nreverse (cons (apply #'string (nreverse partial)) lst))))) > > (ert-deftest test-ob/org-babel-balanced-split () > (should (equal > '(":a 1" "b [2 3]" "c (4 :d (5 6))") > (org-babel-balanced-split ":a 1 :b [2 3] :c (4 :d (5 6))" '((32 9) . 58))))) -- Eric Schulte http://cs.unm.edu/~eschulte/