From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lister Account Newsgroups: gmane.emacs.help Subject: Re: conditional text insertion Date: Tue, 19 Jul 2011 02:57:53 -0700 Message-ID: References: <4E25313A.3080405@dogan.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0016364c723545a3a404a86926d2 X-Trace: dough.gmane.org 1311069598 10142 80.91.229.12 (19 Jul 2011 09:59:58 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 19 Jul 2011 09:59:58 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 19 11:59:52 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Qj75k-0006nn-GE for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jul 2011 11:59:52 +0200 Original-Received: from localhost ([::1]:51854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qj75j-0003j9-CR for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jul 2011 05:59:51 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:45011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qj73x-0003hx-2T for help-gnu-emacs@gnu.org; Tue, 19 Jul 2011 05:58:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qj73r-0000rB-Tg for help-gnu-emacs@gnu.org; Tue, 19 Jul 2011 05:58:00 -0400 Original-Received: from mail-ey0-f174.google.com ([209.85.215.174]:32998) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qj73r-0000r4-5M for help-gnu-emacs@gnu.org; Tue, 19 Jul 2011 05:57:55 -0400 Original-Received: by eyx24 with SMTP id 24so3817757eyx.19 for ; Tue, 19 Jul 2011 02:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=bRBC4amZFopOgK/nJ7UepXEYnqjWYXfw6i6h23Kz8Hk=; b=gljpxg3H2rIopVkzaoNd0K6H788eE8Z8b0MZ9EkHXcq7TS2LHkKvRR1kJSwZsk+g+0 c27r/aIkLe+uRakjZxu4mCnyAwPk29nSh47K69wPyJ2aIM3do5sdb1b2aqakDu064ITN wXalSAVptLgdcOqDbzE0ZyR+uwV8e5OaZIhM4= Original-Received: by 10.14.10.83 with SMTP id 59mr2717871eeu.154.1311069473972; Tue, 19 Jul 2011 02:57:53 -0700 (PDT) Original-Received: by 10.14.119.202 with HTTP; Tue, 19 Jul 2011 02:57:53 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.215.174 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:81672 Archived-At: --0016364c723545a3a404a86926d2 Content-Type: text/plain; charset=ISO-8859-1 by the way - for anybody reading the archives: I had to make a minor update to the code that Deniz provided: (defun hello-there () (interactive) (call-interactively 'move-end-of-line) (unless (looking-back ";") (insert ";")) (newline-and-indent)) I updated line 3 above because I was getting the error "Wrong Number of Arguments". A little googling led me to the solution. Thanks again! On Tue, Jul 19, 2011 at 1:54 AM, Lister Account wrote: > That's exactly what I was looking for. I'm only binding it in c-mode > derivatives, so mine looks like: > > (add-hook 'c-mode-common-hook 'my-cool-return) > > I hope that's OK. Seems to work, anyways. :) > > I very much appreciate the help. I'm slowly making the shift to emacs and > this kind of programmability really has me floored. > > On Tue, Jul 19, 2011 at 12:24 AM, Deniz Dogan wrote: > >> On 2011-07-19 07:47, Lister Account wrote: >> >>> I have a keybinding I just made that essentially will go to the end of a >>> line, insert a semicolon, return, and auto-indent. >>> >>> I'd like to only add the semicolon if it doesn't already exist. >>> >>> In other words, go to the end of the line, if a semicolon is there, >>> return. If a semicolon is not there, add one, then return. >>> >>> I'm brand spanking new to emacs, and I'm sure this is a task that others >>> have resolved, but I'm having trouble googling for a solution. >>> >>> Thanks, >>> Steve >>> >> >> (defun hello-there () >> (interactive) >> (move-end-of-line) >> (unless (looking-back ";") >> (insert ";")) >> (newline-and-indent)) >> >> Then you would want to bind this to only some modes, and not globally. >> E.g., this way: >> >> (add-hook 'prog-mode-hook >> (lambda () >> (local-set-key (kbd "C-c ;") 'hello-there))) >> >> This binds "C-c ;" to that command. >> >> Hope that helps, >> Deniz >> >> >> > --0016364c723545a3a404a86926d2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable by the way - for anybody reading the archives:

I had to make a minor= update to the code that Deniz provided:

(defun hello-there ()
=A0(interactive)
=A0(call-interactively 'move-end-of-line)
=A0(unless (looking-back ";")
=A0 =A0(insert ";"))
=A0(newline-and-indent))

I updated line 3 above because I was getti= ng the error "Wrong Number of Arguments".=A0 A little googling le= d me to the solution.

Thanks again!

On Tue, Jul 19, 2011 at 1:54 AM, Lister Account <lister345@gmail.com> wrote:=
That's exactly what I was looking for.=A0 I'm only binding it in c-= mode derivatives, so mine looks like:

(add-hook 'c-mode-common-h= ook 'my-cool-return)

I hope that's OK.=A0 Seems to work, any= ways. :)

I very much appreciate the help.=A0 I'm slowly making the shift to = emacs and this kind of programmability really has me floored.=A0
<= div>

On Tue, Jul 19, = 2011 at 12:24 AM, Deniz Dogan <deniz@dogan.se> wrote:
<= div>On 2011-07-19 07:47, Lister Account wrote:
I have a keybinding I just made that essentially will go to the end of a line, insert a semicolon, return, and auto-indent.

I'd like to only add the semicolon if it doesn't already exist.

In other words, go to the end of the line, if a semicolon is there,
return. =A0If a semicolon is not there, add one, then return.

I'm brand spanking new to emacs, and I'm sure this is a task that o= thers
have resolved, but I'm having trouble googling for a solution.

Thanks,
Steve

(defun hello-there ()
=A0(interactive)
=A0(move-end-of-line)
=A0(unless (looking-back ";")
=A0 =A0(insert ";"))
=A0(newline-and-indent))

Then you would want to bind this to only some modes, and not globally. E.g.= , this way:

(add-hook 'prog-mode-hook
=A0 =A0 =A0 =A0 =A0(lambda ()
=A0 =A0 =A0 =A0 =A0 =A0(local-set-key (kbd "C-c ;") 'hello-t= here)))

This binds "C-c ;" to that command.

Hope that helps,
Deniz




--0016364c723545a3a404a86926d2--