1
1
# bufname
2
2
3
- ` bufname ` is a module to provide manage Vim's buffer name.
3
+ ` bufname ` is a module to provide functions to handle Vim's buffer name.
4
4
5
5
- [ API documentation] ( https://doc.deno.land/https/deno.land/x/denops_std/bufname/mod.ts )
6
6
7
+ The format of the buffer name assumed in this module is like
8
+
9
+ ``` text
10
+ {scheme}://{expr}[;{params}][#{fragment}]
11
+ ```
12
+
13
+ Where
14
+
15
+ - ` {scheme} ` is used to distinguish a buffer kind. It contains only alphabet
16
+ characters.
17
+ - ` {expr} ` is used to identify a buffer itself. _ Unusable characters_ ,
18
+ semicolons (;), and sharps (#) are replaced with percent-encoded characters.
19
+ - ` {params} ` (Optional) is used to add meta information to the buffer name like
20
+ query parameters of URL. _ Unusable characters_ and sharps (#) are replaced
21
+ with percent-encoded characters.
22
+ - ` {fragment} ` (Optional) is used to add a suffix to the buffer name for file
23
+ type detection or so on. _ Unusable characters_ are replaced with
24
+ percent-encoded characters.
25
+ - _ Unusable characters_ are ` " ` , ` < ` , ` > ` , ` | ` , ` ? ` , or ` * ` . It is caused by the
26
+ limitations of Vim on Windows.
27
+
28
+ For example,
29
+
30
+ ``` text
31
+ denops:///Users/John Titor/test.git
32
+ βββ¬βββ βββββββββββββ¬βββββββββββββ
33
+ scheme expr
34
+
35
+ denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2
36
+ βββ¬βββ βββββββββββββ¬βββββββββββββ βββββββββββββ¬ββββββββββββ
37
+ scheme expr params
38
+
39
+ denops:///Users/John Titor/test.git#README.md
40
+ βββ¬βββ βββββββββββββ¬βββββββββββββ βββββ¬ββββ
41
+ scheme expr fragment
42
+
43
+ denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md
44
+ βββ¬βββ βββββββββββββ¬βββββββββββββ βββββββββββββ¬ββββββββββββ βββββ¬ββββ
45
+ scheme expr params fragment
46
+ ```
47
+
7
48
## Usage
8
49
9
50
### format
@@ -13,88 +54,100 @@ instance like:
13
54
14
55
``` typescript
15
56
import { assertEquals } from " https://deno.land/std/testing/asserts.ts" ;
16
- import { Denops } from " https://deno.land/x/denops_std/mod.ts" ;
17
57
import { format } from " https://deno.land/x/denops_std/bufname/mod.ts" ;
18
58
19
- export async function main(denops : Denops ): Promise <void > {
20
- assertEquals (
21
- format ({ scheme: " denops" , expr: " /Users/johntitor/.vimrc" }),
22
- " denops:///Users/johntitor/.vimrc" ,
23
- );
24
-
25
- assertEquals (
26
- format ({
27
- scheme: " denops" ,
28
- expr: " /Users/johntitor/.vimrc" ,
29
- params: {
30
- foo: " foo" ,
31
- bar: [" bar" , " bar" ],
32
- hoge: undefined ,
33
- },
34
- }),
35
- " denops:///Users/johntitor/.vimrc;foo=foo&bar=bar&bar=bar" ,
36
- );
37
-
38
- assertEquals (
39
- format ({
40
- scheme: " denops" ,
41
- expr: " /Users/johntitor/.vimrc" ,
42
- params: {
43
- foo: " foo" ,
44
- bar: [" bar" , " bar" ],
45
- hoge: undefined ,
46
- },
47
- fragment: " README.md" ,
48
- }),
49
- " denops:///Users/johntitor/.vimrc;foo=foo&bar=bar&bar=bar#README.md" ,
50
- );
51
- }
52
- ```
59
+ assertEquals (
60
+ format ({
61
+ scheme: " denops" ,
62
+ expr: " /Users/John Titor/test.git" ,
63
+ }),
64
+ " denops:///Users/John Titor/test.git" ,
65
+ );
66
+
67
+ assertEquals (
68
+ format ({
69
+ scheme: " denops" ,
70
+ expr: " /Users/John Titor/test.git" ,
71
+ params: {
72
+ foo: " foo" ,
73
+ bar: [" bar1" , " bar2" ],
74
+ },
75
+ }),
76
+ " denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2" ,
77
+ );
53
78
54
- Note that unusable characters (` " ` , ` < ` , ` > ` , ` | ` , ` ? ` , ` * ` ) are replaced with
55
- percent-encoded characters.
79
+ assertEquals (
80
+ format ({
81
+ scheme: " denops" ,
82
+ expr: " /Users/John Titor/test.git" ,
83
+ fragment: " README.md" ,
84
+ }),
85
+ " denops:///Users/John Titor/test.git#README.md" ,
86
+ );
87
+
88
+ assertEquals (
89
+ format ({
90
+ scheme: " denops" ,
91
+ expr: " /Users/John Titor/test.git" ,
92
+ params: {
93
+ foo: " foo" ,
94
+ bar: [" bar1" , " bar2" ],
95
+ },
96
+ fragment: " README.md" ,
97
+ }),
98
+ " denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md" ,
99
+ );
100
+ ```
56
101
57
102
### parse
58
103
59
104
Use ` parse() ` to parse Vim's buffer name and get a ` Bufname ` instance like
60
105
61
106
``` typescript
62
107
import { assertEquals } from " https://deno.land/std/testing/asserts.ts" ;
63
- import { Denops } from " https://deno.land/x/denops_std/mod.ts" ;
64
108
import { parse } from " https://deno.land/x/denops_std/bufname/mod.ts" ;
65
109
66
- export async function main(denops : Denops ): Promise <void > {
67
- assertEquals (parse (" denops:///Users/johntitor/.vimrc" ), {
110
+ assertEquals (
111
+ parse (" denops:///Users/John Titor/test.git" ),
112
+ {
113
+ scheme: " denops" ,
114
+ expr: " /Users/John Titor/test.git" ,
115
+ },
116
+ );
117
+
118
+ assertEquals (
119
+ parse (" denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2" ),
120
+ {
68
121
scheme: " denops" ,
69
- expr: " /Users/johntitor/.vimrc" ,
70
- });
71
-
72
- assertEquals (
73
- parse (" denops:///Users/johntitor/.vimrc;foo=foo&bar=bar&bar=bar" ),
74
- {
75
- scheme: " denops" ,
76
- expr: " /Users/johntitor/.vimrc" ,
77
- params: {
78
- foo: " foo" ,
79
- bar: [" bar" , " bar" ],
80
- },
122
+ expr: " /Users/John Titor/test.git" ,
123
+ params: {
124
+ foo: " foo" ,
125
+ bar: [" bar1" , " bar2" ],
81
126
},
82
- );
83
-
84
- assertEquals (
85
- parse (" denops:///Users/johntitor/.vimrc;foo=foo&bar=bar&bar=bar#README.md" ),
86
- {
87
- scheme: " denops" ,
88
- expr: " /Users/johntitor/.vimrc" ,
89
- params: {
90
- foo: " foo" ,
91
- bar: [" bar" , " bar" ],
92
- },
93
- fragment: " README.md" ,
127
+ },
128
+ );
129
+
130
+ assertEquals (
131
+ parse (" denops:///Users/John Titor/test.git#README.md" ),
132
+ {
133
+ scheme: " denops" ,
134
+ expr: " /Users/John Titor/test.git" ,
135
+ fragment: " README.md" ,
136
+ },
137
+ );
138
+
139
+ assertEquals (
140
+ parse (
141
+ " denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md" ,
142
+ ),
143
+ {
144
+ scheme: " denops" ,
145
+ expr: " /Users/John Titor/test.git" ,
146
+ params: {
147
+ foo: " foo" ,
148
+ bar: [" bar1" , " bar2" ],
94
149
},
95
- );
96
- }
150
+ fragment: " README.md" ,
151
+ },
152
+ );
97
153
```
98
-
99
- Note that percent-encoded characters of unusable characters (` " ` , ` < ` , ` > ` , ` | ` ,
100
- ` ? ` , ` * ` ) are restored.
0 commit comments