it should be possible to do that with some simple python scripting inside pydev.
take a look at: http://pydev.org/manual_articles_scripting.html (you can use https://github.com/aptana/pydev/blob/master/plugins/org.python.pydev.jython/jysrc/pyedit_import_to_string.py as an example).
for the text selection, the pyselection implementation may be found at: https://github.com/aptana/pydev/blob/master/plugins/org.python.pydev.core/src/org/python/pydev/core/docutils/pyselection.java (so, you can see how getselectedtext and work your own version to get the text you want).
here is a little pydev script that i was able to create with the hints given by fabio. if you press ctrl+2,t then the literal string at the cursor position will be surrounded with a gettext call. i'm not sure whether i'm using the java api as expected, but it works for me. if you have ideas for improvement, please comment.
if cmd == 'oncreateactions': from org.eclipse.jface.action import action from org.python.pydev.core import ipythonpartitions from org.python.pydev.core.docutils import parsingutils, pyselection class addgettext(action): """add gettext call around literal string at cursor position.""" gettext = '_' def run(self): sel = pyselection(editor) doc = sel.getdoc() pos = sel.getabsolutecursoroffset() ctype = parsingutils.getcontenttype(doc, pos) if ctype == ipythonpartitions.py_singleline_string1: char, multi = "'", false elif ctype == ipythonpartitions.py_singleline_string2: char, multi = '"', false elif ctype == ipythonpartitions.py_multiline_string1: char, multi = "'", true elif ctype == ipythonpartitions.py_multiline_string2: char, multi = '"', true else: char = none if char: par = parsingutils.create(doc) if multi: start = par.findpreviousmulti(pos, char) end = par.findnextmulti(pos, char) else: start = par.findprevioussingle(pos, char) end = par.findnextsingle(pos, char) doc.replace(end + 1, 0, ')') doc.replace(start, 0, self.gettext + '(') activation_string = 't' wait_for_enter = false editor.addofflineactionlistener( activation_string, addgettext(), 'add gettext call', wait_for_enter)
here is another solution using vrapper:
:map gt ca'_(<esc>pa)<esc>
note that this only works with single-quoted strings, it does not recognize when you use double quotes or multi-line strings.
- Is there a quick way to add gettext() calls to strings in PyDev?
- Is there a quick way to add all undefined methods?
- Is there a quick way to decrease the indentation of multiple lines in Python?
- Is there a way to add the workspace path to the Eclipse IDE title bar?
- Is there a way to add Google Chrome as an external web browser in Flash Builder Standalone for Mac?
- Is there a way to list all calls of equals() of a certain class using Eclipse?
- Is there a way to make Eclipse add static imports without autocomplete?
- Is there a way to suppress unresolved imports in eclipse in a PyDev project?
- In Eclipse PyDev is there a way to exclude arbitrary file-types from the Pydev Package explorer?
- Is there a way to disable calls to Runtime.checkRestricted on the GAE Java development server under Eclipse?
- Is there a quick way to export a WAR file in Eclipse 3.4?
- Is there a way to add a delay to eclipse tooltips?
- Is there a way to set one "//$NON-NLS" annotation for all Strings in one line?
- Is there a way to not wrap line when doing PyDev organize import?
- Netbeans has "Print to HTML" - is there a way to add this feature to Eclipse?
- Is there a way to add a custom class template to Eclipse?
- Java / Eclipse profiling: Is there a way to show the number of method calls to each method?
- In Eclipse Emacs mode, is there any way to remap or add the Alt key to the Esc key?
- Is there a way to add very simple code-highlighting to eclipse by just giving a list of different keyword, block start etc?
- Quick way to add the signature of an inherited method using Eclipse
- Is there a way to input 2 strings into 1 string and have them not effect each others input?
- Is there any way to make pydev (or whatever Python IDE) understand module imported by using __import__ or exec
- When writing Eclipse JDT plugins, is there a way to track appearace of certain strings in code?
- PyDev and Eclipse - Is there any way to show the functions documentation when hovering it?
- Is there a quick way to convert Eclipse "libraries" to Maven POM entries?
- Is there any other way to add an ActionListener to a button using windowbuilder (eclipse) in design mode than to double click on the button?
- Is there a way to quickly find a views.py file for a specific module using pydev in eclipse?
- Eclipse code formatting: is there a way to add "section lines"
- Is there a quick way to move a bunch of static constants to another (non-nested) class?
- Is there a way to add a Horizontal Scroll bar on a layout with a tablelayout?
More Query from same tag
- Eclipse freezes Ubuntu, hard reboot required
- How to calculate specific values - Eclipse
- HTTP 403 WildFly Application Server
- Instance Methods: complex numbers
- SWT CTabFolder doesn't display when running from eclipse
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> Eclipse photon jdk 10 Tomcat 9
- How to convert an Eclipse Android project to use Ant for build?
- Non-working Menu Built in Java
- Attempting to get aspect annotation recognized by eclipse luna while using m2e (maven) build
- Eclipse : How to put break points inside a class (outside the method )
- Set Eclipse not to insert blank lines between methods declaration in interfaces?
- Eclipse Discovery Options in LUNA
- What Eclipse plugin do I need in order to build an Eclipse plugin?
- Start mutliple java applications at once in eclipse
- Is it possible to create multiple jar files of same project
- How to get angular2 to work in eclipse with typescript
- how to open another class by clicking on a button on libgdx? (android development eclipse)
- Eclipse .metadata folder out of workspace
- Read multiple rows indexed by a series of merged cells from Excel using Apache POI
- how to enable nebula widgets in designer's palette of Eclipse Indigo
- How to convert two different strings to date format and finding their differences in JSP/JAVA
- Add JBoss Server Runtime Environment to Eclipse Mars
- Setting up project is eclipse
- Android Eclipse vs Android Studio 2016
- Adding JPA-Connection in Eclipse
- Does Eclipse have to deal with C++ ABI compatibility issues?
- How can I hide this annoying toolbar
- ListView only one list entry play button works
- SeekBar at the top of the layout in Android
- How do I open an existing bada project using badaIDE?