[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: conditional text insertion

From: Lister Account
Subject: Re: conditional text insertion
Date: Tue, 19 Jul 2011 02:57:53 -0700

by the way - for anybody reading the archives:

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

(defun hello-there ()
 (call-interactively 'move-end-of-line)
 (unless (looking-back ";")
   (insert ";"))

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 <address@hidden> 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 <address@hidden> 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.


(defun hello-there ()
 (unless (looking-back ";")
   (insert ";"))

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,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]