Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Export indent to g:Context_indent_function#45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@maxigit
Copy link
Contributor

@maxigitmaxigit commentedFeb 5, 2020
edited by wellle
Loading

g:Context_indent_function being a funcref has to start with an uppercase
(unless there is a way to get away with it)

I'm not expecting you to accept the pull request, it's just a proof of concept, it works in theory
but defining custom function seems a bit more tricky than expected.

Example for markdown and orgmode (and indentation)

functionMyIndent(line)letline=getline(a:line)let headings=match(line,'^*\+\zs\s')+1if headings<=0let headings=match(line,'^#\+\zs\s')+1if headings<=0let headings=5endifendifreturnindent(a:line)+headingsendfunctionletg:Context_indent_function=funcref("MyIndent")letg:context_skip_regex='^\s*$'

For some reason it hangs at the begining. I thinkcontext doesn't like to to start with a indent level of 5 on an empty file ....

#44

g:Context_indent_function being a funcref has to start with an uppercase(unless there is a way to get away with it)
@wellle
Copy link
Owner

wellle commentedFeb 5, 2020
edited
Loading

Very nice, thanks for the proof of concept and example function! I'll consider adding this 👍

For some reason it hangs at the begining. I thinkcontext doesn't like to to start with a indent level of 5 on an empty file ....

Yes,indent() returns -1 for invalid lines, for example tryecho indent(0). This is used as exit condition incontext#popup#get_context() for example. So you could probably fix that by making your custom function have that property too. So for example like this maybe (untested):

functionMyIndent(line)letindent=indent(a:line)ifindent <0return [indent,indent]endifletline=getline(a:line)let headings=match(line,'^*\+\zs\s')+1if headings<=0let headings=match(line,'^#\+\zs\s')+1if headings<=0let headings=5endifendifreturn [indent+headings,indent]endfunctionletg:Context_indent_function=funcref("MyIndent")letg:context_skip_regex='^\s*$'

Edit: Updated according to changes introduced in#85.

@maxigit
Copy link
ContributorAuthor

Your modification works perfectly. Thanks.

@wellle
Copy link
Owner

Hey, thanks again! I tried using this branch for a bit and I found one fundamental issue I don't have a good idea yet how we can solve it in a clean way. Have a look at this screenshot:

Screenshot 2020-02-06 20 18 23

Because of the+5 in the example indent function from above the border line (▬▬▬▬▬▬ <context.vim>) is indented five characters too much. Do you see a good way to fix that?

@maxigit
Copy link
ContributorAuthor

