tm_query --setting fontName

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

tm_query --setting fontName

dangerwillrobinsondanger
Hello all,

I'm looking to fix up the old TextMate Python Jedi completion bundle.
The docstring viewer command returns this error.

Setting or variable 'fontName' not found
Traceback (most recent call last):
  File "Docstrings for word", line 10, in <module>
    completion.show_docstrings()
  File "/Users/myaccount/Library/Application Support/TextMate/Pristine Copy/Bundles/python-jedi.tmbundle/Support/completion.py", line 132, in show_docstrings
    font_name = subprocess.check_output([tm_query, '--setting', 'fontName']).rstrip() or "Menlo-Regular"
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 573, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/Applications/TextMate.app/Contents/Resources/tm_query', '--setting', 'fontName']' returned non-zero exit status 69



This is because the CLI command says no such key exists.
/Applications/TextMate.app/Contents/Resources/tm_query --setting fontName
Setting or variable 'fontName' not found

Is there a modern alternative to fontName?
Or, even better, a reference for that and other keys?

thanks!
JJ


_______________________________________________
textmate mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tm_query --setting fontName

Allan Odgaard-4

On 3 Jul 2017, at 23:07, じょいすじょん wrote:

Setting or variable 'fontName' not found
[…]
Is there a modern alternative to fontName?
Or, even better, a reference for that and other keys?

There is no good solution for this.

The tm_query tool is simply reading your various .tm_properties files (including the Default.tmProperties included with TextMate) and returning the requested value (or exiting with a non-zero return code if not found). So there is no fixed list of keys.

Originally the Default.tmProperties file had a setting for fontName but because Apple has changed the default fixed width font, it wasn’t good to put a hardcoded name in Default.tmProperties (since TextMate should default to the fixed width font that is default for the user’s OS version).

I am not sure for what the TextMate Jedi Completion bundle uses the font name, but it will need its own fallback, incase $TM_QUERY exits with a non-zero return code.

You can hardcode the fallback as Menlo-Regular but technically the user can override the system’s default fixed width font using the NSFixedPitchFont user defaults setting.

This can be obtained using: defaults read -g NSFixedPitchFont

The default size can be changed using the NSFixedPitchFontSize key.



_______________________________________________
textmate mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tm_query --setting fontName

dangerwillrobinsondanger

On Jul 12, 2017, at 23:43, Allan Odgaard <[hidden email]> wrote:

On 3 Jul 2017, at 23:07, じょいすじょん wrote:

Setting or variable 'fontName' not found
[…]
Is there a modern alternative to fontName?
Or, even better, a reference for that and other keys?

There is no good solution for this.

The tm_query tool is simply reading your various .tm_properties files (including the Default.tmProperties included with TextMate) and returning the requested value (or exiting with a non-zero return code if not found). So there is no fixed list of keys.

Originally the Default.tmProperties file had a setting for fontName but because Apple has changed the default fixed width font, it wasn’t good to put a hardcoded name in Default.tmProperties (since TextMate should default to the fixed width font that is default for the user’s OS version).

I am not sure for what the TextMate Jedi Completion bundle uses the font name, but it will need its own fallback, incase $TM_QUERY exits with a non-zero return code.

You can hardcode the fallback as Menlo-Regular but technically the user can override the system’s default fixed width font using the NSFixedPitchFont user defaults setting.

This can be obtained using: defaults read -g NSFixedPitchFont

The default size can be changed using the NSFixedPitchFontSize key.


OK, got it. So the response is correct, the key doesn't exist.
The defaults keys you provided also do not exist by default on my system.
But a font descriptor would return a user preference or a system default.
There's not a great solution you're right.
Core Text and AppKit are both kind of vague.
The solution there seems to be to start with a font and apply the fixed width trait to get a descriptor for a font that comes close to matching somehow (who knows how? personal taste?) or present a UI and let a user select something. Still does not give a default does it? How loopy these APIs can be :(


_______________________________________________
textmate mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tm_query --setting fontName

Allan Odgaard-4

On 12 Jul 2017, at 17:22, じょいすじょん wrote:

The defaults keys you provided also do not exist by default on my system.

Correct, this would only be if the user has explicitly changed the default fixed width font.

Core Text and AppKit are both kind of vague.
The solution there seems to be to start with a font and apply the fixed width trait to get a descriptor for a font that comes close to matching somehow (who knows how? personal taste?) or present a UI and let a user select something. Still does not give a default does it? How loopy these APIs can be :(

NSFont has a method to return the default fixed width font, from Python you can use this code to obtain it:

#!/usr/bin/python
import objc
from AppKit import NSFont

font = NSFont.userFixedPitchFontOfSize_(0)
print("family: %s, name: %s, size: %.1f" % (font.familyName(), font.fontName(), font.pointSize()))

On my system it prints:

family: Menlo, name: Menlo-Regular, size: 11.0

I deliberetly hardcoded the shebang to call /usr/bin/python as PyObjC (the Cocoa bridge used here) may not be installed for a custom python on the user’s system.



_______________________________________________
textmate mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tm_query --setting fontName

dangerwillrobinsondanger

On Jul 13, 2017, at 5:48, Allan Odgaard <[hidden email]> wrote:

On 12 Jul 2017, at 17:22, じょいすじょん wrote:

The defaults keys you provided also do not exist by default on my system.

Correct, this would only be if the user has explicitly changed the default fixed width font.

Core Text and AppKit are both kind of vague.
The solution there seems to be to start with a font and apply the fixed width trait to get a descriptor for a font that comes close to matching somehow (who knows how? personal taste?) or present a UI and let a user select something. Still does not give a default does it? How loopy these APIs can be :(

NSFont has a method to return the default fixed width font, from Python you can use this code to obtain it:

#!/usr/bin/python
import objc
from AppKit import NSFont

font = NSFont.userFixedPitchFontOfSize_(0)
print("family: %s, name: %s, size: %.1f" % (font.familyName(), font.fontName(), font.pointSize()))

On my system it prints:

family: Menlo, name: Menlo-Regular, size: 11.0

I deliberetly hardcoded the shebang to call /usr/bin/python as PyObjC (the Cocoa bridge used here) may not be installed for a custom python on the user’s system.

Thanks Allan, you basically wrote everything I needed.
You even reminded me implicitly that passing 0 or 0.0 gives a default size.
Good callout about which Python to use.
Specifically, regarding the PyObjC part, though older, it is more integrated than the non bundled PyObjC in a few subtle ways.
Most people will need to know that.
The bridge is older but is the one built and used by Apple. 


What are the best options for displaying the completions?
Some implementations on other editors these days are showing some inline docs snippets along with the completions.
Is that sort of thing feasible under the current TM architecture?






_______________________________________________
textmate mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate
Loading...