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

Add support for text-minimap (WIP) #53

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Usage

Default mappings: `<Leader>mm` to display the minimap, `<Leader>mc` to close it.

To overwrite the default keybindings, using following settings in ``.vimrc'':
To overwrite the default keybindings, using following settings in `.vimrc`:

```
let g:minimap_show='<leader>ms'
Expand All @@ -56,6 +56,11 @@ let g:minimap_close='<leader>gc'
let g:minimap_toggle='<leader>gt'
```

# Speed up with `text-minimap`

`vim-minimap` supports [`text-minimap`](https://github.com/dpc/text-minimap) for
accelerating minimap rendering. Follow `text-minimap` installation instructions.

Settings
--------

Expand Down
37 changes: 26 additions & 11 deletions autoload/minimap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
PY3 = sys.version_info[0] == 3

import vim
import subprocess
import shutil

# Add the library to the Python path.
for p in vim.eval("&runtimepath").split(','):
Expand Down Expand Up @@ -162,20 +164,33 @@ def draw(lengths,indents, startline=0):
highlight_group = vim.eval("g:minimap_highlight")
lengths = []
indents = []

first = max(1, topline - 80)
last = min(bottomline + 80, len(src.buffer))
for line in range(first, last):
linestring = src.buffer[line]
indents.append(len(linestring) - len(linestring.lstrip()))
lengths.append(len(linestring))

vim.command(":setlocal modifiable")

minimap.buffer[:] = draw(lengths,indents)
first = max(1, topline - 160)
last = min(bottomline + 160, len(src.buffer))
scale = 4

# TODO: this check could be done once at the start
#text_minimap_path = shutil.which("text-minimap")
#if text_minimap_path is None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using a snippet like that: http://stackoverflow.com/a/377028/828379 to check whether text-minimap is available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea. I tried shutil.which in repl and it worked. And I'm getting syntax error that I can't understand, so I am puzzled.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the reason is that which has been added to shutil in Python 3, but does not exist in Python 2 :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Thanks for helping me with this. That would explain it...

¯_(ツ)_/¯ Python...

Anyway, I've been using this plugin with my changes and there are some weird things going on with selection on the original source code buffer, and I'm not sure if it's because of my changes. Need to investigate. Just letting you know.

Though I'm really happy about the speed now. :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I let you first update your PR with the suggested code to detect text-minimap, then investigate the selection issue. I'll merge your PR as soon as you think it is ready.

Copy link
Contributor Author

@dpc dpc Apr 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's not a problem with this patch. Sometimes redrawing the minimap messes with the current visual selection.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smooth my ass... its nightmare :( why so lagging on my nvim?

# I hate Python in the first place and can't figure why the above
# doesn't work, while it should, so I've put a `False` there instead
# and called it a day. Please put me out of my misery.
if False:
for line in range(first, last):
linestring = src.buffer[line]
indents.append(len(linestring) - len(linestring.lstrip()))
lengths.append(len(linestring))

minimap.buffer[:] = draw(lengths,indents)
else:
proc = subprocess.Popen(["text-minimap", "--xscale", "4", "--yscale", "2"], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
minimap.buffer[:] = proc.communicate(input="\n".join(src.buffer[first-1:last]).encode())[0].decode("utf-8").split("\n")
scale = 8

# Highlight the current visible zone
top = int((topline - first) / 4)
bottom = int((bottomline -first)/ 4 + 1)
top = int((topline - first) / scale)
bottom = int((bottomline - first + (scale - 1))/ scale + 1)
vim.command("match {0} /\\%>0v\\%<{1}v\\%>{2}l\\%<{3}l./".format(
highlight_group, WIDTH + 1, top, bottom))

Expand Down