Skip to content

Commit

Permalink
Merge pull request #271 from vim-denops/remove-foldmethod
Browse files Browse the repository at this point in the history
👍 remove unnecessary 'foldmethod' changes
  • Loading branch information
lambdalisue committed Sep 6, 2024
2 parents 2ac1b5a + c14d65b commit afa88b7
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 94 deletions.
21 changes: 5 additions & 16 deletions buffer/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,16 @@ async function ensurePrerequisites(denops: Denops): Promise<string> {
function! DenopsStdBufferAppend_${suffix}(bufnr, lnum, repl) abort
let modified = getbufvar(a:bufnr, '&modified')
let modifiable = getbufvar(a:bufnr, '&modifiable')
let foldmethod = getbufvar(a:bufnr, '&foldmethod')
call setbufvar(a:bufnr, '&modifiable', 1)
call setbufvar(a:bufnr, '&foldmethod', 'manual')
call appendbufline(a:bufnr, a:lnum, a:repl)
call setbufvar(a:bufnr, '&modified', modified)
call setbufvar(a:bufnr, '&modifiable', modifiable)
call setbufvar(a:bufnr, '&foldmethod', foldmethod)
endfunction
function! DenopsStdBufferReplace_${suffix}(bufnr, repl, fileformat, fileencoding) abort
let modified = getbufvar(a:bufnr, '&modified')
let modifiable = getbufvar(a:bufnr, '&modifiable')
let foldmethod = getbufvar(a:bufnr, '&foldmethod')
call setbufvar(a:bufnr, '&modifiable', 1)
call setbufvar(a:bufnr, '&foldmethod', 'manual')
if a:fileformat isnot# v:null
call setbufvar(a:bufnr, '&fileformat', a:fileformat)
endif
Expand All @@ -82,7 +77,6 @@ async function ensurePrerequisites(denops: Denops): Promise<string> {
call deletebufline(a:bufnr, len(a:repl) + 1, '$')
call setbufvar(a:bufnr, '&modified', modified)
call setbufvar(a:bufnr, '&modifiable', modifiable)
call setbufvar(a:bufnr, '&foldmethod', foldmethod)
endfunction
function! DenopsStdBufferConcreteRestore_${suffix}() abort
Expand Down Expand Up @@ -321,7 +315,7 @@ export interface DecodeResult {
* }
* ```
*
* It temporary change `modified`, `modifiable`, and `foldmethod` options to append
* It temporary change `modified` and `modifiable` options to append
* the content of the `buffer` buffer without unmodifiable error or so on.
*/
export async function append(
Expand Down Expand Up @@ -361,8 +355,8 @@ export interface AppendOptions {
* }
* ```
*
* It temporary change `modified`, `modifiable`, and `foldmethod` options to
* replace the content of the `buffer` buffer without unmodifiable error or so on.
* It temporary change `modified` and `modifiable` options to replace
* the content of the `buffer` buffer without unmodifiable error or so on.
*/
export async function replace(
denops: Denops,
Expand Down Expand Up @@ -518,25 +512,20 @@ export async function modifiable<T>(
bufnr: number,
executor: () => T,
): Promise<T> {
const [modified, modifiable, foldmethod] = await batch.collect(
const [modified, modifiable] = await batch.collect(
denops,
(denops) => [
op.modified.getBuffer(denops, bufnr),
op.modifiable.getBuffer(denops, bufnr),
op.foldmethod.getBuffer(denops, bufnr),
],
);
await batch.batch(denops, async (denops) => {
await fn.setbufvar(denops, bufnr, "&modifiable", 1);
await fn.setbufvar(denops, bufnr, "&foldmethod", "manual");
});
await fn.setbufvar(denops, bufnr, "&modifiable", 1);
try {
return await executor();
} finally {
await batch.batch(denops, async (denops) => {
await fn.setbufvar(denops, bufnr, "&modified", modified);
await fn.setbufvar(denops, bufnr, "&modifiable", modifiable);
await fn.setbufvar(denops, bufnr, "&foldmethod", foldmethod);
});
}
}
Loading

0 comments on commit afa88b7

Please sign in to comment.