Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: incremental regexp diffing #20

Closed
anchnk opened this issue Jul 24, 2017 · 7 comments
Closed

feature request: incremental regexp diffing #20

anchnk opened this issue Jul 24, 2017 · 7 comments

Comments

@anchnk
Copy link
Contributor

anchnk commented Jul 24, 2017

Is it doable to expose a function that will update fields that matches a certain pattern on lines ?

For instance, here's the typical kind of headers I do have in my configuration files.

################################################################################
#
#    ██████╗   ██╗   ██╗  ███╗   ██╗  ███████╗  ████████╗  ██████╗    ██████╗
#    ██╔══██╗  ██║   ██║  ████╗  ██║  ██╔════╝  ╚══██╔══╝  ██╔══██╗  ██╔════╝
#    ██║  ██║  ██║   ██║  ██╔██╗ ██║  ███████╗     ██║     ██████╔╝  ██║
#    ██║  ██║  ██║   ██║  ██║╚██╗██║  ╚════██║     ██║     ██╔══██╗  ██║
#    ██████╔╝  ╚██████╔╝  ██║ ╚████║  ███████║     ██║     ██║  ██║  ╚██████╗
#    ╚═════╝    ╚═════╝   ╚═╝  ╚═══╝  ╚══════╝     ╚═╝     ╚═╝  ╚═╝   ╚═════╝
#
#    Author: anchnk
#    Date: 24.07.2017
#    Dunst: v1.2.0
#    File: dunstrc
#    Last Modified Date: 24.07.2017
#    Last Modified By: anchnk
#    Location: $HOME/.config/dunst/dunstrc
#
################################################################################

Having a function that would update Author, Date, File, Last Modified Date, Last Modified By fields' values without changing the structure of my headers would be awesome.

I understand that would not be top priority but I do believe it would add more flexibility to the plugin and also would avoid the need to wrote a script for that. Well at least if that use case can benefits to others.

@alpertuna
Copy link
Owner

Hello,
Thanks for the idea. This looks good but implementing this may be challenging. If the conditions are - file type should be cfg and the filename should be written as banner - It can be done. Challanging part is generating banner text.
If I have free time, I can do it.

@anchnk
Copy link
Contributor Author

anchnk commented Jul 27, 2017

Oh sorry my explanation was confusing. I am just wondering if the header attributes (Last Modified Date being the most important) could be updated on save without being the first lines of the file (due to the banner).

That would require to expose a function that would search the first occurrence of Last Modified Date for instance and update it's value. Unfortunately I am quite new to Vimscript, I can understand your source quite well and I am willing to work on it as well but I will probably need to some guidance :)

@alpertuna
Copy link
Owner

alpertuna commented Jul 27, 2017

Oh, I didn't read very well sorry. Now I got the point. Actually vim-header supports updating field already. But for this, filetype should be supported and this filetype is not supported now thats why it wont update fields.
I thought vim knows dunstrc as cfg but vim doesnt recognise.

@anchnk
Copy link
Contributor Author

anchnk commented Jul 27, 2017

Now that cfg filetype support is merged, I can invoke AddHeader on the cfg filetype.
I force that option in vim's modeline (# vim: ft=cfg) in my dunstrc file.
However I am still having the issue that vim-header adds the header on top of the file rather than updating existing fields.

Also there's are several white spaces between the comment_char and headers'field in my banner. That's why I thought exporting a function that would update fields only would be great. I mainly need it to be able to have Last Modified Date one but others would be great as well (speaking of those added by the plugin).

@anchnk
Copy link
Contributor Author

anchnk commented Jul 27, 2017

Btw if that can help to get what I mean my dunstrc file is here

@anchnk
Copy link
Contributor Author

anchnk commented Jul 31, 2017

I worked a bit on this feature, it might be messy so I am looking for your opinion on this before even considering to make a PR.

Here you can see the diff between the 2 versions:

master...anchnk:diff-update

It changes the way the update was working by checking if headers are present from top of the buffer to a certain threshold set by the user (option g:header_max_size).

  • If all headers are present, then it updates only their values (keeping indentation).
  • If at least one header is missing, it generates a new file header.

So for example, if in my $MYVIMRC file I set g:header_field_filename = 1' and disabled every other header and set g:header_max_size = 10it will check if the textFile:` is present in the range 0,0+header_max_size:

->..1 # This                  
|...2 # example
|...3 # updates
|...4 # the
|...5 # header
|...6 # as it's in the range
|...7 # 
|...8 #  File: foobar.sh
|...9
->..10 # g:header_max_size

If g:header_max_size is set to default (5) this header won't be updated (as most probably it means that header isn't present) and a new one is added:

->..1 # This
|...2 # example
|...3 # won't update
|...4 # the
->..5 # header (g:header_max_size)
....6 # as it's not in the range
....7 # 
....8 #  File: foobar.sh
....9
....10

Let me know what you think about it and if you want to give it a try to make suggestions.

@alpertuna
Copy link
Owner

Hi again. I am not available so much nowadays to inspect the issue. However I looked into diff and your improvements looks reasonable. When you are done, you can send PR. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants