From: Deniz Dogan <deniz@dogan.se>
To: help-gnu-emacs@gnu.org
Subject: Re: conditional text insertion
Date: Tue, 19 Jul 2011 09:24:42 +0200 [thread overview]
Message-ID: <4E25313A.3080405@dogan.se> (raw)
In-Reply-To: <CAPj0jr8Anc2Xi+ycC2a8bNm9K9ky63Vbz5+Hq1QRy9jiQEC0cw@mail.gmail.com>
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
next prev parent reply other threads:[~2011-07-19 7:24 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 [this message]
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
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=4E25313A.3080405@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.