blob: f635c580216fcf1530cf2e6f1e90ffb7f39e9518 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# UltiSnips
[UltiSnips](https://vimawesome.com/plugin/ultisnips) is one of snippet systems
for vim.
Below are some UltiSnips snippets that other Chromium developers will hopefully
find useful.
## Demos
### Copyright, include guard and namespace
The screencast below showcases how:
- `copyright` + `<tab>` will fill-in current year
- `#ifndef` + `<tab>` will calculate the macro name based on the path
of the current file
- `namespace` + `<tab>` + `namespace_name` + `tab` will copy the namespace
name into a comment at the end of the namespace
[]()
### Ad-hoc logging
The screenscast below showcases how:
- `<< some->expression.logme` + `<tab>` includes the expression
text in the output
- `<< stack` + `<tab>` logs the callstack
[]()
## C++ Snippets
### Copyright
```UltiSnips
snippet copyright
// Copyright `date +%Y` The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
$0
endsnippet
```
### Include guard
This relies on current directory being the Chromium root directory.
```Ultisnips
snippet ifndef "include guard" w
ifndef ${1:`!p snip.rv=str(path).replace('/','_').replace('\\','_').replace('.','_').upper()+'_'`}
#define $1
$0
#endif // $1
endsnippet
```
### Namespace
```Ultisnips
snippet namespace
namespace $1 {
$0
} // namespace $1
endsnippet
```
### Ad-hoc logging
```Ultisnips
snippet LOG(ERROR)
LOG(ERROR) << __func__$0;
endsnippet
snippet "<<.(.+)\.logme" "Logging expansion" r
<< "; `!p snip.rv = match.group(1).replace('"', '\\"')` = " << `!p snip.rv = match.group(1)`$0
endsnippet
snippet "<<.(.+)\.logint" "Logging expansion" r
<< "; `!p snip.rv = match.group(1).replace('"', '\\"')` = " << static_cast<int>(`!p snip.rv = match.group(1)`)$0
endsnippet
snippet "<<.stack" "Logging expansion2" r
<< "; stack = " << base::debug::StackTrace().ToString()
endsnippet
snippet "<<.jstack" "Logging expansion2" r
<< "; js stack = "
<< [](){
char* buf = nullptr; size_t size = 0;
FILE* f = open_memstream(&buf, &size);
if (!f) return std::string("<mem error>");
v8::Message::PrintCurrentStackTrace(
v8::Isolate::GetCurrent(), f);
fflush(f); fclose(f);
std::string result(buf, size);
free(buf);
return result; }();
endsnippet
```
|