I guess the indentation of the border line is a feature (which I didn't realize was there until now).
An option would be obviously to add a global variable to enable/disable it (or have an offset ?)
However, I'm not really happy with the +5 either, it would probably best to be able to specify a special level of indentation (-1, 999, a string ) which mean this line is never part of a context.

@maxigit
Copy link
ContributorAuthor

maxigit commentedFeb 6, 2020 via email

Another option would be to use the actual line indent (not the custom one)or that the custom function return a dictionary with the indent level andthe context bar. That way the user decide how he wants it.
On Thu, 6 Feb 2020, 19:23 Christian Wellenbrock, ***@***.***> wrote: Hey, thanks again! I tried using this branch for a bit and I found one fundamental issue I don't have a good idea yet how we can solve it in a clean way. Have a look at this screenshot: [image: Screenshot 2020-02-06 20 18 23] <https://user-images.githubusercontent.com/474504/73970695-dc78b980-491d-11ea-893b-6216d2c425e4.png> Because of the +5 in the example indent function from above the border line (▬▬▬▬▬▬ <context.vim>) is indented five characters too much. Do you see a good way to fix that? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#45?email_source=notifications&email_token=AAA4FCA5OPG5HB3MIE2VV23RBRPTXA5CNFSM4KQH6VJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELAOUEA#issuecomment-583068176>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAA4FCBPSOLP3WY7P7HGEELRBRPTXANCNFSM4KQH6VJA> .

'border_line' is used to indent the border line
@maxigit
Copy link
ContributorAuthor

I've pushed a new version ...

@wellle
Copy link
Owner

Thank you! To be honest I also have some concerns* about the new implementation. Let me think about it some more.

*Now we always evaluate the border line indent thing, even though we almost never use. That seems a bit wasteful IMO.

@maxigit
Copy link
ContributorAuthor

maxigit commentedFeb 10, 2020 via email

I agree with you.I just wanted to try if it would work but realized it would need a deeperrefactoring.My initial thought was to be able add some `##` at the beginning of theborder linebut realized it doesn't work.The cleaner option would be to add a `heading` or `level` concept (on topof `indent`)or to be able to disable the border line indentation.
On Sun, 9 Feb 2020 at 19:57, Christian Wellenbrock ***@***.***> wrote: Thank you! To be honest I also have some concerns* about the new implementation. Let me think about it some more. *Now we always evaluate the border line indent thing, even though we almost never use. That seems a bit wasteful IMO. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#45?email_source=notifications&email_token=AAA4FCDBWLUE4K57QFW5XX3RCBNZRA5CNFSM4KQH6VJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELGWLBY#issuecomment-583886215>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAA4FCCSUQWEEWG4RINNIEDRCBNZRANCNFSM4KQH6VJA> .

@wellle
Copy link
Owner

@maxigit: I picked your first commit and then added some more to add a separate setting for the border indent function. I opened a new PR:#54

Would you have a look at that and let me know if that works for you and makes sense? Thank you!

@maxigit
Copy link
ContributorAuthor

Seems to work. However, to make it work I add to dolet g:context_skip_regex = '^\s*$'.
Which is then line pased to border_line, is the last line of the popup or the first line after the popup ?

@wellle
Copy link
Owner

@maxigit: Thanks for checking! I mentioned that in the README and updated the linked comment 👍

Do you think it's clear enough now?

@maxigit
Copy link
ContributorAuthor

maxigit commentedFeb 19, 2020 via email

I'm not sure actually why I needed to change the skip regex.I think it's clear enough. If it's not, people will probably let you knowand you can then clarify if needed.Once again, this plugin is great (especially with this feature ;-)! I useit every day !
On Tue, 18 Feb 2020 at 22:46, Christian Wellenbrock < ***@***.***> wrote:@maxigit <https://github.com/maxigit>: Thanks for checking! I mentioned that in the README and updated the linked comment 👍 Do you think it's clear enough now? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#45?email_source=notifications&email_token=AAA4FCGL3V7FOTXIJKWTBPTRDRQLZA5CNFSM4KQH6VJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMFUVQI#issuecomment-587942593>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAA4FCALMXGAVXZOG5ZSGV3RDRQLZANCNFSM4KQH6VJA> .

@wellle
Copy link
Owner

Thank you for the feedback, will merge it later 👍

The reason you need to update the skip regex is that the default one does skip lines starting with#. I did this because in many file formats those lines are comments and I wanted to exclude comment lines from the context. So in order to include markdown header lines (which start with#) we need to not skip those lines, hence a different skip regex is required.

@maxigit
Copy link
ContributorAuthor

maxigit commentedFeb 19, 2020 via email

The reason you need to update the skip regex is that the default one does skip lines starting with #. I did this because in many file formats those lines are comments and I wanted to exclude comment lines from the context. So in order to include markdown header lines (which start with #) we need to not skip those lines, hence a different skip regex is required.
Of course, I remember know. I set the skip regex the other day to make itwork but when I tried your new branch I commented not sure if it was stillneeded.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#45?email_source=notifications&email_token=AAA4FCFGXKZFITLME6GAAZLRDVATJA5CNFSM4KQH6VJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMIEI5Y#issuecomment-588268663>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAA4FCBYQEHPZUY34QBZCR3RDVATJANCNFSM4KQH6VJA> .
wellle reacted with thumbs up emoji

@wellle
Copy link
Owner

Added in#54.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@maxigit@wellle

[8]ページ先頭

©2009-2025 Movatter.jp