jEdit Community - Resources for users of the jEdit Text Editor
Problem with a Ansi To Oem macro
Submitted by Anonymous on Saturday, 7 May, 2005 - 18:53
I am trying to make a macro of conversion ANSI for OEM, and OEM you the ANSI.
The macro works in ANSI to OEM, but does not work ANSI to OEM.
Somebody could help me. the macro is basically this.

Sorry my english.


boolean bAnsiToOem = true;

String[] Ansi = {"â","Â","à","À","�","ã","Ã","á","ê","Ê","è","é","É",
"í","�","õ","Õ","ô","Ô","ó","Ó","ü","Ü","ú","Ú","ç","Ç"};

String[] Oem = {"ƒ","¶","…","·","µ","Æ","Ç"," ","ˆ","Ò","Š","‚","?",
"¡","Ö","ä","å","“","â","¢","à","?","š","£","é","‡","€"};


if(Ansi.length != Oem.length) {
Macros.error(view, "Erro na codificação Ansi ou Oem");
return;
}
for( i=0; i < Ansi.length; i++ ) {
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(false);
SearchAndReplace.setRegexp(false);
SearchAndReplace.setSearchFileSet(new CurrentBufferSet());
SearchAndReplace.replaceAll(view);
if(bAnsiToOem){
SearchAndReplace.setSearchString( Ansi[i] );
SearchAndReplace.setReplaceString( Oem[i] );
}else{
SearchAndReplace.setSearchString( Oem[i] );
SearchAndReplace.setReplaceString( Ansi[i] );
}
}
Macros.confirm example doesnt run
Submitted by Anonymous on Thursday, 3 March, 2005 - 23:14
Hi folks,
Please forgive my newbiness... I'm sure there's a pretty simple solution to this.
I've simply cut and paste the following statement from http://jedit.org/users-guide/helpful-methods.html to display a confirmation box:

int result = Macros.confirm("Do you really want to learn"
+ " about BeanShell?",JOptionPane.YES_NO_OPTION);

I get the following error:

Typed variable declaration : Error in method invocation: Static method confirm( java.lang.String, int ) not found in class'org.gjt.sp.jedit.Macros' : at Line: 1 :

So, if I understand this correctly, the macro doesnt know what an int is? I take it then I have to include a class somehow...

Any suggestions?

Cheers all,
Tim
A simple filter macro?
Submitted by Anonymous on Tuesday, 8 February, 2005 - 17:08
Hi all,

I am after a simple macro which would pass the selected text to an external process through stdin and replace the selected text by the stdout output of the external process. Any idea how to do that?

Thanks a lot.

Victor.
Beanshell: How to load/define a class?
Submitted by malyvelky on Saturday, 5 February, 2005 - 14:51
Hi, I'm using beanshell in my jedit development to test my classes. If I compile the class how can I load it into beanshell so that I could instantiate (without an URLClassLoader and that stuff)? The original beanshell let you load a class but the necessary package bsh.classpath is not in jEdit. Thanks!
unescape a unicode escape sequence
Submitted by Anonymous on Friday, 4 February, 2005 - 16:27
Hi, I'm trying to convert unicode escape sequences to characters. Can someone recommend a good strategy for writing a macro ( or a BeanShell snippet for use in Search Replace dialog? )?

Basically I want to search for this pattern:

(\\u00[[:alnum:]][[:alnum:]]) which matches things like \u00E9

and I want to replace it with:

new Character( $1 ); where $1 is the match from the pattern search.

Is there a way to do this using SearchReplace? Or do I need to iterate through the lines of the current buffer and do replacements on each line?

Thanks for any tips. jEdit Rules my world!!

-Travis McCauley
Toronto
search on a php var
Submitted by Anonymous on Wednesday, 2 February, 2005 - 08:57
hello all,

i ve got problem to write the topic ( because of the echo(''); ) so here is a link where i explain it:

http://lycoch.free.fr/macro.htm


thanks
Using EVAL to make Commando definitions remember its variables/settings ?
Submitted by Sasq on Tuesday, 25 January, 2005 - 13:50
I'm trying to make a Commando files remember it's settings instead of setting the same default value each time.
Instead of this:
<ENTRY LABEL="Custom rule name" VARNAME="ruleName" DEFAULT="all"/>
I want something like this:
<ENTRY LABEL="Custom rule name" VARNAME="ruleName" EVAL="if(ruleName != null) ruleName else "all" "/>
(except the last one obviously doesnt work). Any suggestions?
Run macro on Event
Submitted by raccuia on Monday, 27 December, 2004 - 10:19
Hello,
I'd like to know if I can run a macro when I save a buffer, catching the click on Save button.
Sorry if anyone have already ask for this question, but I don't found anything about it. Can anyone tell me if I can catch this event ed run my macro or where I can found any information?

Thanks in advance.
Mino
Upper/Lower/Invert/Capitalize Case Macros WHITHOUT unselecting text
Submitted by pdfneuro on Wednesday, 15 December, 2004 - 17:28
Hi, Here are 4 separated macro that allows to change word case of selected text WHITHOUT unselecting text:
  • - Upper Case
  • - Lower Case
  • - Invert Case
  • - Capitalize Case
Check it out! and enjoy Smiling
Macro to sort lines like in Ultraedit?
Submitted by pdfneuro on Wednesday, 15 December, 2004 - 13:57
Hi, I just upload a jedit macro which is able to sort lines in ascending/descending order. Available options are
  • Remove duplicated lines
  • Ignore case sorting
Check it at http://community.jedit.org/?q=filestore/download/1943 and tell me if you find it usefull. Enjoy Smiling
Execute program from macro
Submitted by Anonymous on Monday, 13 December, 2004 - 14:29
Strangely enough I haven't been able to find how to do this simple task in the documentation or the FAQ:

How to I execute a program from a Macro?

(For running a compiler/make or an emulator/interpreter for the code or just somethin like a calculator).
Sort_Lines.bsh
Submitted by pdfneuro on Monday, 13 December, 2004 - 09:21
Sort_Lines.bsh Hi, I just upload a jedit macro which is able to sort lines in ascending/descending order. Available options are
  • Remove duplicated lines
  • Ignore case sorting
Check it at http://community.jedit.org/?q=filestore/download/1943 and tell me if you find it usefull. Enjoy Smiling
File system browser current selected item/file?
Submitted by fwelland on Saturday, 20 November, 2004 - 02:29
jedit macro newbie; jedit user for a bit; java journeyman.

In a macro, is possible to get the currently selected item in the filesystem browser?

so in my random hacks I have gotten this..

doc = view.getDockableWindowManager();
names = doc.getRegisteredDockableWindows();

with the idea that if I had a handle of the file system browser (currently docked) then I could interrogate file system browser for the currently selected file(s) - it seems there are some getSelected methods in the VFSBrowser....on the right track?
Loading and then editing a file
Submitted by AlvinD on Tuesday, 16 November, 2004 - 03:43
I have a macro which will parse and modify a list of files. It works as long as the files are preloaded. However, when I use the statement "FileBuffer = jEdit.openFile(view,FilePath+File);" The file is loaded, but it is not editable from within the macro! I can use the "iseditable" method to verify that the textarea is not editable after I open the file. I have spent much time and had no luck in finding out how to make the textarea editable after using an "openFile" statement.

I'm sure the answer is simple, but I have not found it.

Any help would be appreciated.
HTML macro
Submitted by Anonymous on Sunday, 7 November, 2004 - 09:13
Hello,

I'm trying to write a macro, that when I select text it adds the tag to that selected text. I have no problem with making that macro. But I do have a problem when I want to make a (un)orded list. I don't know how I have to search for the line ends (/n) in selected text and add text to for every list item.

Can anybody give a hint how I can do that? BTW I don't no much about beanshell and java

Thnx,

Sjmielh
How to use mysql in macro?
Submitted by AndreJRenard on Saturday, 6 November, 2004 - 04:39
I would like to address a mysql database in a macro:
I put the connector file (mysql-connector-java-3.0.15-ga-bin.jar) in the .jedit/jars directory and used the following statements:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
...
Class.forName("com.mysql.jdbc.Driver");
...
con = DriverManager.getConnection("jdbc:mysql://" + url + "/" + db, login, password);

But I got the error message:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at bsh.Reflect.invokeOnMethod(Reflect.java:149)
at bsh.Reflect.invokeStaticMethod(Reflect.java:100)
at bsh.Name.invokeMethod(Name.java:872)
at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:72)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
at bsh.BSHBlock.eval(BSHBlock.java:80)
at bsh.BshMethod.invokeImpl(BshMethod.java:349)
at bsh.BshMethod.invoke(BshMethod.java:246)
at bsh.BshMethod.invoke(BshMethod.java:179)
at bsh.Name.invokeLocalMethod(Name.java:915)
at bsh.Name.invokeMethod(Name.java:805)
at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:72)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
at bsh.Interpreter.eval(Interpreter.java:641)
at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:355)
at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:284)
at org.gjt.sp.jedit.BeanShell.runScript(BeanShell.java:210)
at org.gjt.sp.jedit.Macros$BeanShellHandler.runMacro(Macros.java:990)
at org.gjt.sp.jedit.Macros$Macro.invoke(Macros.java:417)
at org.gjt.sp.jedit.gui.InputHandler.invokeAction(InputHandler.java:229)
at org.gjt.sp.jedit.jEdit$3.invokeAction(jEdit.java:2910)
at org.gjt.sp.jedit.EditAction$Wrapper.actionPerformed(EditAction.java:216)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

What should I do?
Capitalizing First Letters
Submitted by ELApro on Wednesday, 27 October, 2004 - 17:05
How can one write a macro to capitalize the first letter of each word? My current approach would be...

search for words with the regular expression...
([a-zA-Z0-9])([a-zA-Z0-9])+

but can a variable eg, firstLetter, be assigned to $1 so that I can set...

firstLetter.toUpperCase();
for long lines macro generate Error - Array index out of range: 3
Submitted by Anonymous on Monday, 18 October, 2004 - 17:10
Why this macro generate Error?


__________________________________________________________
I write this macro:
// Delete 3 chars at start of line for all except first line
// delete lines longer then 930 characters

