Patch proposal for PerlDoc at cursor

  • Karl Forner

    Karl Forner - 2009-06-10


    This is my very first attempt at hacking EPIC and an eclipse plugin.

    [I can not use the CVS version because I am stuck behind a corporate firewall,  so switching to subversion would solve this issue. So that explains why it's not easy to provide patches.]

    I've added a little feature to the 'Perldoc' action. If there's no selection, I try to use instead  the perl element at the cursor (cheap emulation of the corresponding xemacs perl-mode feature).

    To do this I use the perl partitioner.
    The only annoying thing I've noticed is that it only selects "Foo" if the cursor is in the "Foo"part of the text  "Foo::Bar" : it does not extend to the full package name.

    I'd like to see implemented (by me or others) :

    - the Pod of the current perl source (like the javadoc view of the JDT)
    - a HTML (or Rich text) formatted view
    - to have the Table of Contents first (like in
    - to extend word recognition at cursor to full package names.

    I 'd appreciate a lot any help for that.



    My changes:
    add to

        public PerlSourceViewer getPerlSourceViewer() {
            return sourceViewer;

    , and this is the new
    package org.epic.perleditor.actions;

    import org.eclipse.core.runtime.CoreException;
    import org.eclipse.jface.dialogs.InputDialog;
    import org.eclipse.jface.dialogs.MessageDialog;
    import org.eclipse.jface.text.BadLocationException;
    import org.eclipse.jface.text.IDocument;
    import org.eclipse.jface.text.ITypedRegion;
    import org.eclipse.jface.text.TextSelection;
    import org.eclipse.jface.window.Window;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.ui.IWorkbenchPage;
    import org.eclipse.ui.PartInitException;
    import org.eclipse.ui.texteditor.ITextEditor;
    import org.epic.core.ResourceMessages;
    import org.epic.core.util.StatusFactory;
    import org.epic.perleditor.PerlEditorPlugin;
    import org.epic.perleditor.editors.PartitionTypes;
    import org.epic.perleditor.editors.PerlEditor;
    import org.epic.perleditor.editors.PerlEditorActionIds;
    import org.epic.perleditor.popupmenus.PopupMessages;
    import org.epic.perleditor.views.PerlDocView;

    public class PerlDocAction extends PerlEditorAction {
        // ~ Constructors

        public PerlDocAction(PerlEditor editor) {

        // ~ Methods

        protected void doRun() {
            ITextEditor editor = getEditor();

            String selection = ((TextSelection) editor.getSelectionProvider()
            Shell shell = PerlEditorPlugin.getWorkbenchWindow().getShell();

            // MessageDialog.openError(shell, "doRun", "coucou");

            // try to look for a word under editor cursor
            if (selection.length() == 0)
                selection = fetchWordAtCursor();
            if (selection.length() == 0) {

                InputDialog inputDialog = new InputDialog(shell, PopupMessages
                        .getString(""), PopupMessages
                        .getString(""), "", null);

                int returnCode =;

                if (returnCode == Window.OK) {
                    selection = inputDialog.getValue();
                } else {


        protected String fetchWordAtCursor() {
            PerlEditor editor = getEditor();
            IDocument doc = editor.getPerlSourceViewer().getDocument();
            TextSelection sel = (TextSelection) editor.getSelectionProvider().getSelection();
            ITypedRegion typedRegion = PartitionTypes.getPerlPartitioner(doc).getPartition(sel.getOffset());
            String word = null;
            try {
                word = doc.get(typedRegion.getOffset(), typedRegion.getLength());
            } catch (BadLocationException e) {
            return word;

        protected void executePerlDocForTerm(String term) {
            PerlDocView view = null;
            ITextEditor editor = getEditor();
            IWorkbenchPage activePage = PerlEditorPlugin.getWorkbenchWindow()

            try {
                view = (PerlDocView) activePage
      , editor);
            } catch (PartInitException e) {
                        StatusFactory.createError(PerlEditorPlugin.getPluginId(), e
                                .getMessage(), e));
            } catch (CoreException e) {
                        StatusFactory.createError(PerlEditorPlugin.getPluginId(), e
                                .getMessage(), e));

        protected String getPerlEditorActionId() {
            return PerlEditorActionIds.PERL_DOC;

    • Karl Forner

      Karl Forner - 2009-06-15

      So nobody's interested ?


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks