From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Victor Kirk Newsgroups: gmane.emacs.help Subject: Problem positioning cursor Date: Fri, 25 Apr 2003 12:01:26 +0100 Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <195F58F118C9D311B622009027DC812F017C1328@mail1.technology.serco.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: main.gmane.org 1051270583 27048 80.91.224.249 (25 Apr 2003 11:36:23 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 25 Apr 2003 11:36:23 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Fri Apr 25 13:36:19 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1991V4-00071s-00 for ; Fri, 25 Apr 2003 13:36:19 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 1991OR-0006w2-06 for gnu-help-gnu-emacs@m.gmane.org; Fri, 25 Apr 2003 07:29:27 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 1991Ch-0002JI-00 for help-gnu-emacs@gnu.org; Fri, 25 Apr 2003 07:17:19 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19918k-0001Zc-00 for help-gnu-emacs@gnu.org; Fri, 25 Apr 2003 07:13:14 -0400 Original-Received: from ns.serco.com ([195.50.81.244] helo=pig.serco.com) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 1990x1-0007sQ-00 for help-gnu-emacs@gnu.org; Fri, 25 Apr 2003 07:01:07 -0400 Original-Received: from [10.22.1.247] (helo=mail1.technology.serco.com) by pig.serco.com with esmtp (Exim 4.12) id 1990wu-0006OO-02 for help-gnu-emacs@gnu.org; Fri, 25 Apr 2003 12:01:01 +0100 Original-Received: by mail1.technology.serco.com with Internet Mail Service (5.5.2650.21) id ; Fri, 25 Apr 2003 12:01:29 +0100 Original-To: "'help-gnu-emacs@gnu.org'" X-Mailer: Internet Mail Service (5.5.2650.21) X-Scanner: exiscan for exim4 (http://duncanthrax.net/exiscan/) *1990wu-0006OO-02*knlbQFQ0DLs* X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:8809 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:8809 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.