From: Deniz Dogan <deniz@dogan.se>
To: help-gnu-emacs@gnu.org
Subject: Re: conditional text insertion
Date: Tue, 19 Jul 2011 12:02:37 +0200 [thread overview]
Message-ID: <4E25563D.1010603@dogan.se> (raw)
In-Reply-To: <CAPj0jr90DNMs92rkwkzNTQAWXvD+8uTBtzDaVEtEgE-EcuUOfQ@mail.gmail.com>
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 <deniz@dogan.se
> <mailto: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
>
>
>
prev parent reply other threads:[~2011-07-19 10:02 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
2011-07-19 14:02 ` Memnon Anon
2011-07-19 17:40 ` Lister Account
2011-07-19 10:02 ` Deniz Dogan [this message]
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=4E25563D.1010603@dogan.se \
--to=deniz@dogan.se \
--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.