iago-lito / vim-visualMarks

mark and retrieve selections in Vim
GNU General Public License v2.0
20 stars 6 forks source link

Now enter is not necessary to be pressed. #1

Closed hallzy closed 9 years ago

hallzy commented 9 years ago

Hi, this is Steven Hall. I had provided a starting point on stack overflow for this project.

I found a way to get rid of the need to press enter, which I have in this pull request. It did also remove some trailing whitespaces because my vimrc does that automatically for me...

Also, If you go to my vimrc I have also made some additions since I last posted that gives persistence, where it writes to a file... as I am writing this, this feature is on the bottom of my vimrc.

Feel free to add the parts to make it persistent, or if you would rather, I can do it.

I should note, that it is persistent, but it does not check files, so the marks will be the same across multiple files, and if you write a mark to register a (for example), and then in a different file to the same, it will be overwritten (I do also have overwrite functionality in it so that you do not get duplicate entries).

The data is stored in the form: "register character" "start line" "start col" "end line" "end col"

hallzy commented 9 years ago

Ignore what I said about the persistence, I have added that to this pull request.

Note that the file that it reads the information from to be persistent is /home/steven/.vim-vis-mark

I was unable to use the ~ for /home/steven with the readfile. I plan on making it work this way because I realize that not eveyones name is Steven :)

I also realize that I did change some things that you may not want changing, so take what you need. For example, I removed the global variable because the way I had it implemented I did not see the need for it.

So ya, feel free to use the parts you want, and change it. I will continue to help you finish this until it is the way you imagined it to be... no point in starting something if you wont finish it :)

hallzy commented 9 years ago

Also, the way that the file is edited should probably be changed. At present, it is actually just opening a new buffer and closing it, which slows down the mapping. In most cases it still works without much notice, but it was meant more as a temp solution to get the correct functionality. It would probably be better to use the wrtiefile() function in vim instead.

iago-lito commented 9 years ago

Hi, I think I've just merged hallzy-master into master, but I am not sure I did it right (this is my first git :"). Is everything okay for you? I fixed the /home/<username> problem, along with a bug with a variable name. Good job for the enter key, getchar() was the function needed indeed. It is starting to feel snappy :)

I am investigating about the best way to save the marks. Opening and closing a file with this kind of 'macro' isn't truly satisfying indeed. Let's keep up with the good work!

hallzy commented 9 years ago

I think it missed my very last change... I added a global variable for the path, but that appears to be solved by you now anyways, and I also removed one of the buffer creations and inserted a writefile to replace it...

It looks like github has recognized the merge conflict, so I will go ahead and recommit it now.

hallzy commented 9 years ago

That should be fixed now... There should be a button in this pull request that will let you automatically merge everything.

iago-lito commented 9 years ago

Hmm, I can't tell what this button did. I can see some of your newest changes, but your declaration of g:filen disappeared. Should I declare it back again then commit back again?

hallzy commented 9 years ago

If you want a way to communicate with this, or if you have questions about git, you can email me at Hallzy.18@gmail.com if you want.

I think writefile() might be the way to go, so if we can change all the buffer creations to that it should be better and definitely faster. If we can find something better that would be nice as well.

I am not sure how well this will work with windows as of right now, because when I last tried it on windows gvim it complained about the path of the file when I tried to insert a path into the file so that we can have marks saved for individual files. writefile() also did not work properly for windows. Each list that is added by writeline is supposed to be on a new line, but in windows it isnt.

I think this is because in the linux world, a newline is \r\n while linux and mac is just \n. So if gvim is sending a \n instead of a \r\n on windows, that would probably be what is causing the problem.

So that might be something worth looking into

hallzy commented 9 years ago

woops sorry that was not your fault that was me... I thought you had removed that variable from the functions when you added the $HOME in the path... I will add it back and I will make the variable $HOME . "/.vim-vis-mark" as well.

iago-lito commented 9 years ago

Good. I won't be able to test it on a Windows. But I am interested in making the marks specific to each file.

The thing is that it would be pretty straightforward with a dictionnary (something like {'/path/to/a/file' : {'a' : [5, 48, 7, 2], 'b' : [12, 1, 15, 1]}, '/path/to/another' : {'a': [9, 10, 9, 30]}}), but I am not sure whether there is an easy way to save this to the disk in VimScript. I've left a post there about it.

If there was not, then we would go with a bit of organization of .vim-vis-mark. What about:

/path/to/a/file
a 5 48 7 2
b 12 1 15 1
/path/to/another
a 9 10 9 30

then utilities function to clean it, move and rename files, etc? But waiting first for a way to save the dictionnary might be worth it.

hallzy commented 9 years ago

that is actually what I was trying to do before. it ended up being more difficult than expected, so I left it for now so that I could at least get the marks in the file.

The viminfo file stores registers etc in a similar way so it must be possible.

The dictionary would make things cleaner for sure though.

iago-lito commented 9 years ago

Yope. See the Stack for a way to do so with string, apparently. Let me implement some two small SaveVariable and ReadVariable (which might prove to be useful in many cases later anyway), then it'll be smooth to feature file-specific marks ;)