home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / modes / c-style.el < prev    next >
Encoding:
Text File  |  1993-02-16  |  5.8 KB  |  197 lines

  1. ;; c-style.el --- sets c-style control variables.
  2. ;; Copyright (C) 1992-1993 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 2, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ;;
  20. ;; LCD Archive Entry:
  21. ;; c-style|Daniel LaLiberte|liberte@cs.uiuc.edu
  22. ;; |sets c-style control variables
  23. ;; |Thu Feb 27 13:42:57 CST 1992|Version: 2.1|~/as-is/c-src-doc.el.Z
  24. ;;
  25. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  26. ;;;
  27. ;;; There are several ways to call set-c-style described below.
  28. ;;; None of these methods reindent your program - they only affect
  29. ;;; new indentation.
  30. ;;;
  31. ;;; - Just call set-c-style in your c-mode-hook.
  32. ;;;    Without style argument, default-c-style will be used.
  33. ;;;    With style argument, this will set the style for every 
  34. ;;;    c-mode buffer the same.
  35. ;;;
  36. ;;; - Call set-c-style from the Local Variables list.
  37. ;;;    e.g. "eval:(set-c-style 'C++)"
  38. ;;;
  39. ;;; - Call set-c-style interactively.  It prompts for the style name
  40. ;;;    with completion using default-c-style.
  41. ;;;
  42. ;;; For convenience, put one of the following in your .emacs:
  43. ;;;    (autoload 'set-c-style "c-style" nil t)
  44. ;;; or (load "c-style")
  45. ;;; =====================================================
  46.  
  47. (defvar default-c-style 'GNU
  48.   "*The default value of c-style.  Set this in your .emacs.")
  49.  
  50. ;; The following predefined styles are all I know about.
  51. ;; If you learn of another style that has a "big" following, please
  52. ;; send me the parameters.
  53.  
  54. (defvar c-style-alist 
  55.   '((GNU 
  56.      (c-indent-level 2)
  57.      (c-continued-statement-offset 2)
  58.      (c-brace-offset 0)
  59.      (c-argdecl-indent 5)
  60.      (c-label-offset -2))
  61.  
  62.     (BSD
  63.      (c-indent-level 8)
  64.      (c-continued-statement-offset 8)
  65.      (c-brace-offset -8)
  66.      (c-argdecl-indent 8)
  67.      (c-label-offset -8))
  68.  
  69.     (K&R 
  70.      (c-indent-level 5)
  71.      (c-continued-statement-offset 5)
  72.      (c-brace-offset -5)
  73.      (c-argdecl-indent 0)
  74.      (c-label-offset -5))
  75.  
  76.     (BS   ; was C++ 
  77.      (c-indent-level 4)
  78.      (c-continued-statement-offset 4)
  79.      (c-brace-offset -4)
  80.      (c-argdecl-indent 4)
  81.      (c-label-offset -4))
  82.  
  83.     ;; From Lynn Slater
  84.     (LRS
  85.      (c-indent-level 4)
  86.      (c-continued-statement-offset 4)
  87.      (c-brace-offset 0)
  88.      (c-argdecl-indent 4)
  89.      (c-label-offset -2)
  90.      (c-auto-newline nil))
  91.  
  92.     (Plauger
  93.      (c-indent-level 0)
  94.      (c-continued-statement-offset 8)
  95.      (c-continued-brace-offset -8)
  96.      (c-brace-offset 8)
  97.      (c-brace-imaginary-offset 0)
  98.      (c-argdecl-indent 0)
  99.      (c-label-offset -8)
  100.      (c-auto-newline t)
  101.      (c-tab-always-indent t))
  102.  
  103.     ;; From Jozsef A Toth <jtoth+@pitt.edu>
  104.     ;; Is this really the Whitesmith style?
  105.     (Alman                
  106.      (c-argdecl-indent 0)
  107.      (c-brace-imaginary-offset 2)  ;;; ????
  108.      (c-brace-offset 0)
  109.      (c-continued-statement-offset 2)
  110.      (c-indent-level 0)
  111.      (c-label-offset -2)
  112.      (c-auto-newline t)
  113.      (comment-column 40)
  114.      (tab-width 2)
  115.      (fill-column '79))
  116.  
  117.     (Gould
  118.      (c-indent-level 4)
  119.      (c-continued-statement-offset 4)
  120.      (c-brace-offset -4)
  121.      (c-argdecl-indent 8)
  122.      (c-label-offset -2)
  123.      (c-brace-imaginary-offset 0))
  124.      
  125.     ;; From Joan Eslinger <wombat@kilimanjaro.key.amdahl.com>
  126.     (WRS 
  127.      (c-indent-level 0)
  128.      (c-continued-statement-offset 4)
  129.      (c-brace-offset 0)
  130.      (c-argdecl-indent 4)
  131.      (c-label-offset -2)
  132.      (c-brace-imaginary-offset 4)
  133.      (c-continued-brace-offset -4))
  134.     ))
  135.   
  136. (defvar c-style nil
  137.   "The buffer local c-mode indentation style.")
  138.  
  139. ;; Add style name to mode line.  Assumes minor-mode-alist is not buffer local.
  140. ;; Thanks to Joan Eslinger.
  141.  
  142. (defvar c-style-name nil
  143.   "The style name for a c-mode indentation style.
  144. This is to be set by set-c-style, and used by the mode line.")
  145.  
  146. (or (assq 'c-style-name minor-mode-alist)
  147.     (setq minor-mode-alist
  148.       (purecopy
  149.        (append minor-mode-alist
  150.            ;; use undocumented feature
  151.            '((c-style-name c-style-name))))))
  152.  
  153. (defun set-c-style (&optional style)
  154.   "Set up the c-mode style variables from STYLE if it is given, or
  155. default-c-style otherwise.  It makes the c indentation style variables
  156. buffer local."
  157.  
  158.   (interactive)
  159.  
  160.   (let ((c-styles (mapcar 'car c-style-alist))) ; for completion
  161.     (if (interactive-p)
  162.     (setq style
  163.           (let ((style-string    ; Get style name with completion.
  164.              (completing-read
  165.               (format "Set c-mode indentation style to (default %s): "
  166.                   default-c-style)
  167.               (vconcat c-styles)
  168.               (function (lambda (arg) (memq arg c-styles)))
  169.               )))
  170.         (if (string-equal "" style-string)
  171.             default-c-style
  172.           (intern style-string))
  173.         )))
  174.     
  175.     ;; If style is nil, use default-c-style.
  176.     (setq style (or style default-c-style))
  177.     
  178.     (make-local-variable 'c-style)
  179.     (if (memq style c-styles)
  180.     (setq c-style style)
  181.       (error "Undefined c style: %s" style)
  182.       )
  183.     (message "c-style: %s" c-style)
  184.     
  185.     ;; Set the c-style-name
  186.     (make-local-variable 'c-style-name)
  187.     (setq c-style-name (format " %s" c-style))
  188.  
  189.     ;; Finally, set the indentation style variables making each one local.
  190.     (mapcar (function (lambda (c-style-pair)
  191.             (make-local-variable (car c-style-pair))
  192.             (set (car c-style-pair)
  193.                  (car (cdr c-style-pair)))))
  194.         (cdr (assq c-style c-style-alist)))
  195.     c-style
  196.     ))
  197.