OLD | NEW |
| 1 # Emacs |
| 2 |
| 3 [TOC] |
| 4 |
1 ## Debugging | 5 ## Debugging |
2 | 6 |
3 LinuxDebugging has some emacs-specific debugging tips. | 7 [Linux Debugging](linux_debugging.md) has some emacs-specific debugging tips. |
4 | 8 |
5 | 9 |
6 ## Blink Style (WebKit) | 10 ## Blink Style (WebKit) |
7 | 11 |
8 Chrome and Blink/WebKit style differ. You can use [directory-local variables](h
ttp://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
) to make the tab key do the right thing. E.g., in `third_party/WebKit`, add a
`.dir-locals.el` that contains | 12 Chrome and Blink/WebKit style differ. You can use |
| 13 [directory-local variables](http://www.gnu.org/software/emacs/manual/html_node/e
macs/Directory-Variables.html) |
| 14 to make the tab key do the right thing. E.g., in `third_party/WebKit`, add a |
| 15 `.dir-locals.el` that contains |
9 | 16 |
10 ``` | 17 ```el |
11 ((nil . ((indent-tabs-mode . nil) | 18 ((nil . ((indent-tabs-mode . nil) |
12 (c-basic-offset . 4) | 19 (c-basic-offset . 4) |
13 (fill-column . 120)))) | 20 (fill-column . 120)))) |
14 ``` | 21 ``` |
15 | 22 |
16 This turns off tabs, sets your indent to four spaces, and makes `M-q` wrap at 12
0 columns (WebKit doesn't define a wrap column, but there's a soft limit somewhe
re in that area for comments. Some reviewers do enforce the no wrap limit, which
Emacs can deal with gracefully; see below.) | 23 This turns off tabs, sets your indent to four spaces, and makes `M-q` wrap at |
| 24 120 columns (WebKit doesn't define a wrap column, but there's a soft limit |
| 25 somewhere in that area for comments. Some reviewers do enforce the no wrap |
| 26 limit, which Emacs can deal with gracefully; see below.) |
17 | 27 |
18 Be sure to `echo .dir-locals.el >> .git/info/exclude` so `git clean` doesn't del
ete your file. | 28 Be sure to `echo .dir-locals.el >> .git/info/exclude` so `git clean` doesn't |
| 29 delete your file. |
19 | 30 |
20 It can be useful to set up a WebKit specific indent style. It's not too much dif
ferent so it's easy to base off of the core Google style. Somewhere after you've
loaded google.el (most likely in your .emacs file), add: | 31 It can be useful to set up a WebKit specific indent style. It's not too much |
| 32 different so it's easy to base off of the core Google style. Somewhere after |
| 33 you've loaded google.el (most likely in your .emacs file), add: |
21 | 34 |
22 ``` | 35 ```el |
23 (c-add-style "WebKit" '("Google" | 36 (c-add-style "WebKit" '("Google" |
24 (c-basic-offset . 4) | 37 (c-basic-offset . 4) |
25 (c-offsets-alist . ((innamespace . 0) | 38 (c-offsets-alist . ((innamespace . 0) |
26 (access-label . -) | 39 (access-label . -) |
27 (case-label . 0) | 40 (case-label . 0) |
28 (member-init-intro . +) | 41 (member-init-intro . +) |
29 (topmost-intro . 0) | 42 (topmost-intro . 0) |
30 (arglist-cont-nonempty . +))))) | 43 (arglist-cont-nonempty . +))))) |
31 ``` | 44 ``` |
32 | 45 |
33 then you can add | 46 then you can add |
34 | 47 |
35 ``` | 48 ```el |
36 (c-mode . ((c-file-style . "WebKit"))) | 49 (c-mode . ((c-file-style . "WebKit"))) |
37 (c++-mode . ((c-file-style . "WebKit")))) | 50 (c++-mode . ((c-file-style . "WebKit")))) |
38 ``` | 51 ``` |
39 | 52 |
40 to the end of the .dir-locals.el file you created above. Note that this style ma
y not yet be complete, but it covers the most common differences. | 53 to the end of the .dir-locals.el file you created above. Note that this style |
| 54 may not yet be complete, but it covers the most common differences. |
41 | 55 |
42 Now that you have a WebKit specific style being applied, and assuming you have f
ont locking and it's default jit locking turned on, you can also get Emacs 23 to
wrap long lines more intelligently by adding the following to your .emacs file: | 56 Now that you have a WebKit specific style being applied, and assuming you have |
| 57 font locking and it's default jit locking turned on, you can also get Emacs 23 |
| 58 to wrap long lines more intelligently by adding the following to your .emacs |
| 59 file: |
43 | 60 |
44 ``` | 61 ```el |
45 ;; For dealing with WebKit long lines and word wrapping. | 62 ;; For dealing with WebKit long lines and word wrapping. |
46 (defun c-mode-adaptive-indent (beg end) | 63 (defun c-mode-adaptive-indent (beg end) |
47 "Set the wrap-prefix for the the region between BEG and END with adaptive fill
ing." | 64 "Set the wrap-prefix for the the region between BEG and END with adaptive fill
ing." |
48 (goto-char beg) | 65 (goto-char beg) |
49 (while | 66 (while |
50 (let ((lbp (line-beginning-position)) | 67 (let ((lbp (line-beginning-position)) |
51 (lep (line-end-position))) | 68 (lep (line-end-position))) |
52 (put-text-property lbp lep 'wrap-prefix (concat (fill-context-prefix lbp
lep) (make-string c-basic-offset ? ))) | 69 (put-text-property lbp lep 'wrap-prefix (concat (fill-context-prefix lbp
lep) (make-string c-basic-offset ? ))) |
53 (search-forward "\n" end t)))) | 70 (search-forward "\n" end t)))) |
54 | 71 |
55 (define-minor-mode c-adaptive-wrap-mode | 72 (define-minor-mode c-adaptive-wrap-mode |
56 "Wrap the buffer text with adaptive filling for c-mode." | 73 "Wrap the buffer text with adaptive filling for c-mode." |
57 :lighter "" | 74 :lighter "" |
58 (save-excursion | 75 (save-excursion |
59 (save-restriction | 76 (save-restriction |
60 (widen) | 77 (widen) |
61 (let ((buffer-undo-list t) | 78 (let ((buffer-undo-list t) |
62 (inhibit-read-only t) | 79 (inhibit-read-only t) |
63 (mod (buffer-modified-p))) | 80 (mod (buffer-modified-p))) |
64 (if c-adaptive-wrap-mode | 81 (if c-adaptive-wrap-mode |
65 (jit-lock-register 'c-mode-adaptive-indent) | 82 (jit-lock-register 'c-mode-adaptive-indent) |
66 (jit-lock-unregister 'c-mode-adaptive-indent) | 83 (jit-lock-unregister 'c-mode-adaptive-indent) |
67 (remove-text-properties (point-min) (point-max) '(wrap-prefix pref))) | 84 (remove-text-properties (point-min) (point-max) '(wrap-prefix pref))) |
68 (restore-buffer-modified-p mod))))) | 85 (restore-buffer-modified-p mod))))) |
69 | 86 |
70 (defun c-adaptive-wrap-mode-for-webkit () | 87 (defun c-adaptive-wrap-mode-for-webkit () |
71 "Turn on visual line mode and adaptive wrapping for WebKit source files." | 88 "Turn on visual line mode and adaptive wrapping for WebKit source files." |
72 (if (or (string-equal "webkit" c-indentation-style) | 89 (if (or (string-equal "webkit" c-indentation-style) |
73 (string-equal "WebKit" c-indentation-style)) | 90 (string-equal "WebKit" c-indentation-style)) |
74 (progn | 91 (progn |
75 (visual-line-mode t) | 92 (visual-line-mode t) |
76 (c-adaptive-wrap-mode t)))) | 93 (c-adaptive-wrap-mode t)))) |
77 | 94 |
78 (add-hook 'c-mode-common-hook 'c-adaptive-wrap-mode-for-webkit) | 95 (add-hook 'c-mode-common-hook 'c-adaptive-wrap-mode-for-webkit) |
79 (add-hook 'hack-local-variables-hook 'c-adaptive-wrap-mode-for-webkit) | 96 (add-hook 'hack-local-variables-hook 'c-adaptive-wrap-mode-for-webkit) |
80 ``` | 97 ``` |
81 | 98 |
82 This turns on visual wrap mode for files using the WebKit c style, and sets up a
hook to dynamically set the indent on the wrapped lines. It's not quite as inte
lligent as it could be (e.g., what would the wrap be if there really were a newl
ine there?), but it's very fast. It makes dealing with long code lines anywhere
much more tolerable (not just in WebKit). | 99 This turns on visual wrap mode for files using the WebKit c style, and sets up a |
| 100 hook to dynamically set the indent on the wrapped lines. It's not quite as |
| 101 intelligent as it could be (e.g., what would the wrap be if there really were a |
| 102 newline there?), but it's very fast. It makes dealing with long code lines |
| 103 anywhere much more tolerable (not just in WebKit). |
83 | 104 |
84 ## Syntax-error Highlighting | 105 ## Syntax-error Highlighting |
85 NinjaBuild users get in-line highlighting of syntax errors using `flymake.el` on
each buffer-save: | 106 |
86 ``` | 107 [Ninja](ninja_build.md) users get in-line highlighting of syntax errors using |
87 (load-file "src/tools/emacs/flymake-chromium.el") | 108 `flymake.el` on each buffer-save: |
88 ``` | 109 |
| 110 |
| 111 (load-file "src/tools/emacs/flymake-chromium.el") |
| 112 |
89 | 113 |
90 ## [ycmd](https://github.com/Valloric/ycmd) (YouCompleteMe) + flycheck | 114 ## [ycmd](https://github.com/Valloric/ycmd) (YouCompleteMe) + flycheck |
91 | 115 |
92 [emacs-ycmd](https://github.com/abingham/emacs-ycmd) in combination with flychec
k provides: | 116 [emacs-ycmd](https://github.com/abingham/emacs-ycmd) in combination with |
93 * advanced code completion | 117 flycheck provides: |
94 * syntax checking | |
95 * navigation to declarations and definitions (using `ycmd-goto`) | |
96 based on on-the fly processing using clang. A quick demo video showing code comp
letion and flycheck highlighting a missing semicolon syntax error: | |
97 | 118 |
98 <a href='http://www.youtube.com/watch?feature=player_embedded&v=a0zMbm4jACk' tar
get='_blank'><img src='http://img.youtube.com/vi/a0zMbm4jACk/0.jpg' width='696'
height=250 /></a> | 119 * advanced code completion |
| 120 * syntax checking |
| 121 * navigation to declarations and definitions (using `ycmd-goto`) based on |
| 122 on-the-fly processing using clang. A quick demo video showing code |
| 123 completion and flycheck highlighting a missing semicolon syntax error: |
99 | 124 |
100 #### Requirements: | 125 [![video preview][img]][video] |
| 126 |
| 127 [img]: http://img.youtube.com/vi/a0zMbm4jACk/0.jpg |
| 128 [video]: http://www.youtube.com/watch?feature=player_embedded&v=a0zMbm4jACk |
| 129 |
| 130 ### Requirements |
| 131 |
101 * Your build system is set up for building with clang or wrapper+clang | 132 * Your build system is set up for building with clang or wrapper+clang |
102 | 133 |
103 #### Setup | 134 ### Setup |
104 | 135 |
105 1. Clone, update external git repositories and build.sh ycmd from https://gith
ub.com/Valloric/ycmd into a directory, e.g. `~/dev/ycmd` | 136 1. Clone, update external git repositories and build.sh ycmd from |
106 1. Test `ycmd` by running | 137 https://github.com/Valloric/ycmd into a directory, e.g. `~/dev/ycmd` |
107 > `~/dev/ycmd$ python ycmd/__main__.py` | 138 1. Test `ycmd` by running `~/dev/ycmd$ python ycmd/__main__.py` You should see |
| 139 `KeyError: 'hmac_secret'` |
| 140 1. Install the following packages to emacs, for example from melpa: |
| 141 * `ycmd` |
| 142 * `company-ycmd` |
| 143 * `flycheck-ycmd` |
| 144 1. [More info on configuring emacs-ycmd](https://github.com/abingham/emacs-ycmd
#quickstart) |
| 145 1. Assuming your checkout of Chromium is in `~/dev/blink`, i.e. this is the |
| 146 directory in which you find the `src`folder, create a symbolic link as |
| 147 follows: |
108 | 148 |
109 > You should see `KeyError: 'hmac_secret'` | 149 ```shell |
110 1. Install the following packages to emacs, for example from melpa: | 150 cd ~/dev/blink |
111 * `ycmd` | 151 ln -s src/tools/vim/chromium.ycm_extra_conf.py .ycm_extra_conf.py |
112 * `company-ycmd` | 152 ``` |
113 * `flycheck-ycmd` | 153 |
114 > [More info on configuring emacs-ycmd](https://github.com/abingham/emacs-ycmd#q
uickstart) | 154 1. Add something like the following to your `init.el` |
115 1. Assuming your checkout of Chromium is in `~/dev/blink`, i.e. this is the di
rectory in which you find the `src`folder, create a symbolic link as follows | 155 |
116 > `cd ~/dev/blink; ln -s src/tools/vim/chromium.ycm_extra_conf.py .ycm_extra_con
f.py` | 156 ```el |
117 1. Add something like the following to your `init.el` | |
118 ``` | |
119 ;; ycmd | 157 ;; ycmd |
120 | 158 |
121 ;;; Googlers can replace a lot of this with (require 'google-ycmd). | 159 ;;; Googlers can replace a lot of this with (require 'google-ycmd). |
122 | 160 |
123 (require 'ycmd) | 161 (require 'ycmd) |
124 (require 'company-ycmd) | 162 (require 'company-ycmd) |
125 (require 'flycheck-ycmd) | 163 (require 'flycheck-ycmd) |
126 | 164 |
127 (company-ycmd-setup) | 165 (company-ycmd-setup) |
128 (flycheck-ycmd-setup) | 166 (flycheck-ycmd-setup) |
(...skipping 12 matching lines...) Expand all Loading... |
141 ;; Edit according to where you have your Chromium/Blink checkout | 179 ;; Edit according to where you have your Chromium/Blink checkout |
142 (add-to-list 'ycmd-extra-conf-whitelist (substitute-in-file-name "$HOME/dev/blin
k/.ycm_extra_conf.py")) | 180 (add-to-list 'ycmd-extra-conf-whitelist (substitute-in-file-name "$HOME/dev/blin
k/.ycm_extra_conf.py")) |
143 | 181 |
144 ;; Show flycheck errors in idle-mode as well | 182 ;; Show flycheck errors in idle-mode as well |
145 (setq ycmd-parse-conditions '(save new-line mode-enabled idle-change)) | 183 (setq ycmd-parse-conditions '(save new-line mode-enabled idle-change)) |
146 | 184 |
147 ;; Makes emacs-ycmd less verbose | 185 ;; Makes emacs-ycmd less verbose |
148 (setq url-show-status nil) | 186 (setq url-show-status nil) |
149 ``` | 187 ``` |
150 | 188 |
151 #### Troubleshooting | 189 ### Troubleshooting |
152 | 190 |
153 * If no completions show up or emacs reports errors, you can check the `*ycmd-
server*` buffer for errors. See the next bullet point for how to handle "OS Erro
r: No such file or directory" | 191 * If no completions show up or emacs reports errors, you can check the |
154 * Launching emacs from an OS menu might result in a different environment so t
hat `ycmd` does not find ninja. In that case, you can use a package like [exec-p
ath from shell](https://github.com/purcell/exec-path-from-shell) and add the fol
lowing to your `init.el`: | 192 `*ycmd-server*` buffer for errors. See the next bullet point for how to |
155 ``` | 193 handle "OS Error: No such file or directory" |
| 194 * Launching emacs from an OS menu might result in a different environment so |
| 195 that `ycmd` does not find ninja. In that case, you can use a package like |
| 196 [exec-path from shell](https://github.com/purcell/exec-path-from-shell) and |
| 197 add the following to your `init.el`: |
| 198 |
| 199 ```el |
156 (require 'exec-path-from-shell) | 200 (require 'exec-path-from-shell) |
157 (when (memq window-system '(mac ns x)) | 201 (when (memq window-system '(mac ns x)) |
158 (exec-path-from-shell-initialize)) | 202 (exec-path-from-shell-initialize)) |
159 ``` | 203 ``` |
160 | 204 |
161 | |
162 ## ff-get-other-file | 205 ## ff-get-other-file |
163 | 206 |
164 There's a builtin function called `ff-get-other-file` which will get the "other
file" based on file extension. I have this bound to C-o in c-mode (`(local-set-k
ey "\C-o" 'ff-get-other-file)`). While "other file" is per-mode defined, in c-li
ke languages it means jumping between the header and the source file. So I switc
h back and forth between the header and the source with C-o. If we had separate
include/ and src/ directories, this would be a pain to setup, but this might jus
t work out of the box for you. See the documentation for the variable `cc-other-
file-alist` for more information. | 207 There's a builtin function called `ff-get-other-file` which will get the "other |
| 208 file" based on file extension. I have this bound to C-o in c-mode |
| 209 (`(local-set-key "\C-o" 'ff-get-other-file)`). While "other file" is per-mode |
| 210 defined, in c-like languages it means jumping between the header and the source |
| 211 file. So I switch back and forth between the header and the source with C-o. If |
| 212 we had separate include/ and src/ directories, this would be a pain to setup, |
| 213 but this might just work out of the box for you. See the documentation for the |
| 214 variable `cc-other-file-alist` for more information. |
165 | 215 |
166 One drawback of ff-get-other-file is that it will always switch to a matching bu
ffer, even if the other file is in a different directory, so if you have A.cc,A.
h,A.cc(2) then ff-get-other-file will switch to A.h from A.cc(2) rather than loa
d A.h(2) from the appropriate directory. If you prefer something (C specific) th
at always finds, try this: | 216 One drawback of ff-get-other-file is that it will always switch to a matching |
167 ``` | 217 buffer, even if the other file is in a different directory, so if you have |
| 218 A.cc,A.h,A.cc(2) then ff-get-other-file will switch to A.h from A.cc(2) rather |
| 219 than load A.h(2) from the appropriate directory. If you prefer something (C |
| 220 specific) that always finds, try this: |
| 221 |
| 222 ```el |
168 (defun cc-other-file() | 223 (defun cc-other-file() |
169 "Toggles source/header file" | 224 "Toggles source/header file" |
170 (interactive) | 225 (interactive) |
171 (let ((buf (current-buffer)) | 226 (let ((buf (current-buffer)) |
172 (name (file-name-sans-extension (buffer-file-name))) | 227 (name (file-name-sans-extension (buffer-file-name))) |
173 » (other-extens | 228 » (other-extens |
174 » (cadr (assoc (concat "\\." | 229 » (cadr (assoc (concat "\\." |
175 (file-name-extension (buffer-file-name)) | 230 (file-name-extension (buffer-file-name)) |
176 » » » "\\'") | 231 » » » "\\'") |
177 cc-other-file-alist)))) | 232 cc-other-file-alist)))) |
178 (dolist (e other-extens) | 233 (dolist (e other-extens) |
179 (if (let ((f (concat name e))) | 234 (if (let ((f (concat name e))) |
180 (and (file-exists-p f) (find-file f))) | 235 (and (file-exists-p f) (find-file f))) |
181 (return))) | 236 (return))) |
182 ) | 237 ) |
183 ) | 238 ) |
184 ``` | 239 ``` |
185 _Note: if you know an easy way to change the ff-get-other-file behavior, please
replace this hack with that solution! - stevenjb@chromium.org_ | 240 |
| 241 _Note: if you know an easy way to change the ff-get-other-file behavior, please |
| 242 replace this hack with that solution! - stevenjb@chromium.org_ |
186 | 243 |
187 ## Use Google's C++ style! | 244 ## Use Google's C++ style! |
188 | 245 |
189 We have an emacs module, [google-c-style.el](http://google-styleguide.googlecode
.com/svn/trunk/google-c-style.el), which adds c-mode formatting. | 246 We have an emacs module, |
190 Then add to your .emacs: | 247 [google-c-style.el](http://google-styleguide.googlecode.com/svn/trunk/google-c-s
tyle.el), |
| 248 which adds c-mode formatting. Then add to your .emacs: |
| 249 |
| 250 ```el |
| 251 (load "/<path/to/chromium>/src/buildtools/clang_format/script/clang-format.el") |
| 252 (add-hook 'c-mode-common-hook |
| 253 (function (lambda () (local-set-key (kbd "TAB") 'clang-format-region)))) |
191 ``` | 254 ``` |
192 (load "/<path/to/chromium>/src/buildtools/clang_format/script/clang-format.e
l") | 255 |
193 (add-hook 'c-mode-common-hook (function (lambda () (local-set-key (kbd "TAB"
) 'clang-format-region)))) | 256 Now, you can use the |
194 ``` | |
195 Now, you can use the | |
196 | 257 |
197 <Tab> | 258 <Tab> |
198 | 259 |
199 key to format the current line (even a long line) or region. | 260 key to format the current line (even a long line) or region. |
200 | 261 |
201 ### Highlight long lines | 262 ## Highlight long lines |
202 | 263 |
203 One nice way to highlight long lines and other style issues: | 264 One nice way to highlight long lines and other style issues: |
204 ``` | 265 |
| 266 ```el |
205 (require 'whitespace) | 267 (require 'whitespace) |
206 (setq whitespace-style '(face indentation trailing empty lines-tail)) | 268 (setq whitespace-style '(face indentation trailing empty lines-tail)) |
207 (setq whitespace-line-column nil) | 269 (setq whitespace-line-column nil) |
208 (set-face-attribute 'whitespace-line nil | 270 (set-face-attribute 'whitespace-line nil |
209 :background "purple" | 271 :background "purple" |
210 :foreground "white" | 272 :foreground "white" |
211 :weight 'bold) | 273 :weight 'bold) |
212 (global-whitespace-mode 1) | 274 (global-whitespace-mode 1) |
213 ``` | 275 ``` |
214 | 276 |
215 | 277 Note: You might need to grab the latest version of |
216 Note: You might need to grab the latest version of [whitespace.el](http://www.em
acswiki.org/emacs-en/download/whitespace.el). | 278 [whitespace.el](http://www.emacswiki.org/emacs-en/download/whitespace.el). |
217 | 279 |
218 ## gyp | 280 ## gyp |
219 | 281 |
220 ### `gyp` style | 282 ### `gyp` style |
221 There is a gyp mode that provides basic indentation and font-lock (syntax highli
ghting) support. The mode derives from python.el (bundled with newer emacsen). | 283 There is a gyp mode that provides basic indentation and font-lock (syntax |
| 284 highlighting) support. The mode derives from python.el (bundled with newer |
| 285 emacsen). |
222 | 286 |
223 You can find it in tools/gyp/tools/emacs or at http://code.google.com/p/gyp/sour
ce/browse/trunk/tools/emacs/ | 287 You can find it in /src/tools/gyp/tools/emacs |
224 | 288 |
225 See the README file there for installation instructions. | 289 See the README file there for installation instructions. |
226 | 290 |
227 **Important**: the mode is only tested with `python.el` (bundled with newer emac
sen), not with `python-mode.el` (outdated and less maintained these days). | 291 **Important**: the mode is only tested with `python.el` (bundled with newer |
| 292 emacsen), not with `python-mode.el` (outdated and less maintained these days). |
228 | 293 |
229 ### deep nesting | 294 ### deep nesting |
230 | 295 |
231 A couple of helpers that show a summary of where you are; the first by tracing t
he indentation hierarchy upwards, the second by only showing `#if`s and `#else`s
that are relevant to the current line: | 296 A couple of helpers that show a summary of where you are; the first by tracing |
| 297 the indentation hierarchy upwards, the second by only showing `#if`s and |
| 298 `#else`s that are relevant to the current line: |
232 | 299 |
233 ```el | 300 ```el |
234 | |
235 (defun ami-summarize-indentation-at-point () | 301 (defun ami-summarize-indentation-at-point () |
236 "Echo a summary of how one gets from the left-most column to | 302 "Echo a summary of how one gets from the left-most column to |
237 POINT in terms of indentation changes." | 303 POINT in terms of indentation changes." |
238 (interactive) | 304 (interactive) |
239 (save-excursion | 305 (save-excursion |
240 (let ((cur-indent most-positive-fixnum) | 306 (let ((cur-indent most-positive-fixnum) |
241 (trace '())) | 307 (trace '())) |
242 (while (not (bobp)) | 308 (while (not (bobp)) |
243 (let ((current-line (buffer-substring (line-beginning-position) | 309 (let ((current-line (buffer-substring (line-beginning-position) |
244 (line-end-position)))) | 310 (line-end-position)))) |
245 (when (and (not (string-match "^\\s-*$" current-line)) | 311 (when (and (not (string-match "^\\s-*$" current-line)) |
246 (< (current-indentation) cur-indent)) | 312 (< (current-indentation) cur-indent)) |
247 (setq cur-indent (current-indentation)) | 313 (setq cur-indent (current-indentation)) |
248 (setq trace (cons current-line trace)) | 314 (setq trace (cons current-line trace)) |
249 (if (or (string-match "^\\s-*}" current-line) | 315 (if (or (string-match "^\\s-*}" current-line) |
250 (string-match "^\\s-*else " current-line) | 316 (string-match "^\\s-*else " current-line) |
251 (string-match "^\\s-*elif " current-line)) | 317 (string-match "^\\s-*elif " current-line)) |
252 (setq cur-indent (1+ cur-indent))))) | 318 (setq cur-indent (1+ cur-indent))))) |
253 (forward-line -1)) | 319 (forward-line -1)) |
254 (message "%s" (mapconcat 'identity trace "\n"))))) | 320 (message "%s" (mapconcat 'identity trace "\n"))))) |
255 | 321 |
256 (require 'cl) | 322 (require 'cl) |
257 (defun ami-summarize-preprocessor-branches-at-point () | 323 (defun ami-summarize-preprocessor-branches-at-point () |
258 "Summarize the C preprocessor branches needed to get to point." | 324 "Summarize the C preprocessor branches needed to get to point." |
259 (interactive) | 325 (interactive) |
260 (flet ((current-line-text () | 326 (flet ((current-line-text () |
261 (buffer-substring (line-beginning-position) (line-end-position)))) | 327 (buffer-substring (line-beginning-position) (line-end-position)))) |
262 (save-excursion | 328 (save-excursion |
263 (let ((eol (or (end-of-line) (point))) | 329 (let ((eol (or (end-of-line) (point))) |
264 deactivate-mark directives-stack) | 330 deactivate-mark directives-stack) |
265 (goto-char (point-min)) | 331 (goto-char (point-min)) |
266 (while (re-search-forward "^#\\(if\\|else\\|endif\\)" eol t) | 332 (while (re-search-forward "^#\\(if\\|else\\|endif\\)" eol t) |
267 (if (or (string-prefix-p "#if" (match-string 0)) | 333 (if (or (string-prefix-p "#if" (match-string 0)) |
268 (string-prefix-p "#else" (match-string 0))) | 334 (string-prefix-p "#else" (match-string 0))) |
269 (push (current-line-text) directives-stack) | 335 (push (current-line-text) directives-stack) |
270 (if (string-prefix-p "#endif" (match-string 0)) | 336 (if (string-prefix-p "#endif" (match-string 0)) |
271 (while (string-prefix-p "#else" (pop directives-stack)) t)))) | 337 (while (string-prefix-p "#else" (pop directives-stack)) t)))) |
272 (message "%s" (mapconcat 'identity (reverse directives-stack) "\n")))))) | 338 (message "%s" (mapconcat 'identity (reverse directives-stack) "\n"))))
)) |
273 ``` | 339 ``` |
274 | 340 |
275 ## find-things-fast | 341 ## find-things-fast |
276 | 342 |
277 erg wrote a suite of tools that do common operations from the root of your repos
itory, called [Find Things Fast](https://github.com/eglaysher/find-things-fast).
It contains ido completion over `git ls-files` (or the svn find equivalent) and
`grepsource` that only git greps files with extensions we care about (or the eq
uivalent the `find | xargs grep` statement in non-git repos.) | 343 erg wrote a suite of tools that do common operations from the root of your |
| 344 repository, called |
| 345 [Find Things Fast](https://github.com/eglaysher/find-things-fast). It contains |
| 346 ido completion over `git ls-files` (or the svn find equivalent) and `grepsource` |
| 347 that only git greps files with extensions we care about (or the equivalent the |
| 348 `find | xargs grep` statement in non-git repos.) |
278 | 349 |
279 ## vc-mode and find-file performance | 350 ## vc-mode and find-file performance |
280 | 351 |
281 When you first open a file under git control, vc mode kicks in and does a high l
evel stat of your git repo. For huge repos, especially WebKit and Chromium, this
makes opening a file take literally seconds. This snippet disables VC git for c
hrome directories: | 352 When you first open a file under git control, vc mode kicks in and does a high |
| 353 level stat of your git repo. For huge repos, especially WebKit and Chromium, |
| 354 this makes opening a file take literally seconds. This snippet disables VC git |
| 355 for chrome directories: |
282 | 356 |
283 ``` | 357 ```el |
284 | |
285 ; Turn off VC git for chrome | 358 ; Turn off VC git for chrome |
286 (when (locate-library "vc") | 359 (when (locate-library "vc") |
287 (defadvice vc-registered (around nochrome-vc-registered (file)) | 360 (defadvice vc-registered (around nochrome-vc-registered (file)) |
288 (message (format "nochrome-vc-registered %s" file)) | 361 (message (format "nochrome-vc-registered %s" file)) |
289 (if (string-match ".*chrome/src.*" file) | 362 (if (string-match ".*chrome/src.*" file) |
290 (progn | 363 (progn |
291 (message (format "Skipping VC mode for %s" % file)) | 364 (message (format "Skipping VC mode for %s" % file)) |
292 (setq ad-return-value nil) | 365 (setq ad-return-value nil) |
293 ) | 366 ) |
294 ad-do-it) | 367 ad-do-it) |
295 ) | 368 ) |
296 (ad-activate 'vc-registered) | 369 (ad-activate 'vc-registered) |
297 ) | 370 ) |
298 ``` | 371 ``` |
299 | 372 |
300 ## git tools | 373 ## git tools |
301 We're collecting Chrome-specific tools under `tools/emacs`. See the files there
for details. | |
302 | 374 |
303 * `trybot.el`: import Windows trybot output into a `compilation-mode` buffer. | 375 We're collecting Chrome-specific tools under `tools/emacs`. See the files there |
| 376 for details. |
| 377 |
| 378 * `trybot.el`: import Windows trybot output into a `compilation-mode` buffer. |
304 | 379 |
305 ## ERC for IRC | 380 ## ERC for IRC |
306 | 381 |
307 See ErcIrc. | 382 See [ErcIrc][erc_irc.md]. |
308 | 383 |
309 ## TODO | 384 ## TODO |
310 | 385 |
311 * Figure out how to make `M-x compile` default to `cd /path/to/chrome/root; ma
ke -r chrome`. | 386 * Figure out how to make `M-x compile` default to |
| 387 `cd /path/to/chrome/root; make -r chrome`. |
OLD | NEW |