* Indentation varies for .cc and .cpp
@ 2006-09-27 7:39 Eric Lilja
2006-09-27 21:30 ` Eric Lilja
0 siblings, 1 reply; 3+ messages in thread
From: Eric Lilja @ 2006-09-27 7:39 UTC (permalink / raw)
Hello, I'm trying to construct .emacs-file to be used in a course. The
emacs version in question is 21.4.1. I haven't written the original
.emacs file but I've made a few changes to it based on student input.
The course is a C++ course and some of the student use .cc to denote to
C++ files, some use .cpp. We want placement of {} to be aligned with
their opening clause:
if(some_condition)
{
// code here
}
for(...)
{
// code here
}
etc...emacs does this for files ending in .cpp, but for files ending in
.cc it indents the {} themselves so we get
if(some_condition)
{
// code
}
Why and how do I change this behaviour?
Here's the .emacs-file:
(setq default-major-mode 'text-mode)
(setq require-final-newline 1)
(setq inhibit-startup-message t)
(put 'downcase-region 'disabled nil)
(setq version-control t)
(setq backup-by-copying t)
(setq backup-by-copying-when-linked t)
(setq backup-by-copying-when-mismatch t)
(setq kept-new-versions 99)
(setq kept-old-versions 0)
(setq delete-auto-save-files t)
(setq trim-versions-without-asking t)
(global-set-key "\C-X\C-s"
'(lambda () (interactive) (save-buffer 16)))
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(set-language-environment "Latin-1")
(set-terminal-coding-system 'latin-1)
(setq scroll-bar-mode-explicit t)
(set-scroll-bar-mode 'right)
(set-background-color "White")
(set-foreground-color "Black")
(set-cursor-color "Black")
(custom-set-variables)
(custom-set-faces
'(font-lock-comment-face ((((class color) (background light))
(:italic t :foreground "Firebrick"))))
'(font-lock-function-name-face ((((class color) (background light))
(:bold t :foreground "Blue"))))
'(font-lock-keyword-face ((((class color) (background light))
(:bold t :foreground "Black"))))
'(font-lock-string-face ((((class color) (background light))
(:italic t :foreground "ForestGreen"))))
'(font-lock-type-face ((((class color) (background light))
(:foreground "Blue"))))
'(font-lock-variable-name-face ((((class color) (background light))
(:foreground "Black"))))
'(font-lock-reference-face ((((class color) (background light))
(:foreground "ForestGreen")))))
(transient-mark-mode t)
(show-paren-mode 1)
(setq next-line-add-newlines nil)
(setq line-number-mode t)
(setq column-number-mode t)
(setq-default indent-tabs-mode nil)
(setq c-basic-offset 3)
(setq display-time-day-and-date t)
(setq display-time-24hr-format t)
(display-time)
(if (eq window-system 'x)
(pc-selection-mode))
(if (string-match "^21" emacs-version)
(progn
(tool-bar-mode -1)
(blink-cursor-mode -1)))
(setq foo (global-key-binding "\C-m"))
(global-set-key "\C-m" (global-key-binding "\C-j"))
(global-set-key "\C-j" foo)
(global-set-key [f4] 'menu-bar-mode)
(global-set-key [f5] 'toggle-truncate-lines)
(add-to-list 'auto-mode-alist '("\\.h$" . c++-mode))
;;(setq c-default-style "stroustrup")
(setq c-default-style "ellemtel")
I stripped out comments in swedish manually so they don't distract,
hope I didn't remove any non-comments by mistake (a command to that
gratefully accepted).
/ E
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Indentation varies for .cc and .cpp
2006-09-27 7:39 Indentation varies for .cc and .cpp Eric Lilja
@ 2006-09-27 21:30 ` Eric Lilja
2006-10-11 11:41 ` Sam Peterson
0 siblings, 1 reply; 3+ messages in thread
From: Eric Lilja @ 2006-09-27 21:30 UTC (permalink / raw)
Eric Lilja skrev:
> Hello, I'm trying to construct .emacs-file to be used in a course. The
> emacs version in question is 21.4.1. I haven't written the original
> .emacs file but I've made a few changes to it based on student input.
> The course is a C++ course and some of the student use .cc to denote to
> C++ files, some use .cpp. We want placement of {} to be aligned with
> their opening clause:
> if(some_condition)
> {
> // code here
> }
>
> for(...)
> {
> // code here
> }
>
> etc...emacs does this for files ending in .cpp, but for files ending in
> .cc it indents the {} themselves so we get
> if(some_condition)
> {
> // code
> }
> Why and how do I change this behaviour?
>
> Here's the .emacs-file:
>
> (setq default-major-mode 'text-mode)
> (setq require-final-newline 1)
> (setq inhibit-startup-message t)
> (put 'downcase-region 'disabled nil)
>
>
> (setq version-control t)
> (setq backup-by-copying t)
> (setq backup-by-copying-when-linked t)
> (setq backup-by-copying-when-mismatch t)
> (setq kept-new-versions 99)
> (setq kept-old-versions 0)
> (setq delete-auto-save-files t)
> (setq trim-versions-without-asking t)
> (global-set-key "\C-X\C-s"
> '(lambda () (interactive) (save-buffer 16)))
>
>
> (global-font-lock-mode t)
> (setq font-lock-maximum-decoration t)
>
>
> (set-language-environment "Latin-1")
> (set-terminal-coding-system 'latin-1)
>
>
> (setq scroll-bar-mode-explicit t)
> (set-scroll-bar-mode 'right)
>
>
> (set-background-color "White")
> (set-foreground-color "Black")
> (set-cursor-color "Black")
>
>
> (custom-set-variables)
> (custom-set-faces
> '(font-lock-comment-face ((((class color) (background light))
> (:italic t :foreground "Firebrick"))))
> '(font-lock-function-name-face ((((class color) (background light))
> (:bold t :foreground "Blue"))))
> '(font-lock-keyword-face ((((class color) (background light))
> (:bold t :foreground "Black"))))
> '(font-lock-string-face ((((class color) (background light))
> (:italic t :foreground "ForestGreen"))))
> '(font-lock-type-face ((((class color) (background light))
> (:foreground "Blue"))))
> '(font-lock-variable-name-face ((((class color) (background light))
> (:foreground "Black"))))
> '(font-lock-reference-face ((((class color) (background light))
> (:foreground "ForestGreen")))))
>
>
> (transient-mark-mode t)
>
>
> (show-paren-mode 1)
>
>
> (setq next-line-add-newlines nil)
> (setq line-number-mode t)
> (setq column-number-mode t)
> (setq-default indent-tabs-mode nil)
> (setq c-basic-offset 3)
> (setq display-time-day-and-date t)
> (setq display-time-24hr-format t)
> (display-time)
>
>
> (if (eq window-system 'x)
> (pc-selection-mode))
>
>
> (if (string-match "^21" emacs-version)
> (progn
> (tool-bar-mode -1)
> (blink-cursor-mode -1)))
>
>
> (setq foo (global-key-binding "\C-m"))
> (global-set-key "\C-m" (global-key-binding "\C-j"))
> (global-set-key "\C-j" foo)
>
>
> (global-set-key [f4] 'menu-bar-mode)
>
> (global-set-key [f5] 'toggle-truncate-lines)
>
> (add-to-list 'auto-mode-alist '("\\.h$" . c++-mode))
>
> ;;(setq c-default-style "stroustrup")
>
> (setq c-default-style "ellemtel")
>
>
> I stripped out comments in swedish manually so they don't distract,
> hope I didn't remove any non-comments by mistake (a command to that
> gratefully accepted).
>
> / E
Sorry for this shameless bump, but do anyone have any ideas at all?
Since it's for a large number of students I would really like to fix
this so they can use .cc or .cpp and still get proper indentation. We
run solaris at the labs and as I mentioned emacs is version 21.4.1. I
dont see this problem with the same .emacs file on my laptop running a
recent cvs checkout of emacs.
/ E
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Indentation varies for .cc and .cpp
2006-09-27 21:30 ` Eric Lilja
@ 2006-10-11 11:41 ` Sam Peterson
0 siblings, 0 replies; 3+ messages in thread
From: Sam Peterson @ 2006-10-11 11:41 UTC (permalink / raw)
"Eric Lilja" <mindcooler@gmail.com> writes:
> Eric Lilja skrev:
>
> Sorry for this shameless bump, but do anyone have any ideas at all?
> Since it's for a large number of students I would really like to fix
> this so they can use .cc or .cpp and still get proper indentation. We
> run solaris at the labs and as I mentioned emacs is version 21.4.1. I
> dont see this problem with the same .emacs file on my laptop running a
> recent cvs checkout of emacs.
(add-hook c-mode-common-hook
(lambda ()
(c-set-offset 'substatement-open 0)
(c-set-offset 'defun-open 0)))
--
Sam Peterson
skpeterson AT nospam ucdavis.edu
"if programmers were paid to remove code instead of adding it,
software would be much better" -- unknown
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-10-11 11:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-27 7:39 Indentation varies for .cc and .cpp Eric Lilja
2006-09-27 21:30 ` Eric Lilja
2006-10-11 11:41 ` Sam Peterson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).