jEdit Community - Resources for users of the jEdit Text Editor
copy file names to file
Submitted by poleta33 on Thursday, 31 March, 2011 - 10:20
Hi everybody

I'm trying without success to write a macro that does a simple thing :

copy the file names of the files selected in the browser directory (this could one or more files) into a named file (C:\temp\test.lst)

thanks in advance !
Combining/sequencing macros
Submitted by highab on Thursday, 3 February, 2011 - 10:49
I have three macros to run one after the other (or combine into one if I can)....

macro 1: populate hypersearch window with results of search for text between specific tags (and the tags)
macro 2: copy the text from the hypersearch window to a new buffer
macro 3: delete the tags and the superfluous bits

if I run them manually they do what I want. If I try to combine them or call them from a fourth macro that just calls them, they don't work right... I think they try to run at the same time rather than waiting for the previous one to finish ("node has no children". How do I get around this please?
Search and Replace EVERY 2nd occurrence i.e. alternate occurrences
Submitted by highab on Thursday, 3 February, 2011 - 10:45
Hi, I'd like to be able to search and replace paragraph marks (\n) with tab marks (\t) for every other line down to the end of a document, effectively merging two lines into one with a tab in between.

thus turning

term1
term2
something else 1
something else 2

into

term1[tab]term2
something else 1[tab]something else 2

this is the code I have so far

SearchAndReplace.setSearchString("\\n");
SearchAndReplace.setReplaceString("\\t");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(true);
SearchAndReplace.setRegexp(true);
SearchAndReplace.replace(view);
SearchAndReplace.setSearchString("\\n");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(true);
SearchAndReplace.setRegexp(true);
SearchAndReplace.find(view);

but if I put it into a loop for textarea number of lines, it replaces ALL occurrences of \n and not every other one.... I'm stumped.

Anyone have any ideas please?
Deleting tags
Submitted by rsmachado90 on Monday, 17 January, 2011 - 17:45
Please, I would like some help in the following: I want delet all: in the file. The id=* is different for each occurence. I'm trying the: "(TimeSpan)(.*\n)*.*(/TimeSpan)" but it's not working. How to fix it? Thanks in advance, Ricardo
Run shell command; return to text area
Submitted by grantciv on Monday, 29 November, 2010 - 00:28
I'm having trouble writing a macro that runs a shell command and returns to the text area. The ultimate goal is to have a macro that saves all the buffers (without confirmation), runs the current buffer in an appropriate interpreter (python, e.g.), and returns to the text area. Really, if focus could simply remain in the text area, that would be great.

The trouble I'm having is that the view.prevTextArea() call is either being executed too early or it's simply not working the way I understood. The focus ends up in the System shell area. My code is below. I think the only important lines are the three last ones, but I'm including it all, just in case.

// This is a recorded macro. First, check over the
// commands to make sure this is what you intended. Then,
// save this buffer, and the macro should appear in the
// Macros menu.
filetypeToCompilers = new java.util.HashMap();
filetypeToCompilers.put(".py", "python -tt");
filetypeToCompilers.put(".java", "javac");

fileExtensionPattern = java.util.regex.Pattern.compile("(\\.[^.]*)$");
matcher = fileExtensionPattern.matcher(buffer.getName());
if (matcher.find())
{
	extension = matcher.group(1);
}
else
{
	Macros.error(view, "Unable to determine file type (missing extension?).");
	return;
}

compiler = filetypeToCompilers.get(extension);
if (compiler == null)
{
	Macros.message(view, "No compiler/interpreter defined for extension '" + 
	extension + "'");
	return;
}

runCommandInConsole(view,"System",compiler + ' ' + buffer.getPath());
waitForConsole(view);
view.prevTextArea();

Any thoughts?
Using the match count as replacement text?
Submitted by heyvern on Thursday, 21 October, 2010 - 20:36
I have searched... uh... literally for at least a year on and off for a solution to this.

What I need to do is to "count" matches and use the "count" number as part of the replacement. I am attempting to change the formatting of a 3d file to another 3D application. Some elements that are not numbered in the original format need to be numbered in the target format. The only way I see to do this is with a macro that can track the match count.

I am very familiar and proficient with regex in jEdit but not so hot with writing macros or java programming. Just looking for some kind of "loop" structure in a macro that counts the matches and increments a variable to be inserted on each match/replace.
Problem finding what I want :)
Submitted by Ziabuch on Thursday, 23 September, 2010 - 15:07
Hello Smiling

I would like to search for the following expression in the text file:

$123 1

Of course the command for this is SearchAndReplace.setSearchString("$123 1");

And it works.

The problem is - that the "123" part of this string is random. So what I really need to find is the first "$", ignore the next 3 digits, find 1 space and finally find "1".

How to create a search command to ignore that "123", or "243" or whatever it may be?

For example if I want to list the file 123AA.txt, I simply put the command "dir ???AA.txt". Is that possible when using BeanShell?

Thanks for advice Smiling
Z.
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
User login
Browse archives
« March 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
31
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   82339
Context Free Art (*.cfdg)   0.31   46046
JBuilder scheme   .001   18487
BBEdit scheme   1.0   18108
ColdFusion scheme   1.0   18016
R Edit Mode - extensive version   0.1   17465
Advanced HTML edit mode   1.0   16198
Matlab Edit Mode   1.0   16060
jEdit XP icons   1.0   15221
XP icons for jEdit   1.1   14285