help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: conditional text insertion


From: Deniz Dogan
Subject: Re: conditional text insertion
Date: Tue, 19 Jul 2011 12:02:37 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0

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







reply via email to

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