emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Re[4]: [Orgmode] programming for org-mode


From: David Maus
Subject: Re: Re[4]: [Orgmode] programming for org-mode
Date: Sun, 08 Aug 2010 08:43:07 +0200
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Gojō) APEL/10.8 Emacs/23.2 (i486-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

Ivanov Dmitry wrote:
>Thanks, David. I improved the scheme, added 2 question. Please, take a look.

1/

,----
| 09.             (if (or (equal "(" (substring prop 0 1)) (equal "'" 
(substring prop 0 1)))
|
| vs.
|
| 09.             (if (string-match "^'?(.*)$" prop)
`----

I wouldn't call it a flaw in the original check but a pragmatic
solution for the problem at this point.  Ideally we want to check if
`prop' is a lisp expression so we can call `read' to return the
expression as lisp object.  To achieve this we would need a function
that checks if the string `prop' is a valid s-expression[1]: Balanced
parentheses and valid lisp atoms.  I am not an expert in regular
expressions but I think such a check can't be done with regexps but
requires an implementation of a lisp parser.

Example: (string-match "^'?(.*)$" "((foo baz)")) would return t but
"((foo baz)" is not a valid s-expression.

If we want (read prop) not to fail on an invalid s-exp but to threat
them as strings we can try to catch the error when executing `read':

,----
| (condition-case nil
|     (read prop)
|   (error prop))
`----

This would return the lisp object for `prop' if `prop' is a valid lisp
expression and the string `prop' otherwise (C-h f condition-case RET).

2/

,----
| 13.                 (progn (set-text-properties 0 (length prop) nil prop)
| 14.                        prop)))
`----

Setting the text-properties to nil indeed removes all
... text-properties, including colors.  The `progn' is unnecessary
because the body of the else clause is not limited to one lisp
expression (C-h f if RET).

HTH,
  -- David

[1] Note that the terms "s-expression", "lisp-expression", and "lisp
object" refer to one and the same structure.

Attachment: pgpZ0X8aEPOUs.pgp
Description: PGP signature


reply via email to

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