jEdit Community - Resources for users of the jEdit Text Editor
Is there a way to close the Incremental Search Bar in a macro ?
Submitted by Lee Elms on Monday, 16 August, 2010 - 10:58
I would like to be able to both detect whether the Incremental Search Bar is displayed, and to close it if it is displayed in a macro (Beanshell). I can't find anything in the API ... I hope I'm missing something obvious.

(I know that there is a command to display the Incremental Search Bar ('Incremental Search Bar'). Also that the macro record facility doesn't record the operation of displaying or closing the bar.)

Can anyone help ?
Detect Acrobat Reader Install Dir
Submitted by jrchilds on Wednesday, 11 August, 2010 - 17:34
I made a macro that opens our programming language reference, which is a PDF, and locates the definition for the selected command.

I also have a batch file that installs jEdit and copies the configuration changes needed for editing in our own language. This install is used by anyone who wants to develop in our language.

Here's the problem... In Beanshell, I am using the exec() command to launch the PDF, which requires the full path to the acrobat reader. This is of course different based on the operating system and installed version of the reader.

Here's my question... Is there a way that I can determine the install directory of the acrobat reader? Or is there a simpler solution I haven't yet considered?

Thanks
James
jython - open docs in webBrowser?
Submitted by pixeldroid on Monday, 26 July, 2010 - 12:58
I'm trying to figure out how to open html docs in a web browser using jython, but I'm not able to get the webbrowser to load.
I've tried the following:

import webbrowser
Error:
File "C:\Documents and Settings\Administrator\.jedit\macros
\MayaHelp.py", line 3, in ?
ImportError: no module named webbrowser
========================================
from org.gjt.sp.jedit import webBrowser
Which is found using autocompletion but nonetheless throws this error:
ImportError: cannot import name webBrowser
========================================
I also tried:
from org.gjt.sp.jedit import browser
which doesn't throw an import error, but it doesn't have 'open',
'openURL', or 'open_new_tab' attributes, so I assume that isn't a web browser.

Anyone know what I'm doing wrong?
Thanks.
jython - open docs in infoViewer?
Submitted by pixeldroid on Monday, 26 July, 2010 - 12:03
I'm trying to figure out how to display docs in the infoViewer (in Windows), but I get an error.
Can someone help?

file = 'C:\Projects\Websites\Pfarm\MayaStuff\MayaPlugins_jEdit.html'
InfoViewerPlugin.openURL(view, file)

ERROR:
Traceback (innermost last):
File "C:\Documents and Settings\Administrator\.jedit\macros\displayHTMLTest.py", line 7, in ?
NameError: InfoViewerPlugin

Thanks.
Mode appropriate comments in templates
Submitted by sillydragon on Wednesday, 21 July, 2010 - 13:23
While messing around with the Template plugin I decided it was pointless to have different templates to take into account differences in comment characters for
different languages, so I poked around to see if I could find a way around this and came up with this.

--
## template = Get mode comment char
#*

Get the line comment character for the current buffer's mode. If the mode
doesn't define a line comment character, complain and ask what prefix
string to use instead. $comment will contain the results either way.

*#
#beanshell (false)
context.put("caret", view.getTextArea().getCaretPosition());
context.put("comment", buffer.getContextSensitiveProperty(caret,"lineComment"));
#end
#if ( $comment )
#else
#prompt ( "Mode doesn't have a line comment. String prefix to use?" $comment )
#end
--

Put that in a file called "getcommentchar.vm" in your templates directory, then in other templates you can do:

--
#parse ( "getcommentchar.vm" )
${comment} Lorem ipsum
${comment} dolor sit amet, consectetur adipiscing
--

The inserted text will be preceded by whatever passes for line comments in the buffer's language, or the prefix text you gave.

Enjoy. Smiling
Macros for ProjectViewer
Submitted by Jabberwock on Monday, 7 June, 2010 - 09:12
Hi,

I write some macros for ProjectViewer.

You have a macro to do a search in the projects tree, and some for load/unload project, and one to add a project.

If you want to use the unload macro, call always the macro Export.bsh
If you want to load a project, call Import_Tree_Project.bsh, if you want to load a tree project, or Import_a_project.bsh if you want to load only one project.

The Add_project.bsh macro, add a project, and the focus stay where your are, and don't go inside the new project.

The Search macros is simple Smiling
Sharing: Context sensitive help for PHP using Firefox
Submitted by ezuk on Monday, 19 April, 2010 - 05:20
Her's a macro I adapted for opening php.net's documentation in Firefox for the currently selected keyword:
// Context-sensitive help for PHP.

String editMode = buffer.getMode().toString();
ffpath = new StringBuffer();
ffpath.append("c:/Program Files (x86)/Mozilla Firefox 3.6 Beta 5/firefox.exe ");
keyword = textArea.getSelectedText();
if ((keyword == null) || (keyword.length() == 0)) {
    textArea.selectWord();
    keyword = textArea.getSelectedText();
}

if ((keyword != null) && (keyword.length() > 0)) {
    if (editMode.equals("php")) {
        keyword = keyword.replace('_', '-');
        command = new StringBuffer();
        command.append(ffpath);
        command.append("http://php.net/manual/en/function.");
        command.append(keyword);
        command.append(".php");

        Runtime.getRuntime().exec(command.toString());

    }
}
Sharing: A macro for making text bold () with Ctrl-B
Submitted by ezuk on Sunday, 18 April, 2010 - 20:19
Hi all, This may be useful for newbies. A macro based on the "Insert Tag" macro which comes with jEdit, but which surrounds the selected text with b and /b tags. I bound it to Ctrl-B and it's a very useful way to quickly make a word bold.
void insertTag(tag)
{
	caret = textArea.getCaretPosition();
	if( tag == null || tag.length() == 0) return;
	text = textArea.getSelectedText();
	if(text == null) text = "";
	sb = new StringBuffer();
	sb.append("<").append(tag).append(">");
	sb.append(text);
	sb.append("");
	textArea.setSelectedText(sb.toString());
	//if no selected text, put the caret between the tags
	if(text.length() == 0)
		textArea.setCaretPosition(caret + tag.length() + 2);
}

if(buffer.isReadOnly())
	Macros.error(view, "Buffer is read-only.");
else
	insertTag("b");

Enjoy Smiling
Block selection
Submitted by optigon on Thursday, 15 April, 2010 - 16:38
Hi all,

There are two ways to select a block of text in jedit as far as I know.
1) press [Alt] + [\] to enter block selection mode. Then use [Shift] and the Arrow keys.
2) press [Ctrl] + the Left mouse button.

