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!
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:
(defun hello-there ()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
(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