From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?B?QW5kcmVhcyBSw7ZobGVy?= Newsgroups: gmane.emacs.help Subject: Re: Wrapping code in a try/except Date: Sat, 20 Nov 2010 18:11:14 +0100 Message-ID: <4CE80132.10009@easy-emacs.de> References: <4CD13E95.3040808@easy-emacs.de> <4CE6C190.8040007@easy-emacs.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1290272764 28000 80.91.229.12 (20 Nov 2010 17:06:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 20 Nov 2010 17:06:04 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 20 18:06:00 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PJqsy-0005Xp-1G for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Nov 2010 18:06:00 +0100 Original-Received: from localhost ([127.0.0.1]:53209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PJqsr-0001nw-Tf for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Nov 2010 12:05:54 -0500 Original-Received: from [140.186.70.92] (port=54710 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PJqp6-0000Vi-9E for help-gnu-emacs@gnu.org; Sat, 20 Nov 2010 12:02:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PJqp4-0000PD-VB for help-gnu-emacs@gnu.org; Sat, 20 Nov 2010 12:02:00 -0500 Original-Received: from moutng.kundenserver.de ([212.227.17.8]:64828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PJqp2-0000O2-W2 for help-gnu-emacs@gnu.org; Sat, 20 Nov 2010 12:01:58 -0500 Original-Received: from [192.168.178.29] (brln-4dbc7de7.pool.mediaWays.net [77.188.125.231]) by mrelayeu.kundenserver.de (node=mrbap0) with ESMTP (Nemesis) id 0MgYIJ-1P4dMM3sVL-00O3UM; Sat, 20 Nov 2010 18:01:54 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6 In-Reply-To: X-Provags-ID: V02:K0:Ixf5nfBl3sgte6k4EP5scuszUzpv8uHTf/bHNg6JdbO OsaT8B55B9CK+xfp1cxYrkyKn7DGEnBQXSaqQ7SalXfz16nvov I5Ge/zwaLVqAdtQeX/QMxE2ExBpb4MVFq1MPk2YvsOcVsZZYEs orylnS1wJ45HJnwxs8YpSRNPyqkKX1OiRwALcwhAlZkyNQevik y2zyVA+em5cbximjUBOanK7YHUicczTUX23AisNQ5g= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:75413 Archived-At: Am 19.11.2010 21:50, schrieb Andrea Crotti: > Andreas Röhler writes: > >> it's not automatically >>> indented in the rest of the C++ code... >>> >> >> Write a function based on `indent-region' with reasonable defaults -- >> function-beginnning-pos, point. >> >> Make it run with an idle-timer like fontifying does. >> >> Could be a feature request if not existing already. > > Well in theory something like that would be perfect reading what those > things should do: > > --8<---------------cut here---------------start------------->8--- > (defun re-indent-buffer () > "reindent the whole buffer" > (indent-region yas/snippet-beg yas/snippet-end)) > > (add-hook 'yas/after-exit-snippet-hook 're-indent-buffer) > --8<---------------cut here---------------end--------------->8--- > > in practice I guess there are some problems since now I have to force > the exit of the snippet instead, so it doens't work at all... > > > below an example, how I would approach the issue (must not be the best way, just for discussion...) It takes a little bit more code. Yasnippet seems not designed for use from programms. ;;;; (defun my-try-wrap-function (beg end) (interactive "r*") (my-wrap-function-base beg end "try {\n" "\n} except")) (defun my-wrap-function-base (beg end &optional before after) " " (let ((end (copy-marker end))) (my-wrap-function-intern beg end before after))) (defun my-wrap-function-intern (beg end &optional before after) (goto-char beg) (when before (insert before)) (goto-char end) (when after (insert after)) (indent-region beg end) (beginning-of-line) (indent-according-to-mode)) BTW the second function might be used to cover default arguments in other cases like this: (let ((beg (cond (beg) ((region-active-p) (region-beginning)) ((bobp) (point)) (t (defun-beginning-position)))) (end (cond (end) ((region-active-p) (copy-marker (region-end))) ((eobp) (point)) (t (defun-end-position)))) so I use this step, which might be omitted here. happy hacking Andreas