.emacs

From opm
Jump to: navigation, search
;; No tabs in files!
(setq indent-tabs-mode nil)

;; Use c++-mode for .h files
(setq auto-mode-alist (cons '("\\.h\\'" . c++-mode) auto-mode-alist))

;; Use font-lock-mode when in most modes
(global-font-lock-mode t)

;; Use 4 spaces for indentation
(add-hook 'c++-mode-hook
          (lambda ()
            (setq c-basic-offset 4)))
(add-hook 'c-mode-hook
          (lambda ()
            (setq c-basic-offset 4)))



;;
;; Automatic copyright header generation for C++ files
;;
(add-hook 'c++-mode-hook
          (lambda ()
            (set 'headername (upcase (concat "OPM_"
                                     (substring
                                      (file-name-nondirectory buffer-file-name)
                                      0
                                      (string-match
                                       "\\.hp*$"
                                       (file-name-nondirectory buffer-file-name)))
                                     "_HEADER_INCLUDED")))

            (local-set-key  "\C-c\C-c" 'compile)
            (cond ((not (file-exists-p (buffer-file-name)))
                   (insert-string
                    (concat
"/*
  Copyright " (format-time-string "%Y") " <Insert your organization or name here>.

  This file is part of the Open Porous Media project (OPM).

  OPM is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  OPM is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with OPM.  If not, see <http://www.gnu.org/licenses/>.
*/\n\n"))

                   (cond ((string-match
                           "\\.hp*$"
                           (file-name-nondirectory buffer-file-name))
                          (insert-string
                           (concat "#ifndef " headername "\n"
                                   "#define " headername "\n\n"
                                   "#endif // " headername "\n"
                                   ))))))
))