From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Deniz Dogan Newsgroups: gmane.emacs.help Subject: Re: conditional text insertion Date: Tue, 19 Jul 2011 12:02:37 +0200 Message-ID: <4E25563D.1010603@dogan.se> References: <4E25313A.3080405@dogan.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1311069909 12087 80.91.229.12 (19 Jul 2011 10:05:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 19 Jul 2011 10:05:09 +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 12:05:06 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 1Qj7Ak-0000Yk-Hy for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jul 2011 12:05:02 +0200 Original-Received: from localhost ([::1]:41965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qj7Ai-0004lu-UV for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jul 2011 06:05:00 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:38059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qj790-0004kt-5O for help-gnu-emacs@gnu.org; Tue, 19 Jul 2011 06:03:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qj78w-0001tl-7w for help-gnu-emacs@gnu.org; Tue, 19 Jul 2011 06:03:14 -0400 Original-Received: from ch-smtp04.sth.basefarm.net ([80.76.153.5]:47467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qj78v-0001tR-Nd for help-gnu-emacs@gnu.org; Tue, 19 Jul 2011 06:03:10 -0400 Original-Received: from c80-216-105-155.bredband.comhem.se ([80.216.105.155]:56228 helo=[192.168.0.10]) by ch-smtp04.sth.basefarm.net with esmtp (Exim 4.76) (envelope-from ) id 1Qj78W-0001Wd-Fo for help-gnu-emacs@gnu.org; Tue, 19 Jul 2011 12:02:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: X-Originating-IP: 80.216.105.155 X-Scan-Result: No virus found in message 1Qj78W-0001Wd-Fo. X-Scan-Signature: ch-smtp04.sth.basefarm.net 1Qj78W-0001Wd-Fo 573db6baadcbc07a43d2c660dc1f4251 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.76.153.5 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:81673 Archived-At: On 2011-07-19 10:54, 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. > I'm glad you're taking the programmability aspect into account on your journey into Emacs. I've seen way too many new users be appalled by things such as when they ask "how do I paste a line 1000 times" and they get an answer along the lines of C-x ( C-y C-x ) C-u 999 C-x e. If anyone is not okay with that behavior, it's so easy to change it. As a matter of fact, I think I'm going to change that behavior right away... > 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 > > >