all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: vb <help-gnu-emacs@vsbe.com>
Cc: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Regular expression search
Date: Wed, 1 Nov 2006 13:10:59 -0800	[thread overview]
Message-ID: <200611011310.59710.help-gnu-emacs@vsbe.com> (raw)
In-Reply-To: <eiaul8$2qe$1@sea.gmane.org>

Kevin,

thank you for your explanation. The [[:print:]] notation didn't quite work 
either, but following your suggestion I tried \\S- and it worked.

(defun vb-first-printable ()
  (interactive)
  (beginning-of-line)
  ( if (re-search-forward "\\S-" (line-end-position) 't)
      (backward-char)
    )
)


Boy, nothing is what it seems with emacs :-)

cheers,
/vb

On Wednesday 01 November 2006 12:04, Kevin Rodgers wrote:
> vb wrote:
> > let's say I need a function to find first printable character on the line
> > where the pointer is. This is what I'm trying to use:
> >
> > (defun vb-first-printable ()
> >   (interactive)
> >   (let (limit-position)
> >     (beginning-of-line)
> >     (next-line 1)
> >     (setq limit-position (point))
> >     (previous-line 1)
> >     (re-search-forward "\\S" limit-position 't)))
> >
> > when I try executing this, I get the following error:
> >
> > ====================================================
> > Debugger entered--Lisp error: (invalid-regexp "Premature end of regular
> > expression")
> >   re-search-forward("\\S" 3543 t)
> >   (let (limit-position) (beginning-of-line) (next-line 1) (setq
> > limit-position (point)) (previous-line 1) (re-search-forward "\\S"
> > limit-position (quote t)))
> >   vb-first-printable()
> >   call-interactively(vb-first-printable)
> > ===================================================
> >
> > the same problem happens when I try re-search-forward from the command
> > line: if I enter "\S" as the pattern to search, I get "premature end of
> > regular expression" error,  but if I enter "\\S" as the regular
> > expression pattern, the only thing it finds is this pattern (\\S) itself
> > (as I try it on the same file where the source code is).
> >
> > What am I missing here?
>
> Commands that prompt you for a regexp allow you to enter it directly;
> but when calling a Lisp function you have to specify the regexp as a
> string, and in order to represent a backslash within a (double quote-
> delimited) string literal you must double it: "This string has 1
> backslash (here: \\) and 1 double quote (here: \")."  And of course
> the `\\' regexp matches the backslash character itself.
>
> The manual states:
>
> ,----
>
> | `\sC'
> |      matches any character whose syntax is C.  Here C is a character
> |      that designates a particular syntax class: thus, `w' for word
> |      constituent, `-' or ` ' for whitespace, `.' for ordinary
> |      punctuation, etc.  *Note Syntax::.
> |
> | `\SC'
> |      matches any character whose syntax is not C.
>
> `----
>
> So you must specify a syntax class `C', e.g. `w' for word constituent,
> `-' or ` ' for whitespace, `.' for ordinary punctuation, etc.
>
> But as there is no syntax class for printable or non-printable
> characters, that seems like a dead end.  But there is the [:print:]
> character class that you can use in regular expressions.
>
> And finally, all that limit-position/next-line/point/previous-line stuff
> can be replaced by line-end-position:
>
> (defun vb-first-printable ()
>    (interactive)
>    (beginning-of-line)
>    (re-search-forward "[[:print:]]" (line-end-position)))

  reply	other threads:[~2006-11-01 21:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.7939.1160429872.9609.help-gnu-emacs@gnu.org>
2006-10-10 12:51 ` Where is clipper.el's homepage today? greg.bognar
2006-10-17  7:37 ` Mathias Dahl
2006-11-01 19:31   ` Regular expression search vb
2006-11-01 20:04     ` Kevin Rodgers
2006-11-01 21:10       ` vb [this message]
2006-11-01 22:23         ` Edward O'Connor
2006-11-01 23:08           ` vb
2006-11-02 18:49         ` Kevin Rodgers

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=200611011310.59710.help-gnu-emacs@vsbe.com \
    --to=help-gnu-emacs@vsbe.com \
    --cc=ihs_4664@yahoo.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 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.