Skip to content

Commit 079f92a

Browse files
committed
👍 remove unnecessary 'foldmethod' changes
1 parent 2ac1b5a commit 079f92a

File tree

2 files changed

+104
-16
lines changed

2 files changed

+104
-16
lines changed

Diff for: buffer/buffer.ts

+5-16
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,16 @@ async function ensurePrerequisites(denops: Denops): Promise<string> {
5757
function! DenopsStdBufferAppend_${suffix}(bufnr, lnum, repl) abort
5858
let modified = getbufvar(a:bufnr, '&modified')
5959
let modifiable = getbufvar(a:bufnr, '&modifiable')
60-
let foldmethod = getbufvar(a:bufnr, '&foldmethod')
6160
call setbufvar(a:bufnr, '&modifiable', 1)
62-
call setbufvar(a:bufnr, '&foldmethod', 'manual')
6361
call appendbufline(a:bufnr, a:lnum, a:repl)
6462
call setbufvar(a:bufnr, '&modified', modified)
6563
call setbufvar(a:bufnr, '&modifiable', modifiable)
66-
call setbufvar(a:bufnr, '&foldmethod', foldmethod)
6764
endfunction
6865
6966
function! DenopsStdBufferReplace_${suffix}(bufnr, repl, fileformat, fileencoding) abort
7067
let modified = getbufvar(a:bufnr, '&modified')
7168
let modifiable = getbufvar(a:bufnr, '&modifiable')
72-
let foldmethod = getbufvar(a:bufnr, '&foldmethod')
7369
call setbufvar(a:bufnr, '&modifiable', 1)
74-
call setbufvar(a:bufnr, '&foldmethod', 'manual')
7570
if a:fileformat isnot# v:null
7671
call setbufvar(a:bufnr, '&fileformat', a:fileformat)
7772
endif
@@ -82,7 +77,6 @@ async function ensurePrerequisites(denops: Denops): Promise<string> {
8277
call deletebufline(a:bufnr, len(a:repl) + 1, '$')
8378
call setbufvar(a:bufnr, '&modified', modified)
8479
call setbufvar(a:bufnr, '&modifiable', modifiable)
85-
call setbufvar(a:bufnr, '&foldmethod', foldmethod)
8680
endfunction
8781
8882
function! DenopsStdBufferConcreteRestore_${suffix}() abort
@@ -321,7 +315,7 @@ export interface DecodeResult {
321315
* }
322316
* ```
323317
*
324-
* It temporary change `modified`, `modifiable`, and `foldmethod` options to append
318+
* It temporary change `modified` and `modifiable` options to append
325319
* the content of the `buffer` buffer without unmodifiable error or so on.
326320
*/
327321
export async function append(
@@ -361,8 +355,8 @@ export interface AppendOptions {
361355
* }
362356
* ```
363357
*
364-
* It temporary change `modified`, `modifiable`, and `foldmethod` options to
365-
* replace the content of the `buffer` buffer without unmodifiable error or so on.
358+
* It temporary change `modified` and `modifiable` options to replace
359+
* the content of the `buffer` buffer without unmodifiable error or so on.
366360
*/
367361
export async function replace(
368362
denops: Denops,
@@ -518,25 +512,20 @@ export async function modifiable<T>(
518512
bufnr: number,
519513
executor: () => T,
520514
): Promise<T> {
521-
const [modified, modifiable, foldmethod] = await batch.collect(
515+
const [modified, modifiable] = await batch.collect(
522516
denops,
523517
(denops) => [
524518
op.modified.getBuffer(denops, bufnr),
525519
op.modifiable.getBuffer(denops, bufnr),
526-
op.foldmethod.getBuffer(denops, bufnr),
527520
],
528521
);
529-
await batch.batch(denops, async (denops) => {
530-
await fn.setbufvar(denops, bufnr, "&modifiable", 1);
531-
await fn.setbufvar(denops, bufnr, "&foldmethod", "manual");
532-
});
522+
await fn.setbufvar(denops, bufnr, "&modifiable", 1);
533523
try {
534524
return await executor();
535525
} finally {
536526
await batch.batch(denops, async (denops) => {
537527
await fn.setbufvar(denops, bufnr, "&modified", modified);
538528
await fn.setbufvar(denops, bufnr, "&modifiable", modifiable);
539-
await fn.setbufvar(denops, bufnr, "&foldmethod", foldmethod);
540529
});
541530
}
542531
}

Diff for: buffer/buffer_test.ts

+99
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,69 @@ test({
302302
assertEquals(0, await fn.getbufvar(denops, bufnr, "&modifiable"));
303303
},
304304
});
305+
await t.step({
306+
name: "appends content of a 'foldmethod=marker' buffer",
307+
fn: async () => {
308+
await denops.cmd("enew");
309+
const bufnr = await fn.bufnr(denops);
310+
await fn.setbufvar(denops, bufnr, "&foldmethod", "marker");
311+
await fn.setbufvar(denops, bufnr, "&foldmarker", "{{{,}}}");
312+
await append(denops, bufnr, [
313+
"Hello {{{",
314+
"Darkness",
315+
"My }}}",
316+
"Old friend",
317+
]);
318+
assertEquals([
319+
"",
320+
"Hello {{{",
321+
"Darkness",
322+
"My }}}",
323+
"Old friend",
324+
], await fn.getline(denops, 1, "$"));
325+
assertEquals(
326+
await fn.getbufvar(denops, bufnr, "&foldmethod"),
327+
"marker",
328+
);
329+
330+
await fn.setbufvar(denops, bufnr, "&foldlevel", 0);
331+
await append(denops, bufnr, [
332+
"Joking",
333+
]);
334+
assertEquals([
335+
"",
336+
"Joking",
337+
"Hello {{{",
338+
"Darkness",
339+
"My }}}",
340+
"Old friend",
341+
], await fn.getline(denops, 1, "$"));
342+
assertEquals(
343+
await fn.getbufvar(denops, bufnr, "&foldmethod"),
344+
"marker",
345+
);
346+
347+
await fn.setbufvar(denops, bufnr, "&foldlevel", 0);
348+
await append(denops, bufnr, [
349+
"Foo",
350+
], {
351+
lnum: 3,
352+
});
353+
assertEquals([
354+
"",
355+
"Joking",
356+
"Hello {{{",
357+
"Foo",
358+
"Darkness",
359+
"My }}}",
360+
"Old friend",
361+
], await fn.getline(denops, 1, "$"));
362+
assertEquals(
363+
await fn.getbufvar(denops, bufnr, "&foldmethod"),
364+
"marker",
365+
);
366+
},
367+
});
305368
},
306369
});
307370

@@ -361,6 +424,42 @@ test({
361424
assertEquals(0, await fn.getbufvar(denops, bufnr, "&modifiable"));
362425
},
363426
});
427+
await t.step({
428+
name: "replaces content of an 'foldmethod=marker' buffer",
429+
fn: async () => {
430+
const bufnr = await fn.bufnr(denops);
431+
await fn.setbufvar(denops, bufnr, "&foldmethod", "marker");
432+
await fn.setbufvar(denops, bufnr, "&foldmarker", "{{{,}}}");
433+
await replace(denops, bufnr, [
434+
"Hello {{{",
435+
"Darkness",
436+
"My }}}",
437+
"Old friend",
438+
]);
439+
assertEquals([
440+
"Hello {{{",
441+
"Darkness",
442+
"My }}}",
443+
"Old friend",
444+
], await fn.getline(denops, 1, "$"));
445+
assertEquals(
446+
await fn.getbufvar(denops, bufnr, "&foldmethod"),
447+
"marker",
448+
);
449+
450+
await fn.setbufvar(denops, bufnr, "&foldlevel", 0);
451+
await replace(denops, bufnr, [
452+
"Joking {{{1",
453+
]);
454+
assertEquals([
455+
"Joking {{{1",
456+
], await fn.getline(denops, 1, "$"));
457+
assertEquals(
458+
await fn.getbufvar(denops, bufnr, "&foldmethod"),
459+
"marker",
460+
);
461+
},
462+
});
364463
},
365464
});
366465

0 commit comments

Comments
 (0)