While these are both useful, I am trying to figure out if there is a way to make a third option
3) [Alt] + Arrow keys

The advantage is that it wouldn't leave you in Block Selection mode like 1, and you wouldn't have
to move your hand to the mouse, like 2.

I tried making a macro of 2, but the macro recording facility won't register mouse events.
Is there a way to do this?

Richard
HTML Cleanup (delete tags and contents)
Submitted by modestmoose on Wednesday, 7 April, 2010 - 20:07
I am working on a project at my law school. I receive news articles in .docx format and then convert them to .html. This requires a lot of cleanup of the extra tags Word puts into the text. I have a very simple macro that does a find and replace to delete common unneccessary tags. What I want to do is the entire header tag and its contents (and other tags such as table tags).

I have no programming background and can't figure it out. How would I have a macro search for (head) and (/head) and then delete the tags and everything in between?

Thank you ahead of time for any insights you can give me,

Brian
Writing text in two buffers
Submitted by DirkK on Sunday, 28 March, 2010 - 13:31
Hi to all,

I'd like to write text in two new buffers, so I wrote this short beanshell script:

buffer1 = jEdit.newFile(view);
editPane = view.goToBuffer(buffer1);
textArea = editPane.getTextArea();

textArea.setSelectedText("Buffer 1\n");

buffer1.save(view, "C:/Work/test1", true);

buffer2 = jEdit.newFile(view);
editPane = view.goToBuffer(buffer2);
textArea = editPane.getTextArea();

textArea.setSelectedText("Buffer 2\n");

buffer2.save(view, "C:/Work/test2", true);

as soon as the script tries to execute the textArea.setSelectedText, I get an exception "Text component read only". Has anyone an idea why I get this exception?
Moving the buffer1.save downward to the buffer2.save the script works fine.

The next challenge: if I try to write in the buffers alternate (first in buffer1, next buffer2 and then in buffer1 again) all the text is written in just one buffer. how do I select where my text is written?

thanks in advance for your responses, Dirk
How to fetch current Keyword/Token?
Submitted by uhuebner on Tuesday, 2 March, 2010 - 10:54
I'm trying to change my existing macro of uppercasing keywords to use exactly the case that is given by the Keyword-XML file, e.g. gettext -> getText instead of GETTEXT.
I get the next token bei using Token.next. But I only get the representation in my TextArea. How can I retrieve the corresponding original Keyword as given by the XML file?

