home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / emacs / help / 4833 < prev    next >
Encoding:
Text File  |  1992-11-17  |  5.7 KB  |  198 lines

  1. Newsgroups: gnu.emacs.help
  2. Path: sparky!uunet!stanford.edu!agate!spool.mu.edu!uwm.edu!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!cs.uiuc.edu!liberte
  3. From: liberte@cs.uiuc.edu
  4. Subject: Re: help with C-mode variables
  5. Message-ID: <9211171811.AA10396@a.cs.uiuc.edu>
  6. Sender: daemon@cis.ohio-state.edu
  7. Organization: Gatewayed from the GNU Project mailing list help-gnu-emacs@prep.ai.mit.edu
  8. Date: Tue, 17 Nov 1992 06:11:02 GMT
  9. Lines: 187
  10.  
  11.     From: ksampath@magnus.acs.ohio-state.edu (Krishna S Sampath)
  12.      
  13.     is there any way to set these variables automatically? like if you are 
  14.     editing two c programs with different indentations, it would be very
  15.     convenient to not fight with these variables every single time....
  16.  
  17. Time to repost c-style.el.
  18.  
  19. dan
  20. ------
  21.  
  22. ;; c-style.el --- sets c-style control variables.
  23. ;;
  24. ;; LCD Archive Entry:
  25. ;; c-style|Daniel LaLiberte|liberte@cs.uiuc.edu
  26. ;; |sets c-style control variables
  27. ;; |Thu Feb 27 13:42:57 CST 1992|Version: 2.1|~/as-is/c-src-doc.el.Z
  28. ;;
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30. ;;;
  31. ;;; There are several ways to call set-c-style described below.
  32. ;;; None of these methods reindent your program - they only affect
  33. ;;; new indentation.
  34. ;;;
  35. ;;; - Just call set-c-style in your c-mode-hook.
  36. ;;;    Without style argument, default-c-style will be used.
  37. ;;;    With style argument, this will set the style for every 
  38. ;;;    c-mode buffer the same.
  39. ;;;
  40. ;;; - Call set-c-style from the Local Variables list.
  41. ;;;    e.g. "eval:(set-c-style 'C++)"
  42. ;;;
  43. ;;; - Call set-c-style interactively.  It prompts for the style name
  44. ;;;    with completion using default-c-style.
  45. ;;;
  46. ;;; For convenience, put one of the following in your .emacs:
  47. ;;;    (autoload 'set-c-style "c-style" nil t)
  48. ;;; or (load "c-style")
  49. ;;; =====================================================
  50.  
  51. (defvar default-c-style 'GNU
  52.   "*The default value of c-style.  Set this in your .emacs.")
  53.  
  54. ;; The following predefined styles are all I know about.
  55. ;; If you learn of another style that has a "big" following, please
  56. ;; send me the parameters.
  57.  
  58. (defvar c-style-alist 
  59.   '((GNU 
  60.      (c-indent-level 2)
  61.      (c-continued-statement-offset 2)
  62.      (c-brace-offset 0)
  63.      (c-argdecl-indent 5)
  64.      (c-label-offset -2))
  65.  
  66.     (BSD
  67.      (c-indent-level 8)
  68.      (c-continued-statement-offset 8)
  69.      (c-brace-offset -8)
  70.      (c-argdecl-indent 8)
  71.      (c-label-offset -8))
  72.  
  73.     (K&R 
  74.      (c-indent-level 5)
  75.      (c-continued-statement-offset 5)
  76.      (c-brace-offset -5)
  77.      (c-argdecl-indent 0)
  78.      (c-label-offset -5))
  79.  
  80.     (BS   ; was C++ 
  81.      (c-indent-level 4)
  82.      (c-continued-statement-offset 4)
  83.      (c-brace-offset -4)
  84.      (c-argdecl-indent 4)
  85.      (c-label-offset -4))
  86.  
  87.     ;; From Lynn Slater
  88.     (LRS
  89.      (c-indent-level 4)
  90.      (c-continued-statement-offset 4)
  91.      (c-brace-offset 0)
  92.      (c-argdecl-indent 4)
  93.      (c-label-offset -2)
  94.      (c-auto-newline nil))
  95.  
  96.     (Plauger
  97.      (c-indent-level 0)
  98.      (c-continued-statement-offset 8)
  99.      (c-continued-brace-offset -8)
  100.      (c-brace-offset 8)
  101.      (c-brace-imaginary-offset 0)
  102.      (c-argdecl-indent 0)
  103.      (c-label-offset -8)
  104.      (c-auto-newline t)
  105.      (c-tab-always-indent t))
  106.  
  107.     ;; From Jozsef A Toth <jtoth+@pitt.edu>
  108.     ;; Is this really the Whitesmith style?
  109.     (Alman                
  110.      (c-argdecl-indent 0)
  111.      (c-brace-imaginary-offset 2)  ;;; ????
  112.      (c-brace-offset 0)
  113.      (c-continued-statement-offset 2)
  114.      (c-indent-level 0)
  115.      (c-label-offset -2)
  116.      (c-auto-newline t)
  117.      (comment-column 40)
  118.      (tab-width 2)
  119.      (fill-column '79))
  120.  
  121.     (Gould
  122.      (c-indent-level 4)
  123.      (c-continued-statement-offset 4)
  124.      (c-brace-offset -4)
  125.      (c-argdecl-indent 8)
  126.      (c-label-offset -2)
  127.      (c-brace-imaginary-offset 0))
  128.      
  129.     ;; From Joan Eslinger <wombat@kilimanjaro.key.amdahl.com>
  130.     (WRS 
  131.      (c-indent-level 0)
  132.      (c-continued-statement-offset 4)
  133.      (c-brace-offset 0)
  134.      (c-argdecl-indent 4)
  135.      (c-label-offset -2)
  136.      (c-brace-imaginary-offset 4)
  137.      (c-continued-brace-offset -4))
  138.     ))
  139.   
  140. (defvar c-style nil
  141.   "The buffer local c-mode indentation style.")
  142.  
  143. ;; Add style name to mode line.  Assumes minor-mode-alist is not buffer local.
  144. ;; Thanks to Joan Eslinger.
  145.  
  146. (defvar c-style-name nil
  147.   "The style name for a c-mode indentation style.
  148. This is to be set by set-c-style, and used by the mode line.")
  149.  
  150. (or (assq 'c-style-name minor-mode-alist)
  151.     (nconc minor-mode-alist
  152.        '((c-style-name c-style-name))))  ; use undocumented feature
  153.  
  154. (defun set-c-style (&optional style)
  155.   "Set up the c-mode style variables from STYLE if it is given, or
  156. default-c-style otherwise.  It makes the c indentation style variables
  157. buffer local."
  158.  
  159.   (interactive)
  160.  
  161.   (let ((c-styles (mapcar 'car c-style-alist))) ; for completion
  162.     (if (interactive-p)
  163.     (setq style
  164.           (let ((style-string    ; Get style name with completion.
  165.              (completing-read
  166.               (format "Set c-mode indentation style to (default %s): "
  167.                   default-c-style)
  168.               (vconcat c-styles)
  169.               (function (lambda (arg) (memq arg c-styles)))
  170.               )))
  171.         (if (string-equal "" style-string)
  172.             default-c-style
  173.           (intern style-string))
  174.         )))
  175.     
  176.     ;; If style is nil, use default-c-style.
  177.     (setq style (or style default-c-style))
  178.     
  179.     (make-local-variable 'c-style)
  180.     (if (memq style c-styles)
  181.     (setq c-style style)
  182.       (error "Undefined c style: %s" style)
  183.       )
  184.     (message "c-style: %s" c-style)
  185.     
  186.     ;; Set the c-style-name
  187.     (make-local-variable 'c-style-name)
  188.     (setq c-style-name (format " %s" c-style))
  189.  
  190.     ;; Finally, set the indentation style variables making each one local.
  191.     (mapcar (function (lambda (c-style-pair)
  192.             (make-local-variable (car c-style-pair))
  193.             (set (car c-style-pair)
  194.                  (car (cdr c-style-pair)))))
  195.         (cdr (assq c-style c-style-alist)))
  196.     c-style
  197.     ))
  198.