* Problem positioning cursor
@ 2003-04-25 11:01 Victor Kirk
2003-04-25 12:27 ` Exception Handling in LISP Gurucharan
[not found] ` <mailman.5189.1051273202.21513.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 8+ messages in thread
From: Victor Kirk @ 2003-04-25 11:01 UTC (permalink / raw)
Hi,
I've wrote a function to insert a skeleton for a java try-catch
block, but I've run into a problem leaving the cursor in the
correct place.
If there is no active region I want the following code to be
inserted (note X marks the spot I want to leave the cursor at.
try {
X
} catch(Exception e) {
e.printStackTrace();
}
This works fine.
If there is code selected I want:
try {
someCode(toBeWrapped);
} catch(Exception e) {
e.printStackTrace();
X
}
unfortunatly the cursor is left at the `n' in Exception.
If anyone has the time to point me in the right direction
it would be appreciated.
(defun vics-java-catch-insert(&optional has-finally)
"Generate a skeleton for a java try-catch block. If the optional
has-finally is true then a finally block is also inserted."
(interactive)
(let ((ex-type (read-from-minibuffer "Exception Type: " "Exception" nil
nil nil nil nil))
(try-start) ;; start of try catch block
(try-end) ;; end of
(try-body nil) ;; code to insert within try/catch
(edit-point)) ;; point to leave user at
;; If a region is selected save this to try-body
(if (c-region-is-active-p)
(setq try-body (delete-and-extract-region (mark) (point))))
(setq try-start (point))
(insert "try {\n")
(if (not try-body)
(setq edit-point (point))
(insert try-body))
(insert (format "\n} catch (%s e) {\n" ex-type))
(insert "e.printStackTrace();\n")
;; if we had some text leave save location at the end of the catch
;; block
(if (eq nil (not try-body))
(setq edit-point (point)))
(insert "}") ;
(if (eq nil (not has-finally))
(insert " finally {\n\n}"))
(setq try-end (point))
(indent-region try-start try-end nil)
(goto-char edit-point)
(c-indent-command)))
Vic
--
Victor Kirk
Analyst
Serco Integrated Transport
--
This message, including attachments, is intended only for the use by the
person(s) to whom it is addressed. It may contain information which is
privileged and confidential. Copying or use by anybody else is not
authorised. If you are not the intended recipient, please contact the sender
as soon as possible. The views expressed in this communication may not
necessarily be the views held by Serco Integrated Transport.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Exception Handling in LISP.
2003-04-25 11:01 Problem positioning cursor Victor Kirk
@ 2003-04-25 12:27 ` Gurucharan
[not found] ` <mailman.5189.1051273202.21513.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 8+ messages in thread
From: Gurucharan @ 2003-04-25 12:27 UTC (permalink / raw)
[-- Attachment #1.1: Type: text/plain, Size: 421 bytes --]
Hi All,
Can we catch any unknown exception in Lisp like C++ ?
That is, like the C++ ... (Epsilon code).
can we catch any exception irrespective of which
exception was thrown ?
Example:
try {
// Something ....
}
catch (...) { // Do something after Exception has occurred ...
}
Any material/links on Exception Handling in LISP
is welcome.
Thanks.
Kind Regards,
gurucharan
[-- Attachment #1.2: Type: text/html, Size: 945 bytes --]
[-- Attachment #2: Type: text/plain, Size: 151 bytes --]
_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/help-gnu-emacs
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Exception Handling in LISP.
[not found] ` <mailman.5189.1051273202.21513.help-gnu-emacs@gnu.org>
@ 2003-04-25 13:25 ` David Kastrup
2003-04-25 14:10 ` Kai Großjohann
1 sibling, 0 replies; 8+ messages in thread
From: David Kastrup @ 2003-04-25 13:25 UTC (permalink / raw)
Gurucharan <gurucharan.murudeshwar@wipro.com> writes:
> Hi All,
> Can we catch any unknown exception in Lisp like C++ ?
>
> That is, like the C++ ... (Epsilon code).
> can we catch any exception irrespective of which
> exception was thrown ?
>
> Example:
> try {
> // Something ....
> }
> catch (...) { // Do something after Exception has occurred ...
> }
>
> Any material/links on Exception Handling in LISP
> is welcome.
Take a look at catch, throw, condition-case and unwind-protect in the
Elisp manual.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Exception Handling in LISP.
[not found] ` <mailman.5189.1051273202.21513.help-gnu-emacs@gnu.org>
2003-04-25 13:25 ` David Kastrup
@ 2003-04-25 14:10 ` Kai Großjohann
1 sibling, 0 replies; 8+ messages in thread
From: Kai Großjohann @ 2003-04-25 14:10 UTC (permalink / raw)
Gurucharan <gurucharan.murudeshwar@wipro.com> writes:
> Can we catch any unknown exception in Lisp like C++ ?
Emacs Lisp has throw/catch and signal/condition-case. I guess
signal/condition-case is more like what you want, since errors are a
special kind of signal.
Both provide ways to just `catch everything'.
--
file-error; Data: (Opening input file no such file or directory ~/.signature)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem positioning cursor
[not found] <mailman.5188.1051270162.21513.help-gnu-emacs@gnu.org>
@ 2003-04-26 14:06 ` Kai Großjohann
2003-04-26 15:24 ` Oliver Scholz
0 siblings, 1 reply; 8+ messages in thread
From: Kai Großjohann @ 2003-04-26 14:06 UTC (permalink / raw)
Victor Kirk <Victor.Kirk@serco.com> writes:
> I've wrote a function to insert a skeleton for a java try-catch
> block, but I've run into a problem leaving the cursor in the
> correct place.
First of all, maybe you want to use skeletons rather than hand-coding
everything. It will be easier to understand.
I think that skeletons can't do what you need, though. There is a
change that adds the capability you need which has been committed to
the development release of Emacs in the last couple of days, or which
will be committed soon.
However, maybe you want to read up on skeletons anyway -- they might
come in useful for other things you are doing.
Failing the use of skeletons, a technique I suggest to use for the
hand-written functions is save-excursion. For example, here is
something that inserts foo() and leaves point inside the parentheses:
(insert "foo(")
(save-excursion
(insert ")")
I think you will find this much easier to understand that your
hand-coded remembering of positions, and thus it will be easier to
find the bugs.
--
file-error; Data: (Opening input file no such file or directory ~/.signature)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem positioning cursor
2003-04-26 14:06 ` Problem positioning cursor Kai Großjohann
@ 2003-04-26 15:24 ` Oliver Scholz
2003-04-27 11:47 ` Kai Großjohann
0 siblings, 1 reply; 8+ messages in thread
From: Oliver Scholz @ 2003-04-26 15:24 UTC (permalink / raw)
kai.grossjohann@gmx.net (Kai Großjohann) writes:
[...]
> I think that skeletons can't do what you need, though. There is a
> change that adds the capability you need which has been committed to
> the development release of Emacs in the last couple of days, or which
> will be committed soon.
It should be possible even in Emacs 21.2. If you use something like
("lirum" _ "larum" _ "schubi"), then point is put at the first "_",
unless that is consumed (so to say) for the region.
Hmmm ...
(define-skeleton vics-java-catch-insert
"Generate a skeleton for a java try-catch block."
nil
"try {" \n
> _ \n
> "} catch(Exception e) {" \n
> "e.printStackTrace();" \n
> _
> "}" \n)
Oliver
--
7 Floréal an 211 de la Révolution
Liberté, Egalité, Fraternité!
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem positioning cursor
2003-04-26 15:24 ` Oliver Scholz
@ 2003-04-27 11:47 ` Kai Großjohann
2003-04-27 12:40 ` Oliver Scholz
0 siblings, 1 reply; 8+ messages in thread
From: Kai Großjohann @ 2003-04-27 11:47 UTC (permalink / raw)
Oliver Scholz <alkibiades@gmx.de> writes:
> It should be possible even in Emacs 21.2. If you use something like
> ("lirum" _ "larum" _ "schubi"), then point is put at the first "_",
> unless that is consumed (so to say) for the region.
But the OP wants point to end up at the _second_ spot.
Hm.
Oh, are you saying that, if the region is active, then it gets put at
the first spot, and point at the second? That'd work, then.
--
file-error; Data: (Opening input file no such file or directory ~/.signature)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem positioning cursor
2003-04-27 11:47 ` Kai Großjohann
@ 2003-04-27 12:40 ` Oliver Scholz
0 siblings, 0 replies; 8+ messages in thread
From: Oliver Scholz @ 2003-04-27 12:40 UTC (permalink / raw)
kai.grossjohann@gmx.net (Kai Großjohann) writes:
[...]
> Oh, are you saying that, if the region is active, then it gets put at
> the first spot, and point at the second? That'd work, then.
[...]
Yes.
Oliver
--
8 Floréal an 211 de la Révolution
Liberté, Egalité, Fraternité!
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2003-04-27 12:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-25 11:01 Problem positioning cursor Victor Kirk
2003-04-25 12:27 ` Exception Handling in LISP Gurucharan
[not found] ` <mailman.5189.1051273202.21513.help-gnu-emacs@gnu.org>
2003-04-25 13:25 ` David Kastrup
2003-04-25 14:10 ` Kai Großjohann
[not found] <mailman.5188.1051270162.21513.help-gnu-emacs@gnu.org>
2003-04-26 14:06 ` Problem positioning cursor Kai Großjohann
2003-04-26 15:24 ` Oliver Scholz
2003-04-27 11:47 ` Kai Großjohann
2003-04-27 12:40 ` Oliver Scholz
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.