Thanks
uhuebner
custom macro works when recorded, but not when run
Submitted by dushanm on Sunday, 28 February, 2010 - 19:55
This was posted to jEdit-users but I never saw it show up, so is being re-
submitted it here.

I'm using jEdit 4.3.1 under Mac OS X.6.2 (Snow Leopard).

I recorded a macro to reformat a paragraph differently from how the re-
gular Format macro does it. This 'Reformat' macro is supposed to reformat
only from the line containing the cursor, put two spaces (instead of one)
after the sentence-end punctuation, and finally place itself at the be-
ginning of the next paragraph.

When recorded, it does exactly this, but when run as a macro it doesn't.

Here's what happens. Suppose I have 3 paragraphs, 1, 2, and 3, and the
cursor is somewhere in para 1. Then Reformat

- separates sentences in the region between the cursor and the end of
para 1 with two spaces,

- joins para 1 and para 2 by deleting the empty line separating them
(but without reformatting para 2), and

- if the cursor was on the 1st line of para 1, it moves it to the begin-
ning of that line; if the cursor is below the 1st line of para 1, it
places it at the beginning of para 3.

Here is the macro:

textArea.goToStartOfLine(false);
textArea.insertEnterAndIndent();
textArea.goToNextParagraph(true);
textArea.goToPrevLine(true);
SearchAndReplace.setSearchString(". ");
SearchAndReplace.setReplaceString(".. ");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.replace(view);
SearchAndReplace.setSearchString("? ");
SearchAndReplace.setReplaceString("?? ");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.replace(view);
textArea.formatParagraph();
textArea.goToPrevParagraph(false);
textArea.goToNextParagraph(false);
textArea.goToNextParagraph(true);
textArea.goToPrevLine(true);
SearchAndReplace.setSearchString("?? ");
SearchAndReplace.setReplaceString("? ");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.replace(view);
SearchAndReplace.setSearchString(".. ");
SearchAndReplace.setReplaceString(". ");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.replace(view);
textArea.goToPrevParagraph(false);
textArea.goToNextParagraph(false);
textArea.backspace();
textArea.goToNextParagraph(false);

Any suggestions as to why the altered behavior? Thanks.

- Dushan Mitrovich
Using beanshell in a macro
Submitted by pbolger on Wednesday, 17 February, 2010 - 21:44
I'm trying to write a macro to renumber footnotes links in a document - it's pretty simple: I just need to capture the previous number in a backreference, add an offset to it, and rewrite the link with the result. I've got the regex search worked out, but I'm completely in the dark on the syntax for the replacement. This looks like a situation where using a beanshell snippet would be appropriate, but I'm no java programmer. What I need is: [value in backreference plus the offset number] Any help would be appreciated.
How-to: Using YUI to auto-compress/minify JavaScript
Submitted by CNSKnight on Monday, 25 January, 2010 - 17:23
Yahoo's YUICompressor is my favorite JavaScript compression/minifier utility.

I wanted to hit a button w/in JEdit and have my source javascripts run through the compressor.

I made a copy* of the Run_Script.bsh macro script and modified as follows

else if(mode.equals("javascript")) {
newpath = buffer.getPath();
if (newpath.contains(".source")) {
newpath = newpath.replace(".source", "");
myPathToYUICompressor = "/var/www/yui/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar";
execScript("YUI Compressor", "java -jar " + myPathToYUICompressor + " " + path + " -o " + newpath);
} else {
execScript("Windows Script Host", "wscript " + path);
}
}

You will of course need to have a copy of the YUI compressor and my need to edit the myPathToYUICompressor var above.
Additionally, as written, the code assumes you name your javascript sources with '.source' in the filename. Modify to '-uncompressed' or somesuch as to your practice.

*For a windows install, locate 'Run_Script.bsh' in the as-installed JEdit directory.
-Windoz: C:\Program Files\jEdit\macros\Misc\Run_Script.bsh
-LINUX: probably eg /usr/share/jedit/ (try >> whereis jedit)

Copy 'Run_Script.bsh' into your personal ~/.jedit/ directory. I did so and also renamed it to 'Run_Skript.bsh' so that all of my customized jEdit scripts are in my personal directory, hidden from jedit upgrades.

example:
w/in jedit, i am editing /path/to/my/JS/myJS.source.js

hitting the macro with the uncompressed javascript file in the buffer produces /path/to/my/JS/myJS.js as a compressed version.
Trying to use TextToolsComments in macro
Submitted by kemptenkid on Saturday, 23 January, 2010 - 00:01
I have created a macro that calls toogleRangeComments method from the TextToolsComments plugin if I have made a selection of code else i call toggleLineComments. When I execute this I get a "java.lang.IllegalMonitorStateException" exception, is there something i'm doing wrong ?


