[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY
From: |
Ben Pfaff |
Subject: |
Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY |
Date: |
Fri, 08 Apr 2005 15:13:19 -0700 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
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
- Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, Alan Mackenzie, 2005/04/08
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, MSR, 2005/04/08
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, William Hughes, 2005/04/08
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, Jonathan Arnold, 2005/04/08
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY,
Ben Pfaff <=
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, Aidan Kehoe, 2005/04/09
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, Eric Eide, 2005/04/10
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, Vedat Hallac, 2005/04/10
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, Klaus Zeitler, 2005/04/11
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, James, 2005/04/11
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, Robert Marshall, 2005/04/11
- Re: Emacs CC Mode's auto-newline facility: INFORMAL SURVEY, Jochen Küpper, 2005/04/11