Home Download Buy Blog Forum Support

Reading PHP help (chm)

Reading PHP help (chm)

Postby agibsonsw on Fri Jun 22, 2012 11:07 pm

I have a copy of the PHP help file - php_enhanced_en.chm - installed on my Windows 7 computer at c:\windows\help. What I want to do is be able to press a key-combination to find help for the current word/function.

I thought it might be possible as a build option and tried variations of:

Code: Select all
{
    // "cmd": ["C:\\Windows\\Help\\php_enhanced_en.chm::/function.${CURRENT_WORD}.html"]
    "cmd": ["C:\\Windows\\Help\\php_enhanced_en.chm::/function.", "$(CURRENT_WORD)"]
}

I don't think a build can interpret ${CURRENT_WORD}. Any suggestions please on how I can get this working? (I have hh.exe available on my system.)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Reading PHP help (chm)

Postby agibsonsw on Fri Jun 22, 2012 11:31 pm

I realised I should be using ${TM_CURRENT_WORD} but still no joy..
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Reading PHP help (chm)

Postby sublimator on Sat Jun 23, 2012 12:45 am

I'm a windows (lo|u)ser too and I've got python docs setup using chm

You can use ctypes to hook into the chm apis for this

I'll post the code when the power comes back on
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Reading PHP help (chm)

Postby sublimator on Sat Jun 23, 2012 1:11 am

Code: Select all
#coding: utf8
#################################### IMPORTS ###################################

#Std Libs
import ctypes
from ctypes.wintypes import BOOL

#################################### HELPERS ###################################

# Force unicode for c_wchar_p
def W(s): return s.decode('utf8') if isinstance(s, str) else s

################################ CTYPES WRAPPING ###############################

HtmlHelp = ctypes.windll.LoadLibrary('hhctrl.ocx').HtmlHelpW

HH_KEYWORD_LOOKUP = 0x000D

class HH_AKLINK(ctypes.Structure):
    _fields_ = (
        # sizeof this structure
        ('cbStruct',     ctypes.c_int),

        # must be FALSE (really!)
        ('fReserved',    BOOL),

        # semi-colon separated keywords
        ('pszKeywords',  ctypes.c_wchar_p),

        # URL to jump to if no keywords found (may be NULL)
        ('pszUrl',       ctypes.c_wchar_p),

        # Message text to display in MessageBox if pszUrl is
        ('pszMsgText',   ctypes.c_wchar_p),
        ('pszMsgTitle',  ctypes.c_wchar_p),

        # Window to display URL in
        ('pszWindow',    ctypes.c_wchar_p),

        # Displays index if keyword lookup fails.
        ('fIndexOnFail', BOOL)
    )

############################## OPEN HELP FUNCTION ##############################

def open_help_for( key_words, # semi-colon separated keywords or sequence
                   help_file, # chm file

                   # URL to jump to if no keywords found
                   backup_url    =  u'',

                   # Displays index if keyword lookup fails.
                   display_index = True,

                   # 0 is fine; using sublime window handle will cause help
                   # to `stay on top`
                   hwnd=0 ):

    key_words = ( u';'.join(key_words) if not isinstance(key_words, basestring)
                                         else W(key_words) )

    ak = HH_AKLINK ( ctypes.sizeof(HH_AKLINK), False, key_words,
                     (W(backup_url) if backup_url else None), None, None,
                     None, display_index )

    HtmlHelp(hwnd, W(help_file), HH_KEYWORD_LOOKUP, ctypes.byref(ak))

################################################################################
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Reading PHP help (chm)

Postby sublimator on Sat Jun 23, 2012 1:14 am

I cut out the help file code from my plugin which relies on my helpers and crap

Code: Select all
open_help_for(key_words, help_file)


Call it like that.
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Reading PHP help (chm)

Postby agibsonsw on Sat Jun 23, 2012 2:08 am

@castles_made_of_sand Thank you for this :) , although I need a little more guidance.

It seems I need to create a TextCommand and pass your function open_help_for() the current word and the path to my php.chm file. Is this correct?
How can I pass ${TM_CURRENT_WORD}, or will I have to add a bit of ST-API-code to read the current word?

This seems a bit more intricate than the simple solution I was aiming for; but perhaps your method has some advantages?

I will certainly give yours a go but, at the same time, I'm still keen to get my version to work ;) . Do you think if I create a key-binding for the command "exec" (or "open"?) that I can supply "args" : ${TM_CURRENT_WORD} and it will work?

Regards, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Reading PHP help (chm)

Postby sublimator on Sat Jun 23, 2012 2:22 am

Yeah, you'll need to write a little TextCommand which gets the current word[s]

ie. `open_help_for(keywords = map(view.substr, view.sel()), path_to_chm)`

I'm not sure how opening help files from the cmd line works as this was the first solution I found back when.

So I don't really know about the relative merits of each way.

I know with subsequent calls to the same chm file, it just reuses the already open window ?

I cobbled it together blind from some random internet source. I didn't even understand the ctypes back then.

But it works for me :) Was more interested in the help file than how I was opening it.
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Reading PHP help (chm)

Postby sublimator on Sat Jun 23, 2012 2:25 am

agibsonsw wrote:Do you think if I create a key-binding for the command "exec" (or "open"?) that I can supply "args" : ${TM_CURRENT_WORD} and it will work?


I'm not sure TM_* vars are expanded here. AFAIK they are only available in snippets?
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Reading PHP help (chm)

Postby agibsonsw on Sat Jun 23, 2012 2:41 am

@castles
I know with subsequent calls to the same chm file, it just reuses the already open window


I was curious about this myself. That is, if I can get my version working - will it close and re-open the help, or possible open another instance. I won't know until I succeed.

If I'm going to have to create a TextCommand anyway then not being able to read TM_CURRENT_WORD will be immaterial. Although, I'm curious if the following might return something:

Code: Select all
os.environ['TM_CURRENT_WORD']


I think I'll create a TextCommand and try os.system() or process.call() or something similar. Once I've conquered this I'll return to your version. Ta, Andy.

PS I tried looking into ctags previously, but I couldn't find a simple description of what it does..
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Reading PHP help (chm)

Postby sublimator on Sat Jun 23, 2012 2:48 am

How do you open a chm from the command line with a particular keyword?

Manually building one of those commands you mentioned doesn't work for me in a console:

Code: Select all
C:\Program Files\Microsoft Visual Studio 9.0\VC>C:\Python27\Doc\python271.chm::/index.html
The filename, directory name, or volume label syntax is incorrect.
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Next

Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 26 guests