void smartComments(View view)
{
if (textArea.getSelectionCount() > 0)
{
TextToolsComments.toggleRangeComments(view);
}
else
{
TextToolsComments.toggleLineComments(view);
}
}
smartComments(view);
GC out of memory with macro.
Submitted by jazminstewart on Tuesday, 19 January, 2010 - 19:29
Hi, first message here. I have been using jEdit for a short time. I've found it as a replacement for UltraEdit and coding is not my need.

Running Macros/Scripts is what I need to do from time to time to clean up files coming in different formats.

I've had many memory issues with jEdit. But this is something I can't solve. It seems to be jEdit related but I think some of you may help.

I have a 162MB text file, opening chews about >330MB (the Heap is at 2GB now)

I run this Macro (avoiding some obvious constants and declarations) (SEE BELOW)

It works fine, but the memory ramps to 2GB, stays like that for about 30 minutes until I get a message from BeanShell that GC has run out of heap memory.

As you can see, my code does not "retain" things in memory, so I don't see why it's doing that.

I've set the Autosave time to "0" and Undo to "0".




while (SearchAndReplace.find(view))
{
SearchAndReplace.setSearchString("\\d+\\.\\d+");
SearchAndReplace.find(view); //Find first number in line
strTemp = textArea.getSelectedText(); //Copy to a String
SearchAndReplace.setSearchString("\\s+.*\\s+(?=(\\d|-))");
SearchAndReplace.find(view); //Find some other numbers

textArea.backspace(); //Erase that

//Add spaces until caret gets to the column it should be
while ( (textArea.getCaretPosition()-textArea.getLineStartOffset(textArea.getCaretLine()))
< 19)
{
textArea.setSelectedText(" ");
}

textArea.setSelectedText(strTemp); //Paste the previously copied number

//Add spaces until caret gets to a specified column
while ( (textArea.getCaretPosition()-textArea.getLineStartOffset(textArea.getCaretLine()))
< 32)
{
textArea.setSelectedText(" ");
}

SearchAndReplace.setSearchString("SOME\\s+");
}


Thanks!
corpus for computational linguisitcs
Submitted by hamyfox on Sunday, 27 September, 2009 - 20:49
Hi,

I recently discovered Jedit and started working with Jedit macros.
This site resources have been very helpful in assisting me with writing
a search and replace macro for HTML documents for corpus purposes.
I would like to clean HTML files and save them into txt files.
I am familiar with classes and methods from C++ but not quite
with Beanshell coding. Are there any references for Beanshell codes and methods ?
I would appreciate any help, in form of macro code for the following:
1- macro to delete first x lines of a document
2- macro for keeping only contents of title, paragraph or body of an HTML document

Any help in this matter through code or references would be greatly appreciated. Thanks.
Selecting lines between two points?
Submitted by hungryOrb on Wednesday, 9 September, 2009 - 02:25
Hi all! I'm a noob user, and am having trouble selecting lines between two points. In example: -----------
Text between Div1 Text between Div2
In the macro, I might want to start the cursor at the first div open, then use the search function to find the close so the cursor is at
then press up arrow once, select the line (Div2 line) then add to the selection everything from that line upwards to where my cursor started. So after all, the selection will contain every line from
to "Text between Div2". However, when I try this, I use the CTRL+F search function, and any selection I have, is overwritten when you hit search and the thing you are looking for replaces the selection. Having 'Multiple Selection' option checked doesn't help.. Thanks for considering my plight! O
Create Global Object in macros
Submitted by Jabberwock on Friday, 24 July, 2009 - 06:05
Hello,

How i cab create a global object in Macro ?

In my case, i create a TelnetWrapper object with the connection, how I can create a global object, becaus i dont' want to process the reconnection, i prefer to re-use my previous object ?

For example :
step 1 : i launch my macro, i create the TelnetWrapper object_toto with the connection.
step 2 : i launch again my macro, but i want to re-use my object_toto without re-connection

It's poossible ?

Thw very much
User login
Browse archives
« April 2024  
MoTuWeThFrSaSu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   82349
Context Free Art (*.cfdg)   0.31   46055
BBEdit scheme   1.0   18595
JBuilder scheme   .001   18495
ColdFusion scheme   1.0   18024
R Edit Mode - extensive version   0.1   17473
Advanced HTML edit mode   1.0   16206
Matlab Edit Mode   1.0   16068
jEdit XP icons   1.0   15229
XP icons for jEdit   1.1   14293