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

Allow editing files without breaking bookmark jumps #12

Closed
MattesGroeger opened this issue Mar 17, 2014 · 4 comments
Closed

Allow editing files without breaking bookmark jumps #12

MattesGroeger opened this issue Mar 17, 2014 · 4 comments
Labels
Milestone

Comments

@MattesGroeger
Copy link
Owner

The reason for that is, that our own model (g:bm_entries) doesn't get updated when lines are added above/below the bookmark. That means our model and and the displayed signs easily get out of sync. Also I don't know of any solution yet on how to properly update our own model after the user edits the file (does someone know?).

Solution

  • Get all the signs and parse our own ones out of the string:
  redir => signs
  silent execute ":sign place"
  redir END
  " @todo parse signs string
  • Use these information to populate the quickfix window
  • Remove line_nr from our own model
  • Remove the option to disable signs
  • This way we will always jump to the position where the sign is actually displayed

Concerns

  • Depending on how many signs are used, the parsing could be performance-intensive
  • Not sure yet how reliable the string parsing would be
@alexandnpu
Copy link

It is surely a performance killer if the marks get updated when user is typing. If you do implement this one, I think it'd better to leave a option there to determine whether the marks will get updated dynamically; thus, users cares about performance can benefit that.

For me, bookmarks are used when i am reading code. If massive code is being written, I seldom use bookmarks.

@alexandnpu
Copy link

My solution for this might be: keep the bookmarks sorted by their line numbers.then when the file is being edited. you can use binary search to quickly updated the bookmarks.
If only the bookmark line is modified, the bookmark content that this plugin maintains also needs to update.

@MattesGroeger
Copy link
Owner Author

I agree with you that bookmarks are mainly used for read-only tasks. But in the current state line number and visual display get easily out of sync by just adding one line on top. That should be addressed.

Actually we would not have to update after each edit because:

  • Signs (and therefore highlights) move automatically in the proper line and update their line number
  • We can use sign jumps for prev/next navigation (no need to update line numbers for that)
  • We need to refresh line numbers only when:
    • A new bookmark get's added, as the order could have changed (because of previous edits)
    • When leaving a buffer (via autocommand BufLeave), so we can get latest line number and content
    • When showing the quickfix window update, the current buffer only

When updating one buffer we can just ask for the signs in the current buffer (:sign place file={fname}) which reduces the amount of parsing greatly.

I don't quite understand your second comment as I don't know of any autocommand that notfies us about edits in a buffer. I'm also not clear what you would binary-search for?

Thanks for your thoughts!

@MattesGroeger
Copy link
Owner Author

Alright, I created branch where I tried the new approach: 48cf995

If you don't mind please have a look and give it a try. I don't think performance will become a problem. Even though there is one more case where I had to update the line numbers based on the signs: When I jump to the prev/next bookmark.

@MattesGroeger MattesGroeger changed the title Use sign line numbers instead of our own model Allow editing files without breaking bookmark jumps Mar 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants