all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: regular expression
Date: Wed, 02 Jul 2014 10:33:01 +0200	[thread overview]
Message-ID: <874mz017pe.fsf@debian.uxu> (raw)
In-Reply-To: mailman.4622.1404173952.1147.help-gnu-emacs@gnu.org

Tak Kunihiro <tak.kunihiro@gmail.com> writes:

> Use `re-builder' and `query-replace-regexp'.
>
> Play on (re-builder) with following setup, then copy
> regexp that is inside of ".  Call
> (query-replace-regexp) for substitution.
>
> (setq reb-re-syntax 'string)

re-builder is a gorgeous tool, if it was a girl I would
hit on it (her), however, compare two workflows:

Method one:

1. get up re-builder
2. start typing - ah, lots of highlights
   immediately...!
3. maybe my idea for a regexp wasn't that good, I have
   to rethink it (?)
4. redo 2-3 (the highlights of an incomplete regexp
   bouncing around, makes me think when I should type
   and think of what I type)
5. OK, that looks fine, check the screen to see it
   caught all cases (the regexp method is so the
   computer can do this, but OK I'll do it - why
   otherwise would it show?)
6. OK, I think it did catch all (didn't check all, I'm
   not a machine, but looks good)
7. put the regexp in query-replace-regexp
8. "yes" or "noing" them one by one

Method two:

1. think/write code
2. execute it

We shouldn't be afraid of the batch, one-hit
tools. They are not more difficult to master, and even
before we get there, they are less error prone that the
interactive pop-shooting all over the place "I
caught them all (almost, I think)". Be brave!

But that's not all, check out this I just wrote:

(progn
  (insert
   (let ((case-fold-search nil)
         (label "Totalt: ")
         (birds 0))
     (save-excursion
       (replace-regexp (format "^%s[[:digit:]]*\n\n" label) "")
       (while (re-search-forward "^[a-z]" (point-max) t) (incf birds)) )
     (format "\n\n%s%d" label birds) ))
  (save-buffer) )

Check it out in context here to see what it does:

http://user.it.uu.se/~embe8573/birds.txt

Yes: by getting better at regexp by doing simple cases
in code (like search-and-replaces with patterns), turns
out, the regexp can be used to keep track of a small
database of birds and keep a digit in sync! (I've heard
you need 300 to be a big boy - but even they had to get
by the 31st so I'm there in a couple of decades.)

Lesson to the computer kids of the world: Do the easy
things the (seemingly) difficult but in reality best
way, very soon the difficult things will be easy with
the exact same method. Remember, "What you once feared,
now makes you free. Do it today - in a different way!"

I'm getting of the soap box, thanks for this session
Emacs people.

-- 
underground experts united:
http://user.it.uu.se/~embe8573


       reply	other threads:[~2014-07-02  8:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.4622.1404173952.1147.help-gnu-emacs@gnu.org>
2014-07-02  8:33 ` Emanuel Berg [this message]
2014-07-02 23:14 regular expression Tak Kunihiro
  -- strict thread matches above, loose matches on Subject: below --
2014-07-02 13:10 Tak Kunihiro
2014-07-02 13:43 ` Stefan Monnier
2014-06-30 23:14 Tak Kunihiro
     [not found] <d5b8df44-60fd-4b8f-83d1-cb7d04b2a7b4@googlegroups.com>
2014-06-30 20:04 ` Emanuel Berg
2014-06-30 20:13   ` Emanuel Berg
2014-06-30 20:36     ` Teemu Likonen
     [not found]     ` <mailman.4605.1404160609.1147.help-gnu-emacs@gnu.org>
2014-06-30 20:52       ` Emanuel Berg
2014-06-30 21:04         ` Teemu Likonen
     [not found]         ` <mailman.4609.1404162300.1147.help-gnu-emacs@gnu.org>
2014-06-30 21:11           ` Emanuel Berg
2010-01-25 11:00 Burkhard Schultheis
2010-01-25 12:35 ` Nuno J. Silva
2010-01-25 12:53   ` Helmut Eller
2010-01-26 19:46     ` Nuno J. Silva
2010-01-25 16:34   ` Burkhard Schultheis
2010-01-25 18:12 ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to=874mz017pe.fsf@debian.uxu \
    --to=embe8573@student.uu.se \
    --cc=help-gnu-emacs@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.