emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carsten Dominik <carsten.dominik@gmail.com>
To: Thorsten Jolitz <tjolitz@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] in org-property-drawer-re?
Date: Tue, 1 Oct 2013 20:17:08 +0200	[thread overview]
Message-ID: <AF619789-B5B0-4904-A1DD-F89DE121D74F@gmail.com> (raw)
In-Reply-To: <87r4c4519w.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4908 bytes --]


On 1.10.2013, at 19:50, Thorsten Jolitz <tjolitz@gmail.com> wrote:

> 
> Hi List, 
> 
> for the navi-mode keyword-search for complete property drawers I copied
> 
> ,-----------------------
> | org-property-drawer-re
> `-----------------------
> 
> from org.el:
> 
> #+begin_src emacs-lisp
>  (concat "\\(" org-property-start-re "\\)[^\000]*\\("
> 	  org-property-end-re "\\)\n?")
> #+end_src
> 
> #+results:
> : \(^[ 	]*:PROPERTIES:[ 	]*$\)[^\\000]*\(^[ 	]*:END:[ 	]*$\)
> : ?
> 
> A bit unreadable, but you get the message ... here is my hopefully equivalent
> version: 
> 
> ,--------------------------------------------------------------
> | (:propertydrawer
> |   . (concat "\\(^[\\s\\t]*:PROPERTIES:[\\s\\t]*$\\)[^\\000]*"
> |             "\\(^[\\s\\t]*:END:[\\s\\t]*$\\)\\n?"))
> `--------------------------------------------------------------
> 
> But this did not match correctly in Bernt Hansens tutorial:

Indeed, this is a bad regular expression, it is too greedy and will
match all the way to the last :END: line it can find.  also, \\s is
wrong, it should be just a space, so "[ \t]". Luckily
this regular expression does not seem to be used in Org as far
as I can see....

> 
>    ,--------------------------------------------------------------------------
>    |  43::PROPERTIES:
>    |    ::CUSTOM_ID: Setup
>    |    ::END:
>    | 131::PROPERTIES:
>    |    ::CUSTOM_ID: OrgFiles
>    |    ::END:
>    | 185::PROPERTIES:
>    |    ::CUSTOM_ID: AgendaSetup
>    |    ::END:
>    |    :
>    |    :Here is my current =org-agenda-files= setup.
>    |    :#+begin_src emacs-lisp :tangle no
>    |    :  (setq org-agenda-files (quote ("~/git/org"
>    |    :                                 "~/git/org/client1"
>    |    :                                 "~/git/org/bzflag"
>    |    :                                 "~/git/client2")))
>    |    :#+end_src
>    |    :
>    |    :#+begin_src emacs-lisp :tangle yes :exports none
>    |    :  ;; The following setting is different from the document so that you
>    |    :  ;; can override the document org-agenda-files by setting your
>    |    :  ;; org-agenda-files in the variable org-user-agenda-files
>    |    :  ;;
>    |    :  (if (boundp 'org-user-agenda-files)
>    |    :      (setq org-agenda-files org-user-agenda-files)
>    |    :    (setq org-agenda-files (quote ("~/git/org"
>    |    :                                 "~/git/org/client1"
>    |    :                                 "~/git/org/bzflag"
>    |    :                                 "~/git/client2"))))
>    |    :  
>    |    :#+end_src
>    `--------------------------------------------------------------------------
> 
> I had to add two ?

You only need the first - the second is OK.

> after the * and delete the final \n 
> 
> ,-------------------------------------------------------------
> | (:propertydrawer
> | . (concat "\\(^[\\s\\t]*:PROPERTIES:[\\s\\t]*$\\)[^\\000]*?"
> |           "\\(^[\\s\\t]*:END:[\\s\\t]*?$\\)"))
> `-------------------------------------------------------------

Yes, you need the star to make it non-greedy.
However, you can leave the \n after you have corrected the
character class to "[ \t]" - it just means that
the \n will be part of the match, but still allow
for the possibility that the last line hits the end
of the buffer.

Ahhhh, regular expressions.  I think in my entire history
as a programmer, learning about regular expressions was
the biggest braintrip I ever had - still love them.

> 
> to get the desired results:
> 
>    ,---------------------------------
>    |  43::PROPERTIES:
>    |    ::CUSTOM_ID: Setup
>    |    ::END:
>    | 131::PROPERTIES:
>    |    ::CUSTOM_ID: OrgFiles
>    |    ::END:
>    | 185::PROPERTIES:
>    |    ::CUSTOM_ID: AgendaSetup
>    |    ::END:
>    | 234::PROPERTIES:
>    |    ::CUSTOM_ID: OrgFileStructure
>    |    ::END:
>    `---------------------------------
> 
> A bug in the regexp?
> 
> PS 
> Can anybody explain this marvelous construct in the regexp:
> 
> ,---------
> | [^\\000]
> `---------

This is just a cheep way to match any character at all, because \000 should
not be part of any string (in C it indicates the end of a string).
In principle you could put any character you are sure will not turn up,
but \000 seems to be the safest choice.  It is
faster (I think) than "\\(.\\|\n\\)*" because the first will
just run fast and streight with a table lookup while the
latter need to always alternate between two alternatives.
I have not timed it, though.

> 
> I often pondered about how to achieve its effect with other means, since
> I did not find it in the Emacs Lisp manual.

There you go - sometimes a brain is better than the Emacs manual :)

Regards

- Carsten

> 
> -- 
> cheers,
> Thorsten
> 
> 


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

  reply	other threads:[~2013-10-01 18:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-01 17:50 [BUG] in org-property-drawer-re? Thorsten Jolitz
2013-10-01 18:17 ` Carsten Dominik [this message]
2013-10-01 18:36   ` Thorsten Jolitz
2013-10-01 18:44     ` Carsten Dominik
2013-10-02  9:55   ` Nicolas Goaziou
2013-10-02 11:05     ` Carsten Dominik
2013-10-02 11:14       ` Nicolas Goaziou
2013-10-02 11:37         ` Carsten Dominik
2013-10-02 11:38     ` Thorsten Jolitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AF619789-B5B0-4904-A1DD-F89DE121D74F@gmail.com \
    --to=carsten.dominik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tjolitz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).