racer-rust / emacs-racer

Racer support for Emacs
399 stars 48 forks source link

Fix column calculations when symbol rewriting is in effect #52

Closed dagit closed 7 years ago

dagit commented 7 years ago

Some ways of changing the displayed contents of the buffer do not play well with the current way of calculating the column offset.

For example, I wanted to use Fira Code with racer-mode. I found this trick to make firacode work: https://gist.github.com/mordocai/50783defab3c3d1650e068b4d1c91495

The problem is that using font-lock-symbols to change the displayed symbol (replacing 2 glyphs with 1 glyph) is throwing off the column calculation in racer mode. The code in this pull request uses the string-width of the underlying string representation to calculate the column. This should match what racer sees when it parses the file.

I don't know if I applied this fix to all the places where columns are used. I could use some code review for that. Doing the calculation this way should also future proof against people using prettify-symbols-mode.

I also tried changing the character width in the char-width-table but I couldn't get that version to work. If we can make that work it's a better solution because the column information in emacs will be correct.

Wilfred commented 7 years ago

Thanks for your contribution! :)

This must have been a subtle issue to debug. I agree this is worth fixing.

dagit commented 7 years ago

I updated the PR. Thanks for the suggestions and the quick response! This version still uses buffer-substring-no-properties as my understanding is that will most accurately match what is written to the file. I think buffer-substring can sometimes return fontification information. At least that's what the emacs manual seemed to be saying (or else I was misunderstanding it).

Wilfred commented 7 years ago

Thank you :)