all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: How to structure looking-at with error conditions
       [not found] <fe88468f-9fac-423b-baac-d39d1bd46f75@z9g2000yqz.googlegroups.com>
@ 2010-11-24 13:33 ` Barry Margolin
  2010-11-24 17:44 ` bolega
  1 sibling, 0 replies; 2+ messages in thread
From: Barry Margolin @ 2010-11-24 13:33 UTC (permalink / raw)
  To: help-gnu-emacs

In article 
<fe88468f-9fac-423b-baac-d39d1bd46f75@z9g2000yqz.googlegroups.com>,
 Fren Zeee <frenzeee@gmail.com> wrote:

> hello emacs users
> 
> generally, i use looking-at as follows
> 
> (when (looking-at "desired_pattern")
>         ( do_this_and_that
> 
>        (do some more things)
> 
> (when (looking-at "anther_ desired_pattern")
>         ( do_this_and_that)
> )
> 
> )
> 
> whats your expert advice on how to modify if the cursor is not at the
> desired pattern in either case so that an error message is reported ?
> 
> should I wrap the looking-at in cond or can I add some kind of default
> ie else like functioning clause to when ?
> 
> Franz Xe

Use the more general cond:

(cond ((looking-at "pattern1")
       (do-first-stuff))
      ((looking-at "pattern2")
       (do-other-stuff))
      (t (error ...)))

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to structure looking-at with error conditions
       [not found] <fe88468f-9fac-423b-baac-d39d1bd46f75@z9g2000yqz.googlegroups.com>
  2010-11-24 13:33 ` How to structure looking-at with error conditions Barry Margolin
@ 2010-11-24 17:44 ` bolega
  1 sibling, 0 replies; 2+ messages in thread
From: bolega @ 2010-11-24 17:44 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: bolega

Barry has explained quite well.

when and cond have different sets of parentheses also. The bare
structure is below :

(when test1 action1)

(cond (test1 action1) (test2 action2) (t default))

If each of the test is like this

(looking-at "regexp1")

then you have two adjacent parens in cond while no adjacent parens in
when.

Similarly, if your action is like this

(setq var1 "string1")

then you have to adjacent parens after "string1"

Hence, the indentation is best done while keeping two adjacent parens
together.

(cond () () ) is more general but not the most readable unless some of
these indentation rules are followed which dont occur in (when).

Bolega



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-11-24 17:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <fe88468f-9fac-423b-baac-d39d1bd46f75@z9g2000yqz.googlegroups.com>
2010-11-24 13:33 ` How to structure looking-at with error conditions Barry Margolin
2010-11-24 17:44 ` bolega

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.