Skip to content

Commit

Permalink
Merge pull request #1 from Milly/update
Browse files Browse the repository at this point in the history
chore: update dependencies and add help
  • Loading branch information
Milly committed Aug 1, 2024
2 parents e028838 + 7c4d7c5 commit 3066af2
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 66 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test

on:
push:
branches:
- master
pull_request:
paths:
- "**.md"
- "**.ts"
- "deno.jsonc"
- ".github/workflows/test.yml"

defaults:
run:
shell: bash --noprofile --norc -eo pipefail {0}

jobs:
check:
strategy:
matrix:
runner:
- ubuntu-latest
deno_version:
- "1.45.x"
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4

- uses: denoland/setup-deno@v1
with:
deno-version: "${{ matrix.deno_version }}"

- name: Check
run: deno task check
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![license:MIT](https://img.shields.io/github/license/Milly/dps-yank-history?style=flat-square)](LICENSE)

Vim denops plugin for persist yank history.
Vim denops plugin for persistent yank history.

## Required

Expand All @@ -17,29 +17,28 @@ You will need one of the following to manipulate your history:
- [ddc.vim](https://github.com/Shougo/ddc.vim)
- Insert matching text from yank history in insert mode.


## Configuration

```vim
" setup dps-yank-history
let yank_history#persist_path = expand('~') .. '/.cache/yank-history.jsonl'
" Setup dps-yank-history
let yank_history#persist_path = expand('~/.cache/yank-history.jsonl')
let yank_history#min_length = 2
let yank_history#update_duration = 1000
let yank_history#mtime_margin = 200
let yank_history#max_items = 100
let yank_history#truncate_threshold = 0
" setup ddu.vim
" Setup ddu.vim
call ddu#custom#patch_global('sources', [
\ {'name': 'yank-history'},
\ ])
call ddu#custom#patch_global('sourceParms', #{
call ddu#custom#patch_global('sourceParams', #{
\ yank-history: #{
\ headerHlGroup: 'Special',
\ prefix: 'Hist:',
\ }})
" setup ddc.vim
" Setup ddc.vim
call ddc#custom#patch_global('sources', [
\ 'yank-history',
\])
Expand Down
13 changes: 8 additions & 5 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"lock": false,
"fmt": {
"exclude": [
"*.md"
]
},
"tasks": {
"lint": "deno lint **/*.ts",
"fmt": "deno fmt **/*.ts",
"test": "deno test --no-lock -A --doc --parallel --shuffle",
"check": "deno check --no-lock **/*.ts",
"upgrade": "deno run --no-lock -A https://deno.land/x/udd@0.8.2/main.ts **/*.ts"
"check": "deno lint && deno fmt --check && deno check --no-lock **/*.ts",
"test": "deno test -A --doc --parallel --shuffle",
"update": "deno run --unstable-kv --allow-env --allow-read --allow-write --allow-run=git,deno --allow-net=jsr.io,api.jsr.io jsr:@molt/cli@^0.19.1 **/*.ts"
}
}
22 changes: 10 additions & 12 deletions denops/@ddc-sources/yank-history.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import type {
GatherArguments,
OnCompleteDoneArguments,
OnInitArguments,
} from "https://deno.land/x/ddc_vim@v4.3.1/base/source.ts";
import {
BaseSource,
type Item as DdcItem,
} from "https://deno.land/x/ddc_vim@v4.3.1/types.ts";
import type { Denops } from "https://deno.land/x/denops_std@v6.4.0/mod.ts";
import { globalOptions } from "https://deno.land/x/denops_std@v6.4.0/variable/option.ts";
import type { Denops } from "jsr:@denops/std@^7.0.0";
import { globalOptions } from "jsr:@denops/std@^7.0.0/variable";
import {
Unprintable,
type UnprintableUserData,
} from "https://deno.land/x/ddc_unprintable@v2.0.2/mod.ts";
} from "jsr:@milly/ddc-unprintable@^4.0.0";
import {
BaseSource,
type GatherArguments,
type OnCompleteDoneArguments,
type OnInitArguments,
} from "jsr:@shougo/ddc-vim@^6.0.0/source";
import type { Item as DdcItem } from "jsr:@shougo/ddc-vim@^6.0.0/types";
import type { RegType, YankHistoryItem } from "../yank-history/types.ts";
import { regContentsToText, toDuration } from "../yank-history/util.ts";

Expand Down
16 changes: 8 additions & 8 deletions denops/@ddu-sources/yank-history.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { abortablePromise } from "https://deno.land/std@0.221.0/async/mod.ts";
import type {
GatherArguments,
} from "https://deno.land/x/ddu_vim@v3.10.3/base/source.ts";
import { abortable } from "jsr:@std/async@^1.0.1";
import * as fn from "jsr:@denops/std@^7.0.0/function";
import {
BaseSource,
type GatherArguments,
} from "jsr:@shougo/ddu-vim@^5.0.0/source";
import {
ActionFlags,
type Actions,
BaseSource,
type Item,
} from "https://deno.land/x/ddu_vim@v3.10.3/types.ts";
import * as fn from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts";
} from "jsr:@shougo/ddu-vim@^5.0.0/types";
import { YankHistoryItem } from "../yank-history/types.ts";
import {
regContentsToText,
Expand Down Expand Up @@ -62,7 +62,7 @@ export class Source extends BaseSource<Params> {
return new ReadableStream({
start: async (controller) => {
try {
const items = await abortablePromise(
const items = await abortable(
this.#generateItems(args),
abortController.signal,
);
Expand Down
55 changes: 36 additions & 19 deletions denops/yank-history/controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defer } from "https://deno.land/x/denops_defer@v1.0.0/batch/defer.ts";
import type { Denops } from "https://deno.land/x/denops_std@v6.4.0/mod.ts";
import * as fn from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts";
import * as vars from "https://deno.land/x/denops_std@v6.4.0/variable/mod.ts";
import { is } from "https://deno.land/x/unknownutil@v3.17.2/is.ts";
import type { Denops } from "jsr:@denops/std@^7.0.0";
import * as fn from "jsr:@denops/std@^7.0.0/function";
import * as vars from "jsr:@denops/std@^7.0.0/variable";
import { is } from "jsr:@core/unknownutil@^3.18.1";
import { accumulate } from "jsr:@milly/denops-batch-accumulate@^1.0.0";
import { DBOptions, YankHistoryDatabase } from "./db.ts";
import { PLUGIN_AUTOLOAD_NS, YankEvent, YankHistoryItem } from "./types.ts";
import { regContentsToText } from "./util.ts";
Expand All @@ -18,8 +18,15 @@ export class YankHistoryController {
return new YankHistoryController(denops, options);
}

static getOptions(denops: Denops): Promise<Options> {
return defer(denops, (helper) => {
static async getOptions(denops: Denops): Promise<Options> {
const [
minLength,
path,
updateDuration,
mtimeMargin,
maxItems,
truncateThreshold,
] = await accumulate(denops, (helper) => {
async function get<D, R>(
name: string,
def: D,
Expand All @@ -32,19 +39,29 @@ export class YankHistoryController {
function toAbsolutePath(path: string) {
return fn.fnamemodify(helper, path, ":p") as Promise<string>;
}
return {
minLength: get("min_length", 2, is.Number),
db: {
path: get("persist_path", undefined, is.String).then(
(path) => path ? toAbsolutePath(path) : undefined,
),
updateDuration: get("update_duration", undefined, is.Number),
mtimeMargin: get("mtime_margin", undefined, is.Number),
maxItems: get("max_items", undefined, is.Number),
truncateThreshold: get("truncate_threshold", undefined, is.Number),
},
};
return Promise.all([
get("min_length", 2, is.Number),
(async () => {
const path = await get("persist_path", undefined, is.String);
return path ? await toAbsolutePath(path) : undefined;
})(),
get("update_duration", undefined, is.Number),
get("mtime_margin", undefined, is.Number),
get("max_items", undefined, is.Number),
get("truncate_threshold", undefined, is.Number),
]);
});

return {
minLength,
db: {
path,
updateDuration,
mtimeMargin,
maxItems,
truncateThreshold,
},
};
}

#denops: Denops;
Expand Down
8 changes: 4 additions & 4 deletions denops/yank-history/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { debounce } from "https://deno.land/std@0.221.0/async/mod.ts";
import { dirname } from "https://deno.land/std@0.221.0/path/mod.ts";
import { Lock } from "https://deno.land/x/async@v2.1.0/mod.ts";
import { assert, is } from "https://deno.land/x/unknownutil@v3.17.2/mod.ts";
import { debounce } from "jsr:@std/async@^1.0.0";
import { dirname } from "jsr:@std/path@^1.0.0";
import { Lock } from "jsr:@lambdalisue/async@^2.1.0";
import { assert, is } from "jsr:@core/unknownutil@^3.18.1";
import { isRegType, RegInfo, RegType, YankHistoryItem } from "./types.ts";

export type DBOptions = {
Expand Down
10 changes: 3 additions & 7 deletions denops/yank-history/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { Denops } from "https://deno.land/x/denops_std@v6.4.0/mod.ts";
import * as autocmd from "https://deno.land/x/denops_std@v6.4.0/autocmd/mod.ts";
import {
assert,
is,
maybe,
} from "https://deno.land/x/unknownutil@v3.17.2/mod.ts";
import type { Denops } from "jsr:@denops/std@^7.0.0";
import * as autocmd from "jsr:@denops/std@^7.0.0/autocmd";
import { assert, is, maybe } from "jsr:@core/unknownutil@^3.18.1";
import { YankHistoryController } from "./controller.ts";
import { isYankEvent, PLUGIN_AUGROUP } from "./types.ts";

Expand Down
5 changes: 1 addition & 4 deletions denops/yank-history/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
is,
type PredicateType,
} from "https://deno.land/x/unknownutil@v3.17.2/is.ts";
import { is, type PredicateType } from "jsr:@core/unknownutil@^3.18.1";

export const PLUGIN_NAME = "yank-history";
export const PLUGIN_AUGROUP = `${PLUGIN_NAME}-internal` as const;
Expand Down
124 changes: 124 additions & 0 deletions doc/yank-history.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
*yank-history.txt* Vim denops plugin for persistent yank history

Author: Milly
License: MIT license

CONTENTS *yank-history-contents*

Introduction |yank-history-introduction|
Install |yank-history-install|
Examples |yank-history-examples|
Options |yank-history-options|


==============================================================================
INTRODUCTION *yank-history-introduction*

Vim denops plugin for persistent yank history.

This plugin does not provide its own UI. You will need one of the following to
manipulate your history:

ddu.vim - Display list of yank history.
- Select and insert text from yank history.
- Select and delete elements from yank history.

ddc.vim - Insert matching text from yank history in insert mode.


==============================================================================
INSTALL *yank-history-install*

Requires "denops.vim" to be installed.

https://github.com/vim-denops/denops.vim

Optionally, install "ddu.vim" or "ddc.vim".

https://github.com/Shougo/ddu.vim
https://github.com/Shougo/ddc.vim


==============================================================================
EXAMPLES *yank-history-examples*
>
" Setup dps-yank-history
let yank_history#persist_path = expand('~/.cache/yank-history.jsonl')
let yank_history#min_length = 2
let yank_history#update_duration = 1000
let yank_history#mtime_margin = 200
let yank_history#max_items = 100
let yank_history#truncate_threshold = 0
" Setup ddu.vim
call ddu#custom#patch_global('sources', [
\ {'name': 'yank-history'},
\ ])
call ddu#custom#patch_global('sourceParams', #{
\ yank-history: #{
\ headerHlGroup: 'Special',
\ prefix: 'Hist:',
\ }})
" Setup ddc.vim
call ddc#custom#patch_global('sources', [
\ 'yank-history',
\])
call ddc#custom#patch_global('sourceParams', #{
\ yank-history: #{
\ maxAbbrWidth: 100,
\ ctrlCharHlGroup: 'SpecialKey',
\ }})
<

==============================================================================
OPTIONS *yank-history-options*

*yank-history-option-max_items*
*g:yank_history#max_items* (number)
The maximum number of histories to be saved. If the number of
histories exceeds |g:yank_history#truncate_threshold|, the
oldest ones will be deleted to reduce to this number.

Default: 100

*yank-history-option-min_length*
*g:yank_history#min_length* (number)
The minimum number of characters to save when yanked.

Default: 2

*yank-history-option-mtime_margin*
*g:yank_history#mtime_margin* (number)
The minimum number of milliseconds for a file update time to
determine whether a database file has been updated.
This is useful when the filesystem has timestamp errors.

Default: 200

*yank-history-option-persist_path*
*g:yank_history#persist_path* (string)
The path to the database file where yank history will be
stored. If it is a relative path, it is taken from the current
directory of Vim.
If empty, nothing will be saved.

Default: ""

*yank-history-option-truncate_threshold*
*g:yank_history#truncate_threshold* (number)
If the number of histories exceeds this, the oldest ones will
be truncated to reduce them to |g:yank_history#max_items|.

Default: |g:yank_history#max_items| + 20

*yank-history-option-update_duration*
*g:yank_history#update_duration* (number)
The number of milliseconds to wait before synchronizing the
database.

Default: 1000


==============================================================================
vim:tw=78:ts=8:ft=help:norl:noet:fen:noet:

0 comments on commit 3066af2

Please sign in to comment.