The quick hack would be to modify "_exec_custom_tool()" in

Below my -- untested ! -- modified version of the routine.

As you might guess the .desktop file for the custom tool (see
.config/zim/customtools) should contain a key "X-Zim-ReplaceSelection" set
to "True".

If this works, also the custom tool dialog (defined in
zim/gui/ should be updated to add that key as a checkbox.

I can also imagine a similar key to insert output text at the cursor.

Please try it out and let me know if you get it to work.



    def _exec_custom_tool(self, action):
        manager = CustomToolManager()
        tool = manager.get_tool(action.get_name())'Execute custom tool %s',
        args = (self.notebook,, self.mainwindow.pageview)
            if tool.isreadonly:
            elif tool['Desktop Entry'].get('X-Zim-ReplaceSelection', False):
                output = tool.pipe(args)
                pageview = self.mainwindow.pageview # XXX
                buffer = pageview.view.get_buffer() # XXX
                if buffer.get_has_selection():
                    start, end = buffer.get_selection_bounds()
                    with buffer.user_action:
                        buffer.delete(start, end)
                    pass # error here ??
                # TODO instead of using run, use spawn and show dialog
                # with cancel button. Dialog blocks ui.
        except Exception, error:
            ErrorDialog(self, error).run()

On Wed, Jun 18, 2014 at 8:36 AM, Sylvain Viart <>

> Le 18/06/2014 05:07, Jaap Karssenberg a écrit :
> > sort lines plugin can be an example how to do[…]
> [start hacking to perform our own custom modification on selected text]
> > Another option is to patch the code calling custom tools and allow a
> > custom tool to filter the selected text from stdin to stdout and have
> > zim replace the selection when you call it.
> Sounds pretty cool. Could you point me some entry point in the code so I
> can start hacking may be.
> Is there a wish list tickets around or something?
> Regards,
> Sylvain.
> _______________________________________________
> Mailing list:
> Post to     :
> Unsubscribe :
> More help   :
Mailing list:
Post to     :
Unsubscribe :
More help   :

Reply via email to