textArea.goToBufferStart(false);
textArea.goToNextLine(false);

int textAreagetLineCount=textArea.getLineCount();
java.lang.String pos ="";

for(int j = 0; j < textAreagetLineCount; ++j)
{
textArea.goToNextCharacter(false);
textArea.goToNextCharacter(false);
textArea.goToNextCharacter(false);
textArea.deleteToStartOfLine();

textArea.goToStartOfLine(false);

if(textArea.getLineLength(j) >= 930)
{
textArea.deleteLine();

}
textArea.goToNextLine(false);
textArea.goToStartOfLine(false);
}
buffer.save(view,null,true);
jEdit.closeBuffer(view,buffer);









__________________________________________________________
and example of file:
----Begin of file---
title
g line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long lineg line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long lineg line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line
g line long line long line long line
---End of file---







__________________________________________________________
produce this error:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3

at org.gjt.sp.jedit.Buffer.getLineEndOffset(Buffer.java:935)

at org.gjt.sp.jedit.Buffer.getLineLength(Buffer.java:958)

at org.gjt.sp.jedit.textarea.JEditTextArea.getLineLength(JEditTextArea.java:1280)

at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at bsh.Reflect.invokeOnMethod(Reflect.java:149)

at bsh.Reflect.invokeObjectMethod(Reflect.java:81)

at bsh.Name.invokeMethod(Name.java:856)

at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:72)

at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)

at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)

at bsh.BSHBinaryExpression.eval(BSHBinaryExpression.java:52)

at bsh.BSHIfStatement.evaluateCondition(BSHIfStatement.java:63)

at bsh.BSHIfStatement.eval(BSHIfStatement.java:46)

at bsh.BSHBlock.evalBlock(BSHBlock.java:130)

at bsh.BSHBlock.eval(BSHBlock.java:80)

at bsh.BSHBlock.eval(BSHBlock.java:46)

at bsh.BSHForStatement.eval(BSHForStatement.java:111)

at bsh.Interpreter.eval(Interpreter.java:641)

at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:355)

at org.gjt.sp.jedit.BeanShell._runScript(BeanShell.java:284)

at org.gjt.sp.jedit.BeanShell.runScript(BeanShell.java:210)

at org.gjt.sp.jedit.Macros$BeanShellHandler.runMacro(Macros.java:990)

at org.gjt.sp.jedit.Macros$Macro.invoke(Macros.java:417)

at org.gjt.sp.jedit.gui.InputHandler.invokeAction(InputHandler.java:229)

at org.gjt.sp.jedit.jEdit$3.invokeAction(jEdit.java:2910)

at org.gjt.sp.jedit.EditAction$Wrapper.actionPerformed(EditAction.java:216)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.AbstractButton.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI$MenuDragMouseHandler.menuDragMouseReleased(Unknown Source)

at javax.swing.JMenuItem.fireMenuDragMouseReleased(Unknown Source)

at javax.swing.JMenuItem.processMenuDragMouseEvent(Unknown Source)

at javax.swing.JMenuItem.processMouseEvent(Unknown Source)

at javax.swing.MenuSelectionManager.processMouseEvent(Unknown Source)

at javax.swing.plaf.basic.BasicMenuUI$MouseInputHandler.mouseReleased(Unknown Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)
[FAQ Candidate]: Can I modify the classpath of a macro?
Submitted by Anonymous on Tuesday, 12 October, 2004 - 10:53
Hi all,

Can I modify the classpath of a macro?
It seems that my question have to be inserted in jEdit FAQ.

------------- References from previous discussions Smiling

[1] Using external java libraries in macros 1 05/01/2004 - 6:38am
by AndreJRenard 05/03/2004 - 8:30am
by Brad Mace

[2] How do I modify the classpath of a macro? 0 04/09/2004 - 4:09am
by Anonymous

-------------

The only solution suggested in previous discussions by Brad
was to put my jars into jEdit folder.
That's good, but not too handy. BeanShell's addClassPath() command was
much better.

Currently I have my classes compiled in Eclipse workbench and can play
with them from BeanShell script as much as I like. I run my BeanShell scripts
from command-line currently and I hoped that jEdit's BeanShell Console can be
a better tool.

Changing class in Eclipse is enough for script. But if I had to create jar,
put it into jEdit folder and restart jEdit to catch the changes, it makes it
useless.

My suggestion is to reflect this behaviour in jEdit FAQ.

Best regards,
Egor Abramovich
egor_abramovich@mail.ru
how to swap a file's extension in Console
Submitted by tclark on Saturday, 25 September, 2004 - 02:30
I'm trying to set up a macro in Console in which, for the current buffer, call it myfile.prg, I am able to have a a particular application run myfile.prg and store the results in myfile.out. What I can't figure out is how, for the output file, to drop the extension .prg and add the extension .out. Using ${n} I can easily store the results in myfile.prg.out. But I don't know how to get rid of the .prg in the file name. Any suggestions would be much appreciated.
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   82348
Context Free Art (*.cfdg)   0.31   46055
JBuilder scheme   .001   18495
BBEdit scheme   1.0   18116
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