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.
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Beanshell Snippet
by Robert Schwenn on Thu, 18/02/2010 - 19:08
If You'd have this:
- line: "word 15 anything"
- search string: "(\w+ *)([0-9]+)"

there were two submatches found:
submatch 1 = "word "
submatch 2 = "15"

In the replace beanshell snippet the submatches are reffered to as "_x". So, with

this beanshell snippet: "_1 + (Long.valueOf(_2)+5000)"
You get this result: "word 5015 anything"

Robert
 
Beanshell Snippet
by pbolger on Fri, 19/02/2010 - 06:19
Thanks for that Robert.

If it's not too much trouble: do you mind telling me the syntax for literal text - I need to wrap the submatch results in the new tag - which is nothing like the old one.

Something like (open tag)link title="title" href="eznode://72#+(Long.valueOf(_1)+23)+(close tag)+(Long.valueOf(_1)+23)+(open tag) /link(close tag)

(
 
?
by Robert Schwenn on Fri, 19/02/2010 - 22:06
I'm not really sure about Your question. In Java "this is Literal text". Smiling
 
Beanshell Snippet
by pbolger on Sat, 20/02/2010 - 04:45
Except that my 'literal text' includes characters such as quote marks which close the literal text string. Do I need to escape special characters, or can I enclose the whole lot in a CDATA type container? Sorry to be a pain, but all the resources I've found on this so far assume a lot of basic knowledge of Java that I just don't have.
 
Java Tutorial
by Robert Schwenn on Sat, 20/02/2010 - 11:59
I'm afraid You won't be able to script in BeanShell without basic Java knowlege because it's nearly the same.

For Strings usage look there: http://java.sun.com/docs/books/tutorial/java/data/characters.html.

Robert
 
Beanshell Snippet
by pbolger on Mon, 22/02/2010 - 00:55
Ok, thanks for your help.
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