help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: regexp won't match


From: Andreas Röhler
Subject: Re: regexp won't match
Date: Tue, 19 May 2009 18:42:57 +0200
User-agent: Thunderbird 2.0.0.19 (X11/20081227)

shm wrote:
> Hello all,
>
> \I have a problem matching a regexp, and i don't understand
> why. We have a license staement which should be at the top of
> every java file in our project:
>
> /**
>    This file is part of opensearch.
>    Copyright © 2009, Dansk Bibliotekscenter a/s,
>    Tempovej 7-11, DK-2750 Ballerup, Denmark. CVR: 15149043
>
>    opensearch is free software: you can redistribute it and/or modify
>    it under the terms of the GNU General Public License as published by
>    the Free Software Foundation, either version 3 of the License, or
>    (at your option) any later version.
>
>    opensearch is distributed in the hope that it will be useful,
>    but WITHOUT ANY WARRANTY; without even the implied warranty of
>    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>    GNU General Public License for more details.
>
>    You should have received a copy of the GNU General Public License
>    along with opensearch.  If not, see <http://www.gnu.org/licenses/>.
> */
>
> and i would like to match it, so i can make some markup for it, like:
>
>     (, "\\`\\(/\\*\\*\n   This file is part of opensearch.\n   Copyright © 
> 2009, Dansk Bibliotekscenter a/s,\n   Tempovej 7-11, DK-2750 Ballerup, 
> Denmark. CVR: 15149043\n\n   opensearch is free software: you can 
> redistribute 
> it and/or modify\n   it under the terms of the GNU General Public License as 
> published by\n   the Free Software Foundation, either version 3 of the 
> License, or\n   (at your option) any later version.\n\n   opensearch is 
> distributed in the hope that it will be useful,\n   but WITHOUT ANY 
> WARRANTY\; 
> without even the implied warranty of\n\\)" 1 java-add-on-font-lock-license-
> face prepend)
>
> But when i try to expand the above line (after the line break it
> should be three spaces and the next line of text), with just one
> space it won't match.
>
> I have used whitespace-mode to check the text, and it shows three
> spaces at the beginning of the line, so I have no clue as to why
> this is not workning.
>
> Thanks in advance
>   Søren Mollerup
>
>
>   


Have made beg-end.el for this kind of things.  You just need a known
beginning-
and end-string.

Its written to detect nested forms, works with
non-nested anyway...

Check it out here:

https://code.launchpad.net/s-x-emacs-werkstatt/

Andreas Röhler

Below an example, it narrows buffer to your license text.

(setq my-begstring "This file is part of opensearch")
(setq my-endstring "If not, see <http://www.gnu.org/licenses/>")


(defun narrow-to-my-firms-license (&optional beg end)
  (interactive)
  (let ((beg (cond (beg beg)
           ((region-active-p)
            (region-beginning))
           (t (point-min))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (point-max)))))
        license-beg license-end)
    (goto-char beg)
    ;; beg-end.el works from inside a form
    (re-search-forward my-begstring nil t 1)
    (beginning-of-form-base my-begstring my-endstring)
    (setq license-beg (point))
    (end-of-form-base my-begstring my-endstring)
    (setq license-end (point))
    (message "%s %s" license-beg license-end)
    (narrow-to-region
     license-beg license-end)))





reply via email to

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