From: Ben Pfaff <blp@cs.stanford.edu>
Subject: Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY
Date: Fri, 08 Apr 2005 15:13:19 -0700 [thread overview]
Message-ID: <87u0mgex34.fsf@benpfaff.org> (raw)
In-Reply-To: 9on63d.36.ln@acm.acm
Alan Mackenzie <acm@muc.de> writes:
> o Do you program with auto-newline switched on (e.g. do you get NLs
> inserted automatically after typing a `;' or `{')?
Yes.
> o Did you configure this auto-newline setting yourself, and if not, are
> you happy with it?
Yes. I have some customization in my .emacs. I don't know elisp
well enough to tell whether this code entirely makes sense, but
it seems to do what I want:
;; Returns true if the last character typed by the user was a
;; semicolon. (This is a gross hack.)
(defun newline-if-semi ()
(= last-command-char ?\;))
...
;; My style for C, based on GNU style.
(defconst blp-c-style
...
;; Insert a newline after a typed semicolon if the line after this
;; one is blank and we're not inside a set of parentheses.
;; Never insert a newline after a comma.
(c-hanging-semi&comma-criteria . (c-semi&comma-no-newlines-before-nonblanks
c-semi&comma-inside-parenlist
newline-if-semi))
...
For what it's worth, I use this in conjunction with custom
keybindings to create and end {} blocks:
;; Simplifies braced blocks: just type M-{ at the beginning, type
;; some statements, type M-} to end it, and no need to worry about
;; anything else.
(local-set-key [?\M-{] 'insert-brace)
(local-set-key [?\M-}] 'move-past-brace-and-reindent)
;; Inserts a pair of braces {}, properly spacing them, and puts the
;; cursor between them.
(defun insert-brace ()
(interactive)
(setq last-command-event ?{)
(c-electric-brace nil)
(c-indent-line)
(save-excursion
(insert "\n\n}")
(c-indent-command)))
(defun move-past-brace-and-reindent ()
(interactive)
(delete-all-blank-lines)
(search-forward "}")
(let ((save-point))
(save-excursion
(insert "\n")
(c-indent-line)
(setq save-point (point)))
(funcall blink-paren-function)
(goto-char save-point)))
(defun delete-all-blank-lines ()
"Delete all surrounding blank lines."
(interactive "*")
(save-excursion
(beginning-of-line)
(if (looking-at "[ \t]*$")
(delete-region (if (re-search-backward "[^ \t\n]" nil t)
(progn (forward-line 1) (point))
(point-min))
(if (re-search-forward "[^ \t\n]" nil t)
(progn (beginning-of-line) (point))
(point-max))))))
> o Are you aware of the key binding C-c C-a to toggle this mode on and
> off?
Yes.
> o How often do you use C-c C-a (or even C-c C-t) to toggle auto-newline
> mode?
Hardly ever.
> o In which language(s) (C, C++, ....) do you program in (X)Emacs?
C mostly. Fairly often Perl, Bourne shell. Occasionally Java,
C++.
--
"Large amounts of money tend to quench any scruples I might be having."
-- Stephan Wilms
next prev parent reply other threads:[~2005-04-08 22:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-08 19:58 Emacs CC Mode's auto-newline facility: INFORMAL SURVEY Alan Mackenzie
2005-04-08 20:18 ` MSR
2005-04-08 20:31 ` William Hughes
2005-04-08 21:38 ` Aidan Kehoe
2005-04-08 22:11 ` Jonathan Arnold
2005-04-08 22:13 ` Ben Pfaff [this message]
2005-04-10 18:34 ` Eric Eide
2005-04-10 21:22 ` Vedat Hallac
2005-04-12 20:58 ` Alan Mackenzie
2005-04-13 8:03 ` Vedat Hallac
2005-04-11 6:39 ` Klaus Zeitler
2005-04-11 10:19 ` James
2005-04-12 21:12 ` Alan Mackenzie
2005-04-11 17:52 ` Robert Marshall
[not found] ` <9on63d.36.ln-Yd3Idk226uQ@public.gmane.org>
2005-04-11 20:51 ` Jochen Küpper
2005-04-12 11:47 ` Greg Rowe
2005-04-24 16:42 ` Emacs CC Mode's auto-newline facility: INFORMAL SURVEY RESULTS Alan Mackenzie
2005-04-25 2:37 ` Miles Bader
2005-04-25 8:21 ` Chris Croughton
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=87u0mgex34.fsf@benpfaff.org \
--to=blp@cs.stanford.edu \
/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.