Home Download Buy Blog Forum Support

Small script for man page

Re: Small script for man page

Postby Spationaute on Fri Mar 08, 2013 11:45 pm

That doesn't work at all, sorry. I think it's not really my code that doesn't work. I think the "edit" object just change to the input_box and I lose control of it.
Spationaute
 
Posts: 9
Joined: Thu Mar 07, 2013 4:36 pm

Re: Small script for man page

Postby skuroda on Sat Mar 09, 2013 2:56 am

Odd it worked for me. Here is what I tested with.

Code: Select all
import sublime, sublime_plugin
from subprocess import *


class man(sublime_plugin.TextCommand):
    def run(self, edit):
        #Set some global to work whit in
        #other functions
        global aedit
        global window
        global view

        #Get the windows and the view
        aedit=edit
        window = self.view.window()
        view = self.view

        #if the selection is empty, ask for the page
        if view.sel()[0].empty():
           
            window.show_input_panel("Man search :", "", self.input_ret,None,None)
        else:
            #if search is not empty
            word = view.substr(view.sel()[0])
            self.man_search(aedit,word)

    def input_ret(self,text):
        #if an text is set, search it
        if text:
            self.man_search(aedit,text)

    def man_search(self,edit,to_search):
        text = "{}".format(to_search)
        #Open the man panel
        man_panel = window.get_output_panel("man")
        print(man_panel)
        #Wait that the panel is ready
        while man_panel.is_loading():
            pass

        #print the search in console
        print("searching in man: {}".format(text))

        #Command to send
        man_command=["man","-P","cat","-7","-a", text]

        #Open the pipe and redirect stdout to the pipe
        pipe = Popen(man_command,stdout=PIPE,stderr=STDOUT)
        (in_pipe,out_pipe) = pipe.communicate()

        #insert text in the man panel
        man_panel.run_command("simple_insert", {"content": in_pipe.decode("utf-8")})

        #Show the panel
        window.run_command("show_panel",{"panel":"output.man"})


class SimpleInsertCommand(sublime_plugin.TextCommand):
    def run(self, edit, content):
        print(self.view)
        self.view.insert(edit, 0, content)

skuroda
 
Posts: 674
Joined: Fri Oct 05, 2012 8:11 am

Re: Small script for man page

Postby Spationaute on Sat Mar 09, 2013 4:51 pm

Hey! Yes, it's working! It's seem that I was missing the lass class. Thank you :)
I'm happy whit my new script!
Spationaute
 
Posts: 9
Joined: Thu Mar 07, 2013 4:36 pm

Re: Small script for man page

Postby skuroda on Sat Mar 09, 2013 7:33 pm

Glad to hear. Hope you removed those prints I forgot to take out. :D
skuroda
 
Posts: 674
Joined: Fri Oct 05, 2012 8:11 am

Previous

Return to Plugin Announcements

Who is online

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