emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [babel][bug] org-babel-balanced-split (with Emacs-22)


From: Eric Schulte
Subject: Re: [O] [babel][bug] org-babel-balanced-split (with Emacs-22)
Date: Tue, 03 Jan 2012 10:46:00 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Martyn Jago <address@hidden> writes:

> Martyn Jago <address@hidden> writes:
>
>> There is a bug running babel on Emacs 22.1.1 with a minimal init file.
>>
>
> [...]
>
>>
>> The following fails:
>>
>> * Test fails
>>
>> #+begin_src emacs-lisp :results silent
>>
>> "hello there"
>>
>> #+end_src
>>
>
> [...]
>
> 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))))
         (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)))))

>
> Best, Martyn
>
>
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]