Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
5.3 KiB

  1. ;;; -*- Mode: Emacs-Lisp -*-
  2. ;***********************************************************
  3. ;* Emacs Lisp code to set up Appelles C/C++ coding
  4. ;* conventions.
  5. ;***********************************************************
  6. ;;;; C++ mode specializations
  7. (setq c-indent-level 4)
  8. (setq c-continued-statement-offset 4)
  9. (setq c-continued-brace-offset -2)
  10. (setq c-brace-offset -2)
  11. (setq c-argdecl-indent 4)
  12. (setq c-auto-newline nil)
  13. (setq c-label-offset -2)
  14. (setq c++-member-init-indent 0)
  15. (defconst appel-c-style
  16. '((c-basic-offset . 4)
  17. (c-offsets-alist . ((statement-block-intro . +)
  18. (knr-argdecl-intro . +)
  19. (block-open . 0)
  20. (statement-cont . +)
  21. (substatement-open . 0)
  22. (label . *)
  23. (member-init-intro . 0)
  24. (case-label . *)
  25. (statement-case-open . *)
  26. (statement-case-intro . *)
  27. (access-label . /)
  28. (inline-open . 0)
  29. )))
  30. "Appelles C++ Programming Style")
  31. ;; Customizations for all of c-mode, c++-mode, and objc-mode
  32. (defun appel-c-mode-common-hook ()
  33. ;; add my personal style and set it for the current buffer
  34. (c-add-style "Appelles" appel-c-style t)
  35. ;; keybindings for C, C++, and Objective-C. We can put these in
  36. ;; c-mode-map because c++-mode-map and objc-mode-map inherit it
  37. (define-key c-mode-map "\C-m" 'newline-and-indent)
  38. (define-key c++-mode-map "\C-m" 'newline-and-indent))
  39. (add-hook 'c-mode-common-hook 'appel-c-mode-common-hook)
  40. (defun set-abbrev-mode-and-fill-mode-on ()
  41. (setq abbrev-mode t)
  42. (auto-fill-mode 1))
  43. (setq c++-mode-hook '(set-abbrev-mode-and-fill-mode-on))
  44. ;; To automatically insert header into new C++ files.
  45. (defvar ifdef-file-name-changer-function 'upcase
  46. "The function to be applied to a file name prefix when generating a header
  47. file ifdef guard. For instance, when the value is 'upcase then a header file
  48. called 'ColorADT.h' will contain '#ifndef _COLORADT_H', while if the value is
  49. 'identity, we get '#ifndef _ColorADT_h'.")
  50. (defun c++-header-init ()
  51. "Stuffs a standard header into a newly created C++ code or header file.
  52. This includes
  53. the file name
  54. a reminder to put in a general comment,
  55. a string that SourceSafe will expand to include version info
  56. a copyright notice,
  57. If the file is a '.h' file, then #ifndef/#define guards are put around
  58. the code."
  59. ;; Cannot use major mode, because it hasn't been set up yet.
  60. (interactive)
  61. (if (>= (length (file-name-nondirectory (buffer-file-name))) 3)
  62. (let* ((file-name (buffer-file-name))
  63. (file-name-nondir (file-name-nondirectory file-name)))
  64. (if (>= (length file-name) 4)
  65. (let ((header-guard-string
  66. (funcall
  67. ifdef-file-name-changer-function
  68. (concat "_"
  69. (substring file-name-nondir 0 -2)
  70. "_h"))))
  71. (if (or (string-equal (substring file-name -3) ".cc")
  72. (string-equal (substring file-name -3) ".hh")
  73. (string-equal (substring file-name -2) ".h")
  74. (string-equal (substring file-name -4) ".cpp"))
  75. (progn
  76. (insert "/*******************************************************************************\n")
  77. (insert " *\n")
  78. (insert " * Copyright (c) 1998 Microsoft Corporation\n")
  79. (insert " *\n")
  80. (insert " * File: " file-name-nondir "\n")
  81. (insert " *\n")
  82. (insert " * Abstract:\n")
  83. (insert " *\n")
  84. (insert " *\n")
  85. (insert " *\n")
  86. (insert " *******************************************************************************/")
  87. (insert "\n")
  88. (insert "\n")
  89. (insert "\n")
  90. (if (string-equal (substring file-name -2) ".h")
  91. (progn
  92. (insert "#ifndef " header-guard-string
  93. "\n#define " header-guard-string "\n\n"
  94. "\n\n#endif /* " header-guard-string " */\n")
  95. ;; Ansii C doesn't like '-' in a cpp symbol
  96. (goto-char (point-min))
  97. (replace-string "-" "_")
  98. (goto-char (point-max))
  99. (previous-line 3)))
  100. ))))))
  101. ;; Returning nil means everything is ok.
  102. nil)
  103. (setq find-file-not-found-hooks
  104. (append '(c++-header-init) find-file-not-found-hooks))
  105. ;; Change tabs to spaces whenever a file is written out.
  106. (setq write-file-hooks (append '((lambda ()
  107. (untabify (point-min) (point-max))))
  108. write-file-hooks))
  109. ;; Recognize .cpp, .c, and .h files as C++ files
  110. (setq auto-mode-alist (append '(("\\.cpp$" . c++-mode)
  111. ("\\.c$" . c++-mode)
  112. ("\\.h$" . c++-mode))
  113. auto-mode-alist))