drmikehenry / vim-fontsize

Adjust Gvim font size via keypresses
42 stars 5 forks source link

Not working with MacVim on Mac OS? #1

Closed januz closed 10 years ago

januz commented 10 years ago

Thanks for the plugin, but I don't seem able to get it to work.

When I execute + (or =), the plugin responds with: ??: Monaco for Powerline: 11 (...) ??: Monaco for Powerline: 11 (Done)

but the font size is not changed. Am I doing something wrong or does the plugin maybe not work with MacVim?

drmikehenry commented 10 years ago

Hi, Januzz,

Though I don't have access to a Mac and I have little experience with Apple machines, I have reports that the plugin works on OS/X.

The ??: from the plugin indicates that it doesn't understand the format of 'guifont'. The plugin is seeing 'guifont' set to Monaco for Powerline: 11 which lacks the expected h before the font size. From :help 'guifont' there is this example:

    For Mac OSX you can use something like this:
        :set guifont=Monaco:h10

It should work if you set your font this way:

set guifont=Monaco\ for\ Powerline:h11

Let me know if that solves the problem.

januz commented 10 years ago

Sorry, seemingly my comment got lost, so I am writing it again...

Sadly, I am already using

set guifont=Monaco\ for\ Powerline:h11

in my .vimrc

I experimented with setting the font manually and setting another font, but I still always get ?? Is there anything else I can do to research the problem?

drmikehenry commented 10 years ago

First you can verify that your 'guifont' was set correctly by displaying it as follows:

:echo &guifont

This will display as a normal string, without backslashes escaping the spaces. In your case, you should see "Monaco for Powerline:h11".

The plugin checks what kind of GUI is running with the following logic found in autoload/fontsize.vim:

if has("gui_gtk2")
    let s:regex = fontsize#regex_gtk2
elseif has("gui_photon")
    let s:regex = fontsize#regex_photon
elseif has("gui_kde")
    let s:regex = fontsize#regex_kde
elseif has("x11")
    let s:regex = fontsize#regex_x11
else
    let s:regex = fontsize#regex_other
endif

You could try the following echo commands to see which of these are true:

:echo has("gui_gtk2")
:echo has("gui_photon")
:echo has("gui_kde")
:echo has("x11")

On your platform, I'd expect all of these to display 0. If any display 1 instead, then the regular expression will be incorrect.

Assuming these are correct, then the regular expression fontsize#regex_other will be selected for your system.

This regular expression is used in the fontsize#getSize() function shown below:

function! fontsize#getSize(font)
    let decodedFont = fontsize#decodeFont(a:font)
    if match(decodedFont, s:regex) != -1
        " Add zero to convert to integer.
        let size = 0 + substitute(decodedFont, s:regex, '\2', '')
    else
        let size = 0
    endif
    return size
endfunction

You should be able to invoke this function to show it working for a couple of hypothetical font names:

:echo fontsize#getSize("Monoco:h11")
:echo fontsize#getSize("Monoco for Powerline:h11")

These should all display 11 if the regular expression was selected correctly.

You can also check the result using your actual 'guifont' setting:

:echo fontsize#getSize(&guifont)

These tests should narrow down the problem a bit more.

januz commented 10 years ago

Thanks for your advice!

Strangely, all of your recommended tests come out the way expected! Are there maybe any known incompabilities with other plugins?

Thanks!

drmikehenry commented 10 years ago

I don't know of any such incompatibilities, but trying with all other plugins disabled would be a good idea.

There is not much left to the plugin's logic. You can try manually invoking fontsize#fontString() on your 'guifont':

echo fontsize#fontString(&guifont)

It should display something like this:

11: Monaco for Powerline:h11

The only addition here over the previous tests is the invocation of fontsize#decodeFont(). That function was added for an Asian user with encoded font names. You can verify that function directly as well:

echo fontsize#decodeFont(&guifont)
drmikehenry commented 10 years ago

The only other thing I can suggest is that your font may not be present. Vim is willing to allow you to set 'guifont' to anything you want before the GUI actually starts (e.g., from within .vimrc), because until the GUI begins it has no way of sanity-checking that the font is valid (and even then, on some platforms it can never sanity-check the font). It may be enlightening for you to manually set 'guifont' after the GUI has begun to make sure the font is being detected properly:

:set guifont=Monaco\ for\ Powerline:h13

You can also try using let:

:let &guifont="Monaco for Powerline:h13"

Afterward, verify that the font is now larger and that 'guifont' holds what you expect:

:echo &guifont
januz commented 10 years ago

Hm, everything seems to be OK, the error also happens with other fonts...

jszakmeister commented 10 years ago

@Januzz It's a bug in MacVim. I fixed it several weeks ago: https://github.com/b4winckler/macvim/pull/37

The issue is that getfontname() was implemented incorrectly. It would leave off the 'h' for the size, and then fontsize would fail to set the font correctly as a result. I believe Ben released a new version of MacVim recently (snapshot 72) that contains my fix. HTH!

januz commented 10 years ago

Ahhh, thank you!!! I was starting to worry...