среда, 16 сентября 2020 г. в 22:55:00 UTC+3, Maxim Kim: 

> It is in an old PR as a new commit, I can make it as a separate PR.
>
>
>
> ср, 16 сент. 2020 г., 22:50 Bram Moolenaar <[email protected]>:
>
> > > E.g. syntax/html.vim links htmlTagName to Statement, but a fancy
> > > colorscheme may choose to give htmlTagName specific colours. This sort
> > > of thing happens frequently.
> > >
> > > If you then switch from one of these fancy colorschemes to one that 
> uses
> > > only the standard groups, htmlTagName won't be highlighted with
> > > Statement colours as you might expect, because the link has gone. It
> > > looks like the second colorscheme is broken.
> > >
> > > The idea was that if default links as well as default colours are
> > > restored on ":hi clear", then colorschemes will be working with a more
> > > consistent initial state, and produce the colours that the user expects
> > > to see.
> >
> > Can you make a new pull request, so we can see the difference with the
> > already included solution? The test would also need updating.
>
>
the patch:

>From 25796fd833e3d39418b7de3b58f1a5252347332d Mon Sep 17 00:00:00 2001
From: Maxim Kim <[email protected]>
Date: Wed, 16 Sep 2020 16:35:11 +0300
Subject: [PATCH] feat: save and restore default links

This approach is from Antony Scriven @adscriven:

* default hi-links are saved on `hi def`
* and restored in `hi clear`

Having this user doesn't have to do neither `syntax on` nor `syntax
enable` to be able to apply default links on a cleared highlight groups.

Thus there will be no need to update old colorschemes to make it work.
---
runtime/doc/syntax.txt | 3 ++-
src/highlight.c | 9 +++++++--
src/testdir/test_highlight.vim | 19 +++++--------------
3 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt
index 9c5656719..f7de54a55 100644
--- a/runtime/doc/syntax.txt
+++ b/runtime/doc/syntax.txt
@@ -4808,7 +4808,8 @@ in their own color.
:hi[ghlight] clear Reset all highlighting to the defaults. Removes all
highlighting for groups added by the user!
Uses the current value of 'background' to decide which
- default colors to use.
+ default colors to use. Default highlight links are
+ restored. |:hi-link|

:hi[ghlight] clear {group-name}
:hi[ghlight] {group-name} NONE
diff --git a/src/highlight.c b/src/highlight.c
index fe22da0f8..7e325afde 100644
--- a/src/highlight.c
+++ b/src/highlight.c
@@ -73,6 +73,7 @@ typedef struct
char_u *sg_gui_sp_name;// GUI special color name
#endif
int sg_link; // link to this highlight group ID
+ int sg_deflink; // default link; restored in highlight_clear()
int sg_set; // combination of SG_* flags
#ifdef FEAT_EVAL
sctx_T sg_script_ctx; // script in which the group was last set
@@ -739,6 +740,9 @@ do_highlight(
else
to_id = syn_check_group(to_start, (int)(to_end - to_start));

+ if (dodefault && (forceit || HL_TABLE()[from_id - 1].sg_deflink == 0))
+ HL_TABLE()[from_id - 1].sg_deflink = to_id;
+
if (from_id > 0 && (!init || HL_TABLE()[from_id - 1].sg_set == 0))
{
/*
@@ -1683,6 +1686,8 @@ highlight_clear(int idx)
HL_TABLE()[idx].sg_gui_attr = 0;
#endif
#ifdef FEAT_EVAL
+ // Restore default link
+ HL_TABLE()[idx].sg_link = HL_TABLE()[idx].sg_deflink;
// Clear the script ID only when there is no link, since that is not
// cleared.
if (HL_TABLE()[idx].sg_link == 0)
diff --git a/src/testdir/test_highlight.vim b/src/testdir/test_highlight.vim
index b8fdf17a8..be96efe79 100644
--- a/src/testdir/test_highlight.vim
+++ b/src/testdir/test_highlight.vim
@@ -796,14 +796,12 @@ func Test_highlight_term_attr()
hi clear
endfunc

-" Test default highlighting is restored
-func Test_highlight_restore_defaults()
+" Test default highlighting links are restored
+func Test_highlight_restore_default_links()

- hi! link TestLink Identifier
- hi! TestHi ctermbg=red
+ hi def link TestLink Identifier

let hlTestLinkPre = HighlightArgs('TestLink')
- let hlTestHiPre = HighlightArgs('TestHi')

" Test colorscheme
hi clear
@@ -811,21 +809,14 @@ func Test_highlight_restore_defaults()
syntax reset
endif
let g:colors_name = 'test'
- hi! link TestLink ErrorMsg
- hi! TestHi ctermbg=green
+ hi link TestLink ErrorMsg

- " Restore default highlighting
+ " Default links should be restored
colorscheme default
- syntax on
- " 'default' should work no matter if highlight group was cleared
- hi def link TestLink Identifier
- hi def TestHi ctermbg=red

let hlTestLinkPost = HighlightArgs('TestLink')
- let hlTestHiPost = HighlightArgs('TestHi')

call assert_equal(hlTestLinkPre, hlTestLinkPost)
- call assert_equal(hlTestHiPre, hlTestHiPost)
hi clear
endfunc

-- 
2.20.1



-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/9188f043-155c-4b08-8c43-e8936fbf2482n%40googlegroups.com.

Raspunde prin e-mail lui