0
|
1 ;;; cc-lobotomy.el --- excise portions of cc-mode's brain... for speed
|
|
2
|
|
3 ;; Copyright (C) 1985-1995 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: 1995 Barry A. Warsaw
|
|
6 ;; Maintainer: cc-mode-help@merlin.cnri.reston.va.us
|
|
7 ;; Created: March 1995, split from cc-mode.el
|
|
8 ;; Version: 1.8
|
|
9 ;; Last Modified: 1995/06/11 21:42:31
|
|
10 ;; Keywords: c languages oop
|
|
11
|
|
12 ;; This file is not part of GNU Emacs.
|
|
13
|
|
14 ;; This program is free software; you can redistribute it and/or modify
|
|
15 ;; it under the terms of the GNU General Public License as published by
|
|
16 ;; the Free Software Foundation; either version 2 of the License, or
|
|
17 ;; (at your option) any later version.
|
|
18 ;;
|
|
19 ;; This program is distributed in the hope that it will be useful,
|
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 ;; GNU General Public License for more details.
|
|
23 ;;
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with this program; if not, write to the Free Software
|
|
26 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
27
|
|
28 ;;; Synched up with: Not in FSF.
|
|
29
|
|
30 ;;; Commentary:
|
|
31 ;;
|
|
32 ;; Every effort has been made to improve the performance of
|
|
33 ;; cc-mode. However, due to the nature of the C, C++, and Objective-C
|
|
34 ;; language definitions, a trade-off is often required between
|
|
35 ;; accuracy of construct recognition and speed. I believe it is always
|
|
36 ;; best to be correct, and that the mode is currently fast enough for
|
|
37 ;; most normal usage. Others disagree. I have no intention of
|
|
38 ;; including these hacks in the main distribution. When cc-mode
|
|
39 ;; version 5 comes out, it will include a rewritten indentation engine
|
|
40 ;; so that performance will be greatly improved automatically. This
|
|
41 ;; was not included in this release of version 4 so that Emacs 18
|
|
42 ;; could still be supported. Note that this implies that cc-mode
|
|
43 ;; version 5 will *not* work on Emacs 18!
|
|
44 ;;
|
|
45 ;; To use, see the variable cc-lobotomy-pith-list and the function
|
|
46 ;; cc-lobotomize. The variable contains a good explanation of the
|
|
47 ;; speed/accuracy trade-offs for each option. Set it to what you'd
|
|
48 ;; like, and call cc-lobotomy in your c-mode-hook.
|
|
49 ;;
|
|
50 ;; This will redefine certain cc-mode functions and affect all cc-mode
|
|
51 ;; buffers globally.
|
|
52 ;;
|
|
53 ;; This file is completely unsupported! I have no idea whether this
|
|
54 ;; will work with such things as cc-mode-18.el.
|
|
55
|
|
56
|
|
57 ;;; Code:
|
|
58 (require 'cc-mode)
|
|
59
|
|
60 (defvar cc-lobotomy-pith-list ()
|
|
61 "*List of things to dumb-ify to speed up cc-mode. Note that each
|
|
62 incurs a penalty in correct identification of certain code constructs.
|
|
63 Possible values to put on this list:
|
|
64
|
|
65 'literal -- `c-in-literal' is lobotomized. This will significantly
|
|
66 speed up parsing over large lists of cpp macros, as seen
|
|
67 for instance in header files. The penalty is that you
|
|
68 cannot put the `#' character as the first non-whitespace
|
|
69 character on a line inside other multi-line literals
|
|
70 (i.e. comments or strings)
|
|
71
|
|
72 'class -- `c-narrow-out-enclosing-class' and `c-search-uplist for
|
|
73 classkey' are lobotomized. This speeds up some
|
|
74 indenting inside and around class and struct
|
|
75 definitions. The penalty is that elements inside of
|
|
76 classes and structs may not indent correctly.
|
|
77
|
|
78 'lists -- `c-inside-bracelist-p' is lobotomized. This speeds up
|
|
79 indenting inside and around brace lists (e.g. aggregate
|
|
80 initializers, enum lists, etc.). The penalty is that
|
|
81 elements inside these lists may not indent correctly.")
|
|
82
|
|
83 (defun cc-lobotomize ()
|
|
84 "Perform lobotomies on cc-mode as described in `cc-lobotomy-pith-list'."
|
|
85 (let (pithedp)
|
|
86 (if (memq 'literal cc-lobotomy-pith-list)
|
|
87 (progn
|
|
88 (fset 'c-in-literal 'cc-in-literal-lobotomized)
|
|
89 (setq pithedp t)))
|
|
90 (if (memq 'class cc-lobotomy-pith-list)
|
|
91 (progn
|
|
92 (fset 'c-narrow-out-enclosing-class
|
|
93 'cc-narrow-out-enclosing-class-lobotomized)
|
|
94 (fset 'c-search-uplist-for-classkey
|
|
95 'cc-search-uplist-for-classkey-lobotomized)
|
|
96 (setq pithedp t)))
|
|
97 (if (memq 'lists cc-lobotomy-pith-list)
|
|
98 (progn
|
|
99 (fset 'c-inside-bracelist-p 'cc-inside-bracelist-p-lobotomized)
|
|
100 (setq pithedp t)))
|
|
101 (if pithedp
|
|
102 (fset 'c-submit-bug-report 'cc-submit-bug-report-lobotomized))
|
|
103 ))
|
|
104
|
|
105
|
|
106 ;; This is a faster version of c-in-literal. It trades speed for one
|
|
107 ;; approximation, namely that within other literals, the `#' character
|
|
108 ;; cannot be the first non-whitespace on a line.
|
|
109 (defun cc-in-literal-lobotomized (&optional lim)
|
|
110 ;; first check the cache
|
|
111 (if (and (boundp 'c-in-literal-cache)
|
|
112 c-in-literal-cache
|
|
113 (= (point) (aref c-in-literal-cache 0)))
|
|
114 (aref c-in-literal-cache 1)
|
|
115 ;; quickly check for cpp macro. this breaks if the `#' character
|
|
116 ;; appears as the first non-whitespace on a line inside another
|
|
117 ;; literal.
|
|
118 (let* (state
|
|
119 (char-at-boi (char-after (c-point 'boi)))
|
|
120 (rtn (cond
|
|
121 ((and char-at-boi (= char-at-boi ?#))
|
|
122 'pound)
|
|
123 ((nth 3 (setq state (save-excursion
|
|
124 (parse-partial-sexp
|
|
125 (or lim (c-point 'bod))
|
|
126 (point)))))
|
|
127 'string)
|
|
128 ((nth 4 state) (if (nth 7 state) 'c++ 'c))
|
|
129 (t nil))))
|
|
130 ;; cache this result if the cache is enabled
|
|
131 (and (boundp 'c-in-literal-cache)
|
|
132 (setq c-in-literal-cache (vector (point) rtn)))
|
|
133 rtn)))
|
|
134
|
|
135 (defun cc-narrow-out-enclosing-class-lobotomized (dummy1 dummy2) nil)
|
|
136
|
|
137 (defun cc-search-uplist-for-classkey-lobotomized (dummy) nil)
|
|
138
|
|
139 (defun cc-inside-bracelist-p-lobotomized (dummy1 dummy2) nil)
|
|
140
|
|
141 (defun cc-submit-bug-report-lobotomized ()
|
|
142 "Submit via mail a bug report on cc-mode."
|
|
143 (interactive)
|
|
144 ;; load in reporter
|
|
145 (let ((reporter-prompt-for-summary-p t)
|
|
146 (reporter-dont-compact-list '(c-offsets-alist)))
|
|
147 (and
|
|
148 (y-or-n-p "Do you want to submit a report on cc-mode? ")
|
|
149 (require 'reporter)
|
|
150 (reporter-submit-bug-report
|
|
151 c-mode-help-address
|
|
152 (concat "cc-mode " c-version " ("
|
|
153 (cond ((eq major-mode 'c++-mode) "C++")
|
|
154 ((eq major-mode 'c-mode) "C")
|
|
155 ((eq major-mode 'objc-mode) "ObjC"))
|
|
156 ")")
|
|
157 (let ((vars (list
|
|
158 ;; report only the vars that affect indentation
|
|
159 'c-basic-offset
|
|
160 'c-offsets-alist
|
|
161 'c-block-comments-indent-p
|
|
162 'c-cleanup-list
|
|
163 'c-comment-only-line-offset
|
|
164 'c-backslash-column
|
|
165 'c-delete-function
|
|
166 'c-electric-pound-behavior
|
|
167 'c-hanging-braces-alist
|
|
168 'c-hanging-colons-alist
|
|
169 'c-hanging-comment-ender-p
|
|
170 'c-tab-always-indent
|
|
171 'c-recognize-knr-p
|
|
172 'defun-prompt-regexp
|
|
173 'tab-width
|
|
174 )))
|
|
175 (if (not (boundp 'defun-prompt-regexp))
|
|
176 (delq 'defun-prompt-regexp vars)
|
|
177 vars))
|
|
178 (function
|
|
179 (lambda ()
|
|
180 (insert
|
|
181 (if c-special-indent-hook
|
|
182 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
|
|
183 "c-special-indent-hook is set to '"
|
|
184 (format "%s" c-special-indent-hook)
|
|
185 ".\nPerhaps this is your problem?\n"
|
|
186 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
|
|
187 "\n")
|
|
188 (format "c-emacs-features: %s\n" c-emacs-features)
|
|
189 )))
|
|
190 (function
|
|
191 (lambda ()
|
|
192 (insert
|
|
193 "You are using cc-lobotomy.el. You realize that by doing\n"
|
|
194 "so you have already made the decision to trade off accuracy\n"
|
|
195 "for speed? Don't set your hopes too high that your problem\n"
|
|
196 "will be fixed.\n\n"
|
|
197 )))
|
|
198 "Dear Barry,"
|
|
199 ))))
|
|
200
|
|
201 (provide 'cc-lobotomy)
|
|
202 ;;; cc-lobotomy.el ends here
|