Home Download Buy Blog Forum Support

Reading PHP help (chm)

Re: Reading PHP help (chm)

Postby agibsonsw on Sat Jun 23, 2012 3:05 am

Doh! Hadn't occurred to me yet to try it from a command line.

Code: Select all
hh.exe c:\windows\help\php_enhanced_en.chm::/res/function.range.html

..works for me. I had to specifically call 'hh.exe' (HtmlHelp). And /res was not mentioned when I googled earlier.

But I notice a second instance opening. I'll have to see how, and whether, it behaves from a TextCommand. I tried subprocess.call() from the Console and it returned 1 but didn't open (that I noticed) the .chm.

Added: Also, if you open the .chm and visit a page, then choose the View menu, URL, you'll see something like:

Code: Select all
mk:@MSITStore:C:\Windows\Help\php_enhanced_en.chm::/res/index.html
"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 Sat Jun 23, 2012 3:14 am

Code: Select all
subprocess.call("hh.exe mk:@MSITStore:C:\\Windows\\Help\\php_enhanced_en.chm::/res/function.range.html",shell=True)


works from the console, but suspends/crashes ST until I close .chm - with either shell=True or False. But it IS progress..
"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 3:24 am

subprocess.call() waits for the command to return

you could use `start` or `cmd /k` (can't recall, on my mactard book atm) and shell=True, along with the hide console window flags

or use subprocess.Popen directly (call is a wrapper) and don't call wait()
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 3:28 am

He, he you're a minute ahead of (or behind?) me:

Code: Select all
subprocess.Popen("hh.exe mk:@MSITStore:C:\\Windows\\Help\\php_enhanced_en.chm::/res/function.range.html",shell=False)


I'll try as a TextCommand later and see if two instances occur. Actually, just ran it again from the Console with a different fn and two instances are open. Mmm. I'll have to dig deeper. I need to somehow kill the first instance.
"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 Sat Jun 23, 2012 11:58 am

Cool, got this working:

Code: Select all
import sublime, sublime_plugin
import subprocess

PHP_HELP = \
"""hh.exe mk:@MSITStore:C:\\Windows\\Help\\php_enhanced_en.chm::/res/function.%(func)s.html"""

class PhpHelpCommand(sublime_plugin.TextCommand):
    proc1 = None
    def run(self, edit):
        curr_view = self.view
        if not curr_view.match_selector(0, 'source.php'): return
        word_end = curr_view.sel()[0].end()
        if curr_view.sel()[0].empty():
            word = curr_view.substr(curr_view.word(word_end)).lower()
        else:
            word = curr_view.substr(curr_view.sel()[0]).lower()
        if word is None or len(word) <= 1:
            sublime.status_message('No function selected')
            return
        word = word.replace('_', '-')
        try:
            if self.proc1 is not None:
                self.proc1.kill()
        except Exception:
            pass
        self.proc1 = subprocess.Popen(PHP_HELP % { "func": word }, shell=False)

I like the possibilities for this:

Could have one key-binding which would work with many languages (providing there is a .chm file available for the language);
[the TextCommand could check the current file-syntax and search the corresponding .chm]
Consistency of behaviour;
Limited set-up required, possibly none if the help file is in a default location;
If a function search fails, it could then be made to search for a method or class.

For example, my JavaScript .chm search looks like this:

Code: Select all
mk:@MSITStore:C:\Windows\Help\javascript.chm::/jsref_decodeURI.htm
"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 Sat Jun 23, 2012 12:46 pm

Here's a working proof of concept, that will open either a PHP or JS .chm help file on a single keybinding:

Code: Select all
import sublime, sublime_plugin
import subprocess

PHP_HELP = \
"""hh.exe mk:@MSITStore:C:\\Windows\\Help\\php_enhanced_en.chm::/res/function.%(func)s.html"""
JS_HELP = \
"""hh.exe mk:@MSITStore:C:\\Windows\\Help\\javascript.chm::/jsref_%(func)s.htm"""

class LanguageHelpCommand(sublime_plugin.TextCommand):
    proc1 = None
    def run(self, edit):
        curr_view = self.view
        curr_sel = curr_view.sel()[0]
        if curr_view.match_selector(curr_sel.begin(), 'source.php'):
            source = 'PHP'
        elif curr_view.match_selector(curr_sel.begin(), 'source.js'):
            source = 'JS'
        else:
            return

        word_end = curr_sel.end()
        if curr_sel.empty():
            word = curr_view.substr(curr_view.word(word_end)).lower()
        else:
            word = curr_view.substr(curr_sel).lower()
        if word is None or len(word) <= 1:
            sublime.status_message('No function selected')
            return
        if source == 'PHP':
            word = word.replace('_', '-')
            HELP = PHP_HELP % { "func": word }
        elif source == 'JS':
            HELP = JS_HELP % { "func": word }
        try:
            if self.proc1 is not None:
                self.proc1.kill()
        except Exception:
            pass
        self.proc1 = subprocess.Popen(HELP, shell=False)

If anyone is interested in trying this then you'll need to revise the path and filename to your JS and PHP .chm files. You'll also need the file 'hh.exe'. This may already be on your (Windows) computer - mine's at 'C:\Windows\', so I don't need to provide a path to it. I believe a more recent version of this HTMLHelp file is named 'keyhh.exe'.

[Also, ensure that the .chm files are unblocked.]

My key-binding:
Code: Select all
{ "keys": ["ctrl+f1"], "command": "language_help" },
"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 Sat Jun 23, 2012 1:10 pm

Unfortunately, the Python help file (pydoc.chm) looks unworkable (I already have a help feature for this anyway..), but jQuery looks very good:

Code: Select all
# The Python help file is a mess:
# mk:@MSITStore:C:\Windows\Help\pydoc.chm::/library/stdtypes.html#str.replace
# jQuery:
# mk:@MSITStore:C:\Windows\Help\jqdoc.chm::/api/add.html
"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 Sat Jun 23, 2012 3:52 pm

If you are able to specify jQuery syntax, and can track down jQuery-UI-Reference-1.7.chm or similar, then:

Code: Select all
import sublime, sublime_plugin
import subprocess

PHP_HELP = \
"""hh.exe mk:@MSITStore:C:\\Windows\\Help\\php_enhanced_en.chm::/res/function.%(func)s.html"""
JS_HELP = \
"""hh.exe mk:@MSITStore:C:\\Windows\\Help\\javascript.chm::/jsref_%(func)s.htm"""
jQuery_HELP = \
"""hh.exe mk:@MSITStore:C:\Windows\Help\jQuery-UI-Reference-1.7.chm::/api/%(func)s.htm"""

# The Python help file is a mess:
# mk:@MSITStore:C:\Windows\Help\pydoc.chm::/library/stdtypes.html#str.replace
# mk:@MSITStore:C:\Windows\Help\jqdoc.chm::/api/add.html # jQuery 1.4
# mk:@MSITStore:C:\Windows\Help\css-2.1.chm::/colors.html#propdef-background-color
# mk:@MSITStore:C:\Windows\Help\css-2.1.chm::/box.html#propdef-border-top

class LanguageHelpCommand(sublime_plugin.TextCommand):
    proc1 = None
    def run(self, edit):
        curr_view = self.view
        curr_sel = curr_view.sel()[0]
        if curr_view.match_selector(curr_sel.begin(), 'source.php'):
            source = 'PHP'
        elif curr_view.match_selector(curr_sel.begin(), 'source.js.jquery'):
            source = 'JQUERY'
        elif curr_view.match_selector(curr_sel.begin(), 'source.js'):
            source = 'JS'
        else:
            return

        word_end = curr_sel.end()
        if curr_sel.empty():
            word = curr_view.substr(curr_view.word(word_end)).lower()
        else:
            word = curr_view.substr(curr_sel).lower()
        if word is None or len(word) <= 1:
            sublime.status_message('No function selected')
            return
        if source == 'PHP':
            word = word.replace('_', '-')
            HELP = PHP_HELP % { "func": word }
        elif source == 'JQUERY':
            HELP = jQuery_HELP % { "func": word }
        elif source == 'JS':
            HELP = JS_HELP % { "func": word }
        try:
            if self.proc1 is not None:
                self.proc1.kill()
        except Exception:
            pass
        self.proc1 = subprocess.Popen(HELP, shell=False)

Unfortunately, CSS, HTML and Python .chm files are unworkable :(
"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 Sat Jun 23, 2012 4:59 pm

.. I might even considering bundling all these .chm files together into a Package. This way, it wouldn't require any set up at all :D (but Windows only).

I am aware that there are already help systems available, and they are certainly more comprehensive. This version would only look up functions OR methods.

ON the other hand, this would:
Not require any detailed set-up;
Be quick and consistent.
"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 Sat Jun 23, 2012 8:02 pm

And finally.. I won't be pursuing this much further :( . Most .chm files are unworkable for this. They either put things in different subfolders, use numbered bookmarks, or complex code numbers.

But my previous code works for PHP functions, JS, and jQuery methods. 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

Previous

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 33 guests