unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* mark-sexp signals "Containing expression ends prematurely"
@ 2006-08-30 12:47 Florian Kaufmann
  2006-08-30 14:14 ` rgb
  2006-08-30 15:23 ` Drew Adams
  0 siblings, 2 replies; 3+ messages in thread
From: Florian Kaufmann @ 2006-08-30 12:47 UTC (permalink / raw)


Hello

I'm trying to write a defun which which takes point or the current
region and extends the region at both side by an sexp. This is what I
wrote so far

(defun mark-whole-sexp ()
  (interactive)
  (if (region-exists-p) (if (> (point) (mark))
(exchange-point-and-mark)))
  (mark-sexp -1)
  (exchange-point-and-mark)
  (mark-sexp 1))

I intend to use it in c++ source files, so c++ minor mode (from cc mode
package) is enabled.

However if point or mark bump into a curly brace, that is { or },
mark-sexp signal the "Containing expression ends prematurely" error.
What I want to do in this case is that the region should extend only on
the other side until the whole { } bock is in the region. If I then
call mark-whole-sexp again, the region should extend again around the
sexp preceding and following the block { }.

Has somebody any ideas? Of course I don't expect a final solution, I'm
happy if you can direct me to the right functions I have to use, which
help I then can look up myself.

Thank you

Flo

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

* Re: mark-sexp signals "Containing expression ends prematurely"
  2006-08-30 12:47 mark-sexp signals "Containing expression ends prematurely" Florian Kaufmann
@ 2006-08-30 14:14 ` rgb
  2006-08-30 15:23 ` Drew Adams
  1 sibling, 0 replies; 3+ messages in thread
From: rgb @ 2006-08-30 14:14 UTC (permalink / raw)


> However if point or mark bump into a curly brace, that is { or },
> mark-sexp signal the "Containing expression ends prematurely" error.
> What I want to do in this case is that the region should extend only on
> the other side until the whole { } bock is in the region.

You want to surround the expression signaling the error with the
(in my opinion, unintuitively named) condition-case statement.
That will give control back to your function when the error occurs.
You can then take a different action like backward-up-list or
down-list.

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

* RE: mark-sexp signals "Containing expression ends prematurely"
  2006-08-30 12:47 mark-sexp signals "Containing expression ends prematurely" Florian Kaufmann
  2006-08-30 14:14 ` rgb
@ 2006-08-30 15:23 ` Drew Adams
  1 sibling, 0 replies; 3+ messages in thread
From: Drew Adams @ 2006-08-30 15:23 UTC (permalink / raw)


    I'm trying to write a defun which which takes point or the current
    region and extends the region at both side by an sexp.

Take a look at the commands and functions in library thing-cmds.el, here:
http://www.emacswiki.org/cgi-bin/wiki/thing-cmds.el. The doc is here:
http://www.emacswiki.org/cgi-bin/wiki/ThingAtPointCommands.

>From your description, it sounds like they might provide what you are
looking for.

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

end of thread, other threads:[~2006-08-30 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-30 12:47 mark-sexp signals "Containing expression ends prematurely" Florian Kaufmann
2006-08-30 14:14 ` rgb
2006-08-30 15:23 ` Drew Adams

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).