From 207f0da3807e51d3f2f5add05b122e716db7c792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 5 May 2023 22:59:52 +0200 Subject: [PATCH 1/4] doc: improve descriptions of links and urls --- autoload/wiki/link.vim | 4 +- .../wiki/link/{shortcite.vim => cite.vim} | 6 +- autoload/wiki/rx.vim | 4 +- doc/wiki.txt | 301 ++++++++++-------- plugin/wiki.vim | 2 +- 5 files changed, 173 insertions(+), 144 deletions(-) rename autoload/wiki/link/{shortcite.vim => cite.vim} (76%) diff --git a/autoload/wiki/link.vim b/autoload/wiki/link.vim index 33669081..c4381fb4 100644 --- a/autoload/wiki/link.vim +++ b/autoload/wiki/link.vim @@ -216,7 +216,7 @@ let s:matchers = [ \ wiki#link#ref_collapsed#matcher(), \ wiki#link#ref_full#matcher(), \ wiki#link#url#matcher(), - \ wiki#link#shortcite#matcher(), + \ wiki#link#cite#matcher(), \ wiki#link#date#matcher(), \ wiki#link#word#matcher(), \] @@ -231,7 +231,7 @@ let s:matchers_real = [ \ wiki#link#org#matcher(), \ wiki#link#ref_definition#matcher(), \ wiki#link#url#matcher(), - \ wiki#link#shortcite#matcher(), + \ wiki#link#cite#matcher(), \] " }}}1 diff --git a/autoload/wiki/link/shortcite.vim b/autoload/wiki/link/cite.vim similarity index 76% rename from autoload/wiki/link/shortcite.vim rename to autoload/wiki/link/cite.vim index 6ec1a677..ba2fb9ca 100644 --- a/autoload/wiki/link/shortcite.vim +++ b/autoload/wiki/link/cite.vim @@ -4,7 +4,7 @@ " Email: karl.yngve@gmail.com " -function! wiki#link#shortcite#matcher() abort " {{{1 +function! wiki#link#cite#matcher() abort " {{{1 return extend( \ wiki#link#_template#matcher(), \ deepcopy(s:matcher)) @@ -14,8 +14,8 @@ endfunction let s:matcher = { - \ 'type': 'url', - \ 'rx': wiki#rx#link_shortcite, + \ 'type': 'cite', + \ 'rx': wiki#rx#link_cite, \} function! s:matcher.parse_url() abort dict " {{{1 diff --git a/autoload/wiki/rx.vim b/autoload/wiki/rx.vim index 731e9850..d9385030 100644 --- a/autoload/wiki/rx.vim +++ b/autoload/wiki/rx.vim @@ -55,7 +55,7 @@ let wiki#rx#link_ref_full = \ . '[\]\[]\@!' let wiki#rx#link_ref_definition = \ '^\s*\[' . wiki#rx#reflabel . '\]:\s\+' . wiki#rx#url -let wiki#rx#link_shortcite = '\%(\s\|^\|\[\)\zs@[-_.a-zA-Z0-9]\+[-_a-zA-Z0-9]' +let wiki#rx#link_cite = '\%(\s\|^\|\[\)\zs@[-_.a-zA-Z0-9]\+[-_a-zA-Z0-9]' let wiki#rx#link_wiki = '\[\[\/\?[^\\\]]\{-}\%(|[^\\\]]\{-}\)\?\]\]' let wiki#rx#link = join([ \ wiki#rx#link_wiki, @@ -68,5 +68,5 @@ let wiki#rx#link = join([ \ wiki#rx#link_ref_shortcut, \ wiki#rx#link_ref_full, \ wiki#rx#url, - \ wiki#rx#link_shortcite, + \ wiki#rx#link_cite, \], '\|') diff --git a/doc/wiki.txt b/doc/wiki.txt index 491c54df..05f02418 100644 --- a/doc/wiki.txt +++ b/doc/wiki.txt @@ -44,15 +44,18 @@ CONTENTS *wiki-contents* Text objects |wiki-mappings-text-obj| Journal mappings |wiki-mappings-default| Links |wiki-link| - Link URLs |wiki-link-url| + Overview of link types |wiki-link-types| Wiki links |wiki-link-wiki| - Markdown links |wiki-link-markdown| - Markdown image links |wiki-link-image| - Orgmode links |wiki-link-orgmode| - Reference links |wiki-link-reference| - Zotero shortlinks |wiki-link-zotero| - AsciiDoc cross references |wiki-link-adoc-xref| - AsciiDoc link macro |wiki-link-adoc-link| + Markdown links |wiki-link-md| + Markdown image links |wiki-link-md_fig| + Orgmode links |wiki-link-org| + Reference links |wiki-link-ref_shortcut| + |wiki-link-ref_definition| + Cite links |wiki-link-cite| + AsciiDoc cross references |wiki-link-adoc_xref_bracket| + |wiki-link-adoc_xref_inline| + AsciiDoc link macro |wiki-link-adoc_link| + URLs |wiki-link-url| Completion |wiki-completion| Autocomplete |wiki-completion-auto| Tags |wiki-tags| @@ -258,7 +261,7 @@ makes the concept so important. Although I do add a lot of text to my wiki, I've also realized that I should not add all data there. For instance, I've come to use Zotero [7] for managing my literature database. This is also why there is now some support for Zotero -within wiki.vim (see |wiki-link-zotero|). +within wiki.vim (see |wiki-link-cite|). For some topics, I may write a wiki page about stuff where I have links to data files in which I can append new data and to scripts I can run to @@ -742,17 +745,17 @@ OPTIONS *wiki-config-options* link_type ~ A string that specifies the type of link to create. Possible values: - `md` (|wiki-link-markdown|) + `md` (|wiki-link-md|) Markdown style links. `wiki` (|wiki-link-wiki|) Wiki style links. - `org` (|wiki-link-orgmode|) + `org` (|wiki-link-org|) Orgmode style links. - `adoc_xref_bracket` (|wiki-link-adoc-xref|) - `adoc_xref_inline` + `adoc_xref_bracket` (|wiki-link-adoc_xref_bracket|) + `adoc_xref_inline` (|wiki-link-adoc_xref_inline|) AsciiDoc cross-reference style links (angled brackets style or inline `xref:...` style). @@ -840,7 +843,7 @@ OPTIONS *wiki-config-options* \ 'adoc_xref_bracket': 'wiki#link#adoc_xref_inline#template', \ 'adoc_xref_inline': 'wiki#link#adoc_xref_bracket#template', \ 'date': 'wiki#link#wiki#template', - \ 'shortcite': 'wiki#link#md#template', + \ 'cite': 'wiki#link#md#template', \ 'url': 'wiki#link#md#template', \} @@ -1575,9 +1578,10 @@ specify global mappings available anywhere, and the liens annotated ============================================================================== LINKS *wiki-link* -Links are one of the most essential features of a wiki, and as such, require -particular attention. A link is a structure that consists of an URL (see -|wiki-link-url|) and a possibly empty description. +Links are one of the most essential features of a wiki. As such, it is +important to understand them. A link is a "structure" that consists of an URL +and a possibly empty description, e.g. the wiki link `[[URL]]`. The supported +link types are listed below. The mappings that act on links are listed in |wiki-mappings-default|. The most notable default mappings are: @@ -1590,47 +1594,167 @@ notable default mappings are: - `wf` can be used to transform a link between different types (see |g:wiki_link_toggles|). -These are the link formats that are currently supported with some examples: + *wiki-link-types* +These are the link types that are currently supported with some examples: -- Link URLs |wiki-link-url| - `http://www.example.com` - `wiki:index` - `journal:2013-04-05` - `doi:10.1002%2Fandp.19053220607` - Wiki links |wiki-link-wiki| `[[URL]]` `[[URL|Description]]` -- Markdown links |wiki-link-markdown| +- Markdown links |wiki-link-md| `[Description](URL)` -- Markdown image links |wiki-link-image| +- Markdown image links |wiki-link-md_fig| `![Caption text](URL)` -- Orgmode links |wiki-link-orgmode| +- Orgmode links |wiki-link-org| `[[URL]]` `[[URL][Description]]` -- Reference links |wiki-link-reference| +- Reference links |wiki-link-ref_shortcut| + |wiki-link-ref_definition| `[Target]` `[Description][Target]` -- Zotero shortlink |wiki-link-zotero| - `@citekey` -- AsciiDoc cross-reference links |wiki-link-adoc-xref| + `[Target]: URL` +- AsciiDoc cross-reference links |wiki-link-adoc_xref_bracket| + |wiki-link-adoc_xref_inline| `<>` `xref:URL[Description]` -- AsciiDoc link macro |wiki-link-adoc-link| +- AsciiDoc link macro |wiki-link-adoc_link| `link:URL[Description]` +- Cite links |wiki-link-cite| + `@citekey` +- ISO dates |wiki-link-date| + `2023-05-05` +- URLs |wiki-link-url| + `https://www.example.com` + +------------------------------------------------------------------------------ +WIKI LINKS *wiki-link-wiki* + +Wiki links are similar in style to the standard Mediawiki links. This is the +standard syntax for creating internal wiki links. The description part is +optional. Examples: > + + [[URL]] + [[URL|Description]] + +------------------------------------------------------------------------------ +MARKDOWN LINKS *wiki-link-md* + +Markdown links are one of the more common types of links. They look like +this: > + + [Description](URL) + +------------------------------------------------------------------------------ +MARKDOWN IMAGE LINKS *wiki-link-md_fig* + +Markdown image links are similar to markdown links: > + + ![Caption text](URL) + +------------------------------------------------------------------------------ +ORGMODE LINKS *wiki-link-org* + +Orgmode links look identical to wiki links if they don't have a description. +If they have a description, it is added within the outer square brackets +within a second pair of square brackers. Examples: > + + [[URL]] + [[URL][Description]] + +------------------------------------------------------------------------------ +REFERENCE LINKS *wiki-link-ref_shortcut* + *wiki-link-ref_definition* + +Reference style links are slightly different. They consist of up to three +parts: An optional `description`, a `label` and a `link definition.` The +syntax is best explained through an example: > + + The most simple form, and perhaps the most useful one, is to add a simple + reference like this [1]. + + One may also add a [description][label]. + + The target may consist of both words and numbers, e.g. [like this][Ref 3]. + + [1]: + [label]: + [Ref 3]: + +Reference links are implemented as two different link types: + +- `ref_shortcut`: matches links used in the text, such as `[1]` and + `[description][label]`. Following this link will either open the target URL + or move the cursor to the target URL. +- `ref_definition`: matches link targets, such as `[1]: URL`. Following this + will open the URL. + +------------------------------------------------------------------------------ +ASCIIDOC CROSS REFERENCES *wiki-link-adoc_xref_bracket* + *wiki-link-adoc_xref_inline* + +AsciiDoc cross-reference links or xrefs [0] look like this: > + + Bracket style + <> + <> + <> + <> + + Inline macro + xref:anchor[Description] + xref:filename.adoc#anchor[Description] + xref:[LONG URL][Description] + +The `[LONG URL]` variant is supported for cases where the filename contains +spaces. + +[0]: https://docs.asciidoctor.org/asciidoc/latest/macros/xref/ + +------------------------------------------------------------------------------ +ASCIIDOC LINK MACROS *wiki-link-adoc_link* + +The AsciiDoc link macro [0] is a generic link syntax that looks like this: > + + link:[] + +The `[]` will be recognized by wiki.vim as the link text. + +[0]: https://docs.asciidoctor.org/asciidoc/latest/macros/link-macro/ + +------------------------------------------------------------------------------ +CITE LINKS *wiki-link-cite* + +The cite links are a convenient link type that can be used with e.g. Zotero +URLs. That is, instead of writing a link with URL `zot:citekey` one may simply +write `@citekey`. + +See also |wiki-link-url| for more info on the Zotero URL scheme and handler. ------------------------------------------------------------------------------ -LINK URLS *wiki-link-url* +ISO DATES *wiki-link-date* -An URL, which is short for Uniform Resource Locator, has the general format +Dates written in ISO date format, e.g. 2023-05-05, will be recognized as +a link to `journal:2023-05-05`. - `[scheme:]address` - `` +------------------------------------------------------------------------------ +URLS *wiki-link-url* + +URL is short for Uniform Resource Locator and is an address to a resource. The +concept of URLs is specified in RFC 3986 "Uniform Resource Identifier (URI): +Generic Syntax" (https://datatracker.ietf.org/doc/html/rfc3986). + +A typical URL looks like this: `scheme:address`. Some example of URLs: -The `scheme` specifies which kind of link it is. When the URL is typed -directly and with a proper scheme, it will typically be possible to follow the -link directly without putting it inside a fuller link type. The scheme is -required in general. However, for some type of links, the scheme may be -implied by the link type. +- `http://www.example.com` +- `wiki:index` +- `journal:2013-04-05` +- `doi:10.1002%2Fandp.19053220607` + +The `scheme` part specifies "which kind" of URL it is and is typically used to +identify which service should handle the URL. When the URL is typed directly +and with a proper scheme, it will typically be possible to follow the URL +directly without putting it inside a proper link type. However, if the +`address` part has spaces in it, the URL must be surrounded by angled +brackets, like this: ``. When the scheme is not specified for URLs inside one of the other link types, then the `wiki` scheme is generally assumed (unless otherwise stated). @@ -1679,7 +1803,7 @@ The following schemes are supported: For more user flexibility, one can implement a custom file handler with |g:wiki_file_handler|. - This scheme is the default scheme for |wiki-link-image|. + This scheme is the default scheme for |wiki-link-md_fig|. doi ~ Will use the `generic` scheme handler on an expanded URL of the form @@ -1712,101 +1836,6 @@ Schemes are defined in `autoload/wiki/url/{scheme}.vim`, which means it is relatively easy to define new custom schemes. See the generic scheme for a simple example of how this is implemented. ------------------------------------------------------------------------------- -WIKI LINKS *wiki-link-wiki* - -Wiki links are similar in style to the standard Mediawiki links. This is the -main syntax for creating internal wiki links. The description part is -optional. Examples: > - - [[URL]] - [[URL|Description]] - ------------------------------------------------------------------------------- -MARKDOWN LINKS *wiki-link-markdown* - -Markdown links are one of the more standard types of links. They look like -this: > - - [Description](URL) - ------------------------------------------------------------------------------- -MARKDOWN IMAGE LINKS *wiki-link-image* - -Markdown image links are similar to markdown links: > - - ![Caption text](URL) - ------------------------------------------------------------------------------- -ORGMODE LINKS *wiki-link-orgmode* - -Orgmode links look identical to wiki links if they don't have a description. -If they have a description, it is added within the outer square brackets -within a second pair of square brackers. Examples: > - - [[URL]] - [[URL][Description]] - ------------------------------------------------------------------------------- -REFERENCE LINKS *wiki-link-reference* - -Reference style links are slightly different. They consist of up to three -parts: An optional `description`, a `label` and a `link definition.` The -syntax is best explained through an example: > - - The most simple form, and perhaps the most useful one, is to add a simple - reference like this [1]. - - One may also add a [description][label]. - - The target may consist of both words and numbers, e.g. [like this][Ref 3]. - - [1]: - [label]: - [Ref 3]: - -Reference style links may be followed with `` both on the reference -location and on the link line. - ------------------------------------------------------------------------------- -ZOTERO SHORTLINKS *wiki-link-zotero* - -As a minor convenience link type, Zotero URLs may be written in short as -`@citekey` instead of `zot:citekey`. See also |wiki-link-url| for more info on -the Zotero URL scheme and handler. - ------------------------------------------------------------------------------- -ASCIIDOC CROSS REFERENCES *wiki-link-adoc-xref* - -AsciiDoc cross-reference links or xrefs [0] look like this: > - - Bracket style - <> - <> - <> - <> - - Inline macro - xref:anchor[Description] - xref:filename.adoc#anchor[Description] - xref:[LONG URL][Description] - -The `[LONG URL]` variant is supported for cases where the filename contains -spaces. - -[0]: https://docs.asciidoctor.org/asciidoc/latest/macros/xref/ - ------------------------------------------------------------------------------- -ASCIIDOC LINK MACROS *wiki-link-adoc-link* - -The AsciiDoc link macro [0] is a generic link syntax that looks like this: > - - link:[] - -The `[]` will be recognized by wiki.vim as the link text. - -[0]: https://docs.asciidoctor.org/asciidoc/latest/macros/link-macro/ - ============================================================================== COMPLETION *wiki-completion* diff --git a/plugin/wiki.vim b/plugin/wiki.vim index f73e64d8..87ed757b 100644 --- a/plugin/wiki.vim +++ b/plugin/wiki.vim @@ -70,7 +70,7 @@ call wiki#init#option('wiki_link_toggles', { \ 'adoc_xref_bracket': 'wiki#link#adoc_xref_inline#template', \ 'adoc_xref_inline': 'wiki#link#adoc_xref_bracket#template', \ 'date': 'wiki#link#wiki#template', - \ 'shortcite': 'wiki#link#md#template', + \ 'cite': 'wiki#link#md#template', \ 'url': 'wiki#link#md#template', \}) call wiki#init#option('wiki_mappings_use_defaults', 'all') From a8d378185acf335bbedbfd430ccd67d98aa8ef5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 5 May 2023 23:02:21 +0200 Subject: [PATCH 2/4] doc: add description of g:wiki_link_default_schemes --- doc/wiki.txt | 30 ++++++++++++++++++++++++++++-- plugin/wiki.vim | 13 +++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/doc/wiki.txt b/doc/wiki.txt index 05f02418..f3fe7d9e 100644 --- a/doc/wiki.txt +++ b/doc/wiki.txt @@ -803,6 +803,32 @@ OPTIONS *wiki-config-options* \ }, \} +*g:wiki_link_default_schemes* + A dictionary to configure the default URL scheme for link types, i.e. the + scheme assumed if the URL does not contain an initial scheme specifier. See + |wiki-link| for more information about link types and a more proper + definition of URLs and schemes. + + The keys represent the link type and the values are either strings, in which + case they specify the default scheme, or dictionaries between filetype + extensions and default schemes. + + Default: >vim + + let g:wiki_link_default_schemes = { + \ 'wiki': { 'wiki': 'wiki', 'adoc': 'adoc' }, + \ 'md': 'wiki', + \ 'md_fig': 'file', + \ 'org': 'wiki', + \ 'adoc_xref_inline': 'adoc', + \ 'adoc_xref_bracket': 'adoc', + \ 'adoc_link': 'file', + \ 'ref_shortcut': '', + \ 'ref_definition': '', + \ 'date': 'journal', + \ 'cite': 'zot', + \} + *g:wiki_link_toggle_on_follow* This option allows disabling the toggle behaviour in |WikiLinkFollow| where "normal" text under the cursor is transformed into links. The behaviour is @@ -1756,8 +1782,8 @@ directly without putting it inside a proper link type. However, if the `address` part has spaces in it, the URL must be surrounded by angled brackets, like this: ``. -When the scheme is not specified for URLs inside one of the other link types, -then the `wiki` scheme is generally assumed (unless otherwise stated). +When the scheme is not specified for URLs inside a link, then the scheme is +specified from |g:wiki_link_default_schemes|. The following schemes are supported: diff --git a/plugin/wiki.vim b/plugin/wiki.vim index 87ed757b..327d64c3 100644 --- a/plugin/wiki.vim +++ b/plugin/wiki.vim @@ -62,6 +62,19 @@ call wiki#init#option('wiki_link_creation', { \ 'url_extension': '', \ }, \}) +call wiki#init#option('wiki_link_default_schemes', { + \ 'wiki': { 'wiki': 'wiki', 'adoc': 'adoc' }, + \ 'md': 'wiki', + \ 'md_fig': 'file', + \ 'org': 'wiki', + \ 'adoc_xref_inline': 'adoc', + \ 'adoc_xref_bracket': 'adoc', + \ 'adoc_link': 'file', + \ 'ref_shortcut': '', + \ 'ref_definition': '', + \ 'date': 'journal', + \ 'cite': 'zot', + \}) call wiki#init#option('wiki_link_toggle_on_follow', 1) call wiki#init#option('wiki_link_toggles', { \ 'wiki': 'wiki#link#md#template', From 3c90a9696749cc45f310acbd11a0db03a317b6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 6 May 2023 20:55:35 +0200 Subject: [PATCH 3/4] feat: implement g:wiki_link_default_schemes refer: #301 --- autoload/wiki/link.vim | 11 ++++++++ autoload/wiki/link/_template.vim | 35 +++++++++++++----------- autoload/wiki/link/adoc_link.vim | 1 - autoload/wiki/link/adoc_xref_bracket.vim | 1 - autoload/wiki/link/adoc_xref_inline.vim | 1 - autoload/wiki/link/cite.vim | 11 ++------ autoload/wiki/link/date.vim | 1 - autoload/wiki/link/md_fig.vim | 1 - autoload/wiki/link/ref_shortcut.vim | 2 +- autoload/wiki/link/word.vim | 3 +- autoload/wiki/rx.vim | 1 + autoload/wiki/template.vim | 10 +++---- test/test-links/test-detection.vim | 6 ++-- test/wiki-adoc/index.adoc | 2 ++ 14 files changed, 45 insertions(+), 41 deletions(-) diff --git a/autoload/wiki/link.vim b/autoload/wiki/link.vim index c4381fb4..1a2b3844 100644 --- a/autoload/wiki/link.vim +++ b/autoload/wiki/link.vim @@ -74,6 +74,17 @@ function! wiki#link#get_creator(...) abort " {{{1 return a:0 > 0 ? l:c[a:1] : l:c endfunction +" }}}1 +function! wiki#link#get_scheme(link_type) abort " {{{1 + let l:scheme = get(g:wiki_link_default_schemes, a:link_type, '') + + if type(l:scheme) == v:t_dict + let l:scheme = get(l:scheme, expand('%:e'), '') + endif + + return l:scheme +endfunction + " }}}1 function! wiki#link#show(...) abort "{{{1 diff --git a/autoload/wiki/link/_template.vim b/autoload/wiki/link/_template.vim index 2e6ebde7..78f3c64a 100644 --- a/autoload/wiki/link/_template.vim +++ b/autoload/wiki/link/_template.vim @@ -45,8 +45,8 @@ function! s:matcher.create_link(match) dict abort " {{{1 " Get link text let l:match.text = '' - if has_key(self, 'rx_text') - let [l:text, l:c1, l:c2] = s:matchstrpos(l:match.content, self.rx_text) + if has_key(l:match, 'rx_text') + let [l:text, l:c1, l:c2] = s:matchstrpos(l:match.content, l:match.rx_text) if !empty(l:text) let l:match.text = l:text let l:match.text_pos_start = [l:match.pos_start[0], l:match.pos_start[1] + l:c1] @@ -56,8 +56,8 @@ function! s:matcher.create_link(match) dict abort " {{{1 " Get link url let l:match.url = l:match.content - if has_key(self, 'rx_url') - let [l:url, l:c1, l:c2] = s:matchstrpos(l:match.content, self.rx_url) + if has_key(l:match, 'rx_url') + let [l:url, l:c1, l:c2] = s:matchstrpos(l:match.content, l:match.rx_url) if !empty(l:url) let l:match.url = l:url let l:match.url_pos_start = [l:match.pos_start[0], l:match.pos_start[1] + l:c1] @@ -66,13 +66,19 @@ function! s:matcher.create_link(match) dict abort " {{{1 endif let l:match.url_raw = l:match.url - " Matcher specific url parsing - call l:match.parse_url() + " Add scheme to URL if it is missing + let l:match.default_scheme = wiki#link#get_scheme(l:match.type) + if empty(matchstr(l:match.url, '^\w\+:')) + if !empty(l:match.default_scheme) + let l:match.url = l:match.default_scheme . ':' . l:match.url + endif + endif + let l:match.scheme = matchstr(l:match.url, '^\w\+:') " Add toggle function if !has_key(l:match, 'toggle_template') - \ && has_key(g:wiki_link_toggles, self.type) - let l:match.toggle_template = function(g:wiki_link_toggles[self.type]) + \ && has_key(g:wiki_link_toggles, l:match.type) + let l:match.toggle_template = function(g:wiki_link_toggles[l:match.type]) endif " Clean up @@ -81,20 +87,17 @@ function! s:matcher.create_link(match) dict abort " {{{1 silent! unlet l:match.rx_text silent! unlet l:match.create_link silent! unlet l:match.match_at_cursor - silent! unlet l:match.parse_url + + if has_key(l:match, 'create_link_post') + call l:match.create_link_post() + unlet l:match.create_link_post + endif " Return the parsed link return s:link.new(l:match) endfunction "}}}1 -function! s:matcher.parse_url() dict abort " {{{1 - if !empty(get(self, 'scheme', '')) && empty(matchstr(self.url, '^\w\+:')) - let self.url = self.scheme . ':' . self.url - endif -endfunction - -" }}}1 let s:link = {} diff --git a/autoload/wiki/link/adoc_link.vim b/autoload/wiki/link/adoc_link.vim index 1364e5ab..79589699 100644 --- a/autoload/wiki/link/adoc_link.vim +++ b/autoload/wiki/link/adoc_link.vim @@ -6,7 +6,6 @@ function! wiki#link#adoc_link#matcher() abort " {{{1 return extend(wiki#link#_template#matcher(), { - \ 'scheme': 'file', \ 'type': 'adoc_link', \ 'rx': g:wiki#rx#link_adoc_link, \ 'rx_url': '\]\{-}\ze,[^>]\{-}\|[^>]\{-}\ze\)>>', \ 'rx_text': '<<[^,>]\{-},\zs[^>]\{-}\ze>>', diff --git a/autoload/wiki/link/adoc_xref_inline.vim b/autoload/wiki/link/adoc_xref_inline.vim index 9c811a36..9da46b84 100644 --- a/autoload/wiki/link/adoc_xref_inline.vim +++ b/autoload/wiki/link/adoc_xref_inline.vim @@ -7,7 +7,6 @@ function! wiki#link#adoc_xref_inline#matcher() abort " {{{1 return extend(wiki#link#_template#matcher(), { \ 'type': 'adoc_xref_inline', - \ 'scheme': 'adoc', \ 'rx': g:wiki#rx#link_adoc_xref_inline, \ 'rx_url': '\ Date: Sat, 6 May 2023 20:56:17 +0200 Subject: [PATCH 4/4] feat: use scratch buffer to show link data --- autoload/wiki/link.vim | 12 +++++++++- autoload/wiki/link/_template.vim | 39 +++++++++++--------------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/autoload/wiki/link.vim b/autoload/wiki/link.vim index 1a2b3844..f02db8f9 100644 --- a/autoload/wiki/link.vim +++ b/autoload/wiki/link.vim @@ -93,7 +93,17 @@ function! wiki#link#show(...) abort "{{{1 if empty(l:link) || l:link.type ==# 'word' call wiki#log#info('No link detected') else - call wiki#log#info('Link info', l:link.pprint()) + let l:viewer = { + \ 'name': 'WikiLinkInfo', + \ 'items': l:link.describe() + \} + function! l:viewer.print_content() abort dict + for [l:key, l:value] in self.items + call append('$', printf(' %-14s %s', l:key, l:value)) + endfor + endfunction + + call wiki#scratch#new(l:viewer) endif endfunction diff --git a/autoload/wiki/link/_template.vim b/autoload/wiki/link/_template.vim index 78f3c64a..596dfc15 100644 --- a/autoload/wiki/link/_template.vim +++ b/autoload/wiki/link/_template.vim @@ -123,33 +123,20 @@ function! s:link.replace(text) dict abort " {{{1 endfunction " }}}1 -function! s:link.pprint() dict abort " {{{1 - let l:out = { - \ 'type': self.type, - \ 'scheme': get(self, 'scheme', 'NONE'), - \ 'text': get(self, 'text', ''), - \ 'url': self.url, - \ 'raw_url': self.url_raw, - \ 'raw': self.content, - \ 'follow': string(get(self, 'follow', '')), - \ 'toggle_template': string(get(self, 'toggle_template', '')), - \} - if l:out.raw_url ==# l:out.url - unlet l:out.raw_url - endif - if l:out.raw ==# l:out.url - unlet l:out.raw - endif - if empty(l:out.text) - unlet l:out.text - endif - if empty(l:out.follow) - unlet l:out.follow +function! s:link.describe() dict abort " {{{1 + let l:content = [ + \ ['Type:', self.type], + \ ['Match:', self.content], + \ ['URL:', self.url], + \] + + if self.url !=# self.url_raw + let l:content += [['URL (raw):', self.url_raw]] endif - if empty(l:out.toggle_template) - unlet l:out.toggle_template - endif - return l:out + + let l:content += [['Description:', empty(self.text) ? 'N/A' : self.text]] + + return l:content endfunction " }}}1