all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lister Account <lister345@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: conditional text insertion
Date: Tue, 19 Jul 2011 02:57:53 -0700	[thread overview]
Message-ID: <CAPj0jr8Kak80FOfbpKjgKx2guO+vTzyVqph0Gy_J3mhtx+tttA@mail.gmail.com> (raw)
In-Reply-To: <CAPj0jr90DNMs92rkwkzNTQAWXvD+8uTBtzDaVEtEgE-EcuUOfQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1907 bytes --]

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 <lister345@gmail.com> 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 <deniz@dogan.se> 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
>>
>>
>>
>

[-- Attachment #2: Type: text/html, Size: 2935 bytes --]

  reply	other threads:[~2011-07-19  9:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-19  5:47 conditional text insertion Lister Account
2011-07-19  7:24 ` Deniz Dogan
2011-07-19  8:54   ` Lister Account
2011-07-19  9:57     ` Lister Account [this message]
2011-07-19 14:02       ` Memnon Anon
2011-07-19 17:40         ` Lister Account
2011-07-19 10:02     ` Deniz Dogan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPj0jr8Kak80FOfbpKjgKx2guO+vTzyVqph0Gy_J3mhtx+tttA@mail.gmail.com \
    --to=lister345@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.