jEdit Community - Resources for users of the jEdit Text Editor
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
autocomplete macro question
Submitted by fenderog on Friday, 24 April, 2009 - 17:33
Hello everyone,

I want to write a macro that does a simple autocomplete. It is a macro that I've had for nedit and I would like to get it working on jedit but I dont have too much experience with java so I wanted to ask for a starting point

Pretty much what I want to have is a macro that once executed, searches the buffer *backwards* starting from the current position. and replaces the current word with the first found result , once executed again, replace it with second results , and go on.

here is an example
string $variableA = "bla";
string $variableB = "blabla";
string $variableC = "blablabla";

string $var -> right when I type this , I'd like to execute this macro , and it would replace $var with $variableC , $variableB $variableA


I'm not asking someone to write this for me, I just wanted to know if there is something out there similar that you might have encountered , if not just some example of a macro that's similar to this would be great

Thanks in advance !!
View the console output during the macro
Submitted by lilive on Friday, 13 February, 2009 - 10:02
Hello,
I wrote a macro to compile a file, using :
runCommandInConsole(view, "System", compilCommand);

It work fine. I want to view the console output, so I add :
view.getDockableWindowManager().showDockableWindow("console");

The problem is that the console panel open at the end of the macro.
Does anybody know how to make it open during the macro execution ? Because I want to see the output during the compilation process.

Thank you.

--- and sorry for my english --- just a french ... ---
Run macro in a specific EditPane split screen
Submitted by kircheis on Friday, 6 February, 2009 - 10:16
Someone asked something like this but got no answer.
http://community.jedit.org/?q=node/view/1688

I'm working with some old Cobol code full of "go to" instructions, so I wrote a macro that would take me to the corresponding place in code so I don't have to look for it manually.

I have jEdit screen split vertically in two, working on the same file. I tried adapting my macro to go to the next pane and search from there instead of the first one and then set the focus back again to the first pane.

I tried using view.nextTextArea(), but only the cursor go to the next pane, the macro still runs on the first pane. Then I tried using EditPane setBuffer, but it also runs on the same side of the split screen. Is there some other class with the methods I need or am I doing something really wrong?
Starting a java jar from a Beanshell and vice versa
Submitted by bigmoun10 on Friday, 23 January, 2009 - 15:29
Hi

First, I'm new to all this java and beanshell stuff. Please be patient with me.

In general
* all beanshell files are stored on "C:\Program Files\jEdit\macros\xyMacros" and
* all jar files are stored on "C:\Program Files\jEdit\jars".

First problem:
==============
I want to extend jEdit with a beanshell macro, which calls xy.class in xy.jar file. The class in the class file is defined as "public class xy extends JDialog" and the main method is defined the following way:

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() ...

The jar file also contains other source files like icons and additional class files.

Now, the question is: how can I call the java code from the beanshell macro and what is needed to make it work (e.g. classpath, imports, ...)?

Second problem:
===============
Once the java code is executed and the dialog pops up I would like to execute a beanshell script, let's say myScript.bsh, when a certain button is pushed. The beanshell script then manipulates the textarea of the actual view in jEdit.
Questions here: How can I call beanshell scripts from the java code? Is there anything I need to do regarding the actual view, e.g. storing it in the java class and then give it to the beanshell script as an argument, or is this working right away?

If somebody could answer and give code examples, this would be great!
Thanks in advance!
RegExp - Replace special characters in a string
Submitted by jrchilds on Thursday, 15 January, 2009 - 20:00
I am writing a macro that will take highlighted text, convert any non alpha numeric characters to underscores, and then open a .chm file to the topic named by the resulting string. I can make everything except the regular expression part of that work. I only yesterday started playing with regular expressions, and I'm not sure how to do this, and google was not much help. Here is what I need.... I have, SomeVariable= "?This!String@1#2&3." I need to make SomeVariable= "_this_string_1_2_3_" Here is the set I want to replace [!@#$%^&*()<>{}[]?~`|\/] Is this an easy thing to achieve? Thanks for the help.
Current project directory
Submitted by takeshin on Saturday, 1 November, 2008 - 12:11
Hi!

How to get current project directory? (stored in ProjectViewer's xml)
I'd like to have action "add new file to this project".

--
takeshin
disable undo temporary
Submitted by takeshin on Wednesday, 29 October, 2008 - 14:04
Hi!

I have a macro which updates comments at the beginning of the buffer.
Then, when I edit the file and press Ctrl+Z, cursor goes to the beginning of file,
where macro operated.

How to disable undo temporary, so commands executed in macro were not registered in history?

--
takeshin
How to clear only invalid entries in Recent Files
Submitted by tvojeho on Wednesday, 22 October, 2008 - 18:26
Hi all,

I was wondering if there was a way for a macro to go through the items in Recent files list and delete invalid entries, leaving the rest. My Java know-how is not very extensive, and after some googling and searching the default macros code, I have put together a few lines of code which luckily do not throw an exception, but unfortunately do not apply the desired changes to Recent Files menu.

I would be grateful for any help.

  Cheers, tvojeho.

  

BufferHistory.Entry[] recentBuffersArray = BufferHistory.getHistory().toArray(new BufferHistory.Entry[0]); // get history

for(i=0;i {

recentPath = recentBuffersArray[i].path;

if( ! new File(recentPath).exists())

{

BufferHistory.Entry removeEntry(recentPath);

}

}

return;

Wait for buffer reload
Submitted by takeshin on Friday, 17 October, 2008 - 11:06
When i run:
buffer.reload(view);
buffer.save(view, null); // or other I/O

I get: I/O Error
Each buffer can execute only one I/O operation at one time.

How to wait until buffer reloads?
I can't modify textArea until it completes to reload.

I suppose I have to use BufferAdapter and bufferLoaded method. But how to do it?

--
regards,
takeshin
Can I parse the errorlist?
Submitted by PaulCollingwood on Thursday, 21 August, 2008 - 10:59
I have an errorlist being generated from Lint, and so I can move to each warning and error within the code.
What I would like to do is write a macro that, for a given buffer and cursor position is first able to acquire the full path name and file line number (this bit I can do) and then parse the errorlist content looking for a match.
I would then like to insert the comment in the preceding line of the form '/*lint */' which would prevent such errors in future - again. the comment insertion I know how to do.

The question is this - is there a way to parse the errors in the errorlist, extracting file-name, line-number, and error-message for each item in the process?
Search and replace - right way
Submitted by takeshin on Sunday, 17 August, 2008 - 21:48
I have recorded macro like this:

SearchAndReplace.setSearchString("\\{[\\s\\t]+"); SearchAndReplace.setReplaceString("\\{ "); SearchAndReplace.setBeanShellReplace(false); SearchAndReplace.setIgnoreCase(true); SearchAndReplace.setRegexp(true); SearchAndReplace.setSearchFileSet(new CurrentBufferSet()); SearchAndReplace.replaceAll(view);

It works fine, but slow and it beeps each time and so on.

How it should be coded using java.util.regex?

--
regards,
takeshin
Macro or shortcut for Reload with Encoding UTF-8
Submitted by JanciB on Sunday, 17 August, 2008 - 17:24
How can I make macro for "Reload with Encoding UTF-8"? Or can it have a shortcut? I use it often and it is annoying to go through the menu every time.
indicate progress, status bar
Submitted by takeshin on Thursday, 31 July, 2008 - 17:36
I wrote a macro which takes a long time to execute.
(while loop operating on texarea text). While the macro works, jEdit is frozen, and user may think it hanged.
How to notify user that everything is ok?
How to set statusbar message?

How to indicate progress of the macro?
It would be nice to have message box saying: macro in progress… [cancel]

How to use observers in macros?

--
regards,
takeshin
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