;; 03-c-mode.el --- Set up C mode

;; Copyright (C) 2007 - 2020 Steve Youngs

;;     Author: Steve Youngs <steve@sxemacs.org>
;; Maintainer: Steve Youngs <steve@sxemacs.org>
;;    Created: <2007-12-02>
;; Time-stamp: <Thursday Apr  9, 2020 06:45:27 steve>
;;   Download: <https://downloads.sxemacs.org/SYinits/>
;;   HTMLised: <https://www.sxemacs.org/SYinits/03-c-mode.html>
;;   Git Repo: git clone https://git.sxemacs.org/syinit
;;   Keywords: init, compile

;; This file is part of SYinit

;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; 1. Redistributions of source code must retain the above copyright
;;    notice, this list of conditions and the following disclaimer.
;;
;; 2. Redistributions in binary form must reproduce the above copyright
;;    notice, this list of conditions and the following disclaimer in the
;;    documentation and/or other materials provided with the distribution.
;;
;; 3. Neither the name of the author nor the names of any contributors
;;    may be used to endorse or promote products derived from this
;;    software without specific prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

;;; Commentary:
;;   This sets up my C programming styles.  Note, too, that with this
;;   setup I am able to have different styles for different projects.
;;   It is a little kludgy, but it works.

;;; Credits:
;;
;;   The HTML version of this file was created with Hrvoje Niksic's
;;   htmlize.el which is part of the XEmacs "text-modes" package.
;;

;;; Todo:
;;
;;     

;;; Code:
;:*=======================
;:* Defaults
(setq c-comment-leader "  ")
(setq c-default-style
      '((c-mode . "linux")
        (c++-mode . "linux")
        (java-mode . "java")
        (python-mode . "python")
        (other . "gnu")))

;:*=======================
;:* Special style for Linux source files
(defun linux-c-mode ()
  "C mode with adjusted defaults for use with the Linux kernel.

Key-bindings:
\\{c-mode-map}"
  (c-mode)
  (c-set-style "linux")
  (setq mode-name "Linux/C"))

(add-to-list
 'auto-mode-alist '("^.*/linux.*/.*\\.[ch]$" . linux-c-mode))

;:*=======================
;:* C style for XEmacs core source files
(defun xemacs-c-mode ()
  "C mode with adjusted defaults for use with XEmacs core sources.

Key-bindings:
\\{c-mode-map}"
  (c-mode)
  (c-set-style "gnu")
  (setq mode-name "XE/C"))

(add-to-list
 'auto-mode-alist '("^.*/xemacs.*/.*\\.[ch]$" . xemacs-c-mode))

;:*=======================
;:* C style for SXEmacs core source files
(defvar c-enable-xemacs-performance-kludge-p)
(defun sxemacs-c-mode ()
  "C mode with adjusted defaults for use with SXEmacs core sources.

Key-bindings:
\\{c-mode-map}"
  (c-mode)
  (c-set-style "linux")
  (setq mode-name "SXE/C")
  (make-variable-buffer-local 'c-enable-xemacs-performance-kludge-p)
  (setq c-enable-xemacs-performance-kludge-p t))

(add-to-list
 'auto-mode-alist '("^.*/sxemacs.*/.*\\.[ch]$" . sxemacs-c-mode))

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
(message "C mode initialised.")
Created with SXEmacs Valid XHTML 1.0 Transitional!
Copyright © 2020 Steve Youngs
Verbatim copying and distribution is permitted in any medium, providing this notice is preserved.
Last modified: Wed Apr 15 18:11:21 AEST 2020