jEdit Community - Resources for users of the jEdit Text Editor
jEdit 4.2 question: How to tell if a file exists on a VFS using the FTP Plugin?
Submitted by txporter on Thursday, 25 May, 2006 - 03:35
I use the FTP plugin to give me remote access to files. I am trying to write a macro to look in the directory of the file I have open in a buffer and determine if another file exists in the same directory.

On a local file system I would simply create a File instance using a path string I constructed and check to see if it exists, like this:

dirname = dir(buffer.getPath());
FQPN = dirname + "new file name";
java.io.File newFile = new java.io.File(FQPN);
if (newFile.exists()) {
//do stuff
}


If I try this when my buffer is on my remote server, newFile.exists() always returns false, regardless of whether the file actually exists or not. I think this is because dirname is something like "ftp://myuserid@myremotehost:21/path/to/new_file_name" and the normal java.io.File.exists() method does not understand URI's like this.

Any ideas on how to tell if the remote file exists or not?

I tried unconditionally opening the file and checking the length of the buffer, expecting a new file to have zero length and then I could close it immediately, but since jEdit.openFile(view, pathToFile) does not seem to be a blocking operation, trying to get the buffer length did not work:


1. aBuffer = jEdit.openFile(view,FQPN);
2. if (aBuffer.getLength() == 0) {
3. // file is new, so close it, as I only want new buffer if file exists
4. }


Could I put a VFSManager.waitForRequests() call between line 1 & 2 to wait for the FTP I/O to complete before checking the buffer length? Is this a static call? If not how to I get access to the VFSManager instance associated with my FTP connection?

Thanks!!

Tom Porter
Sort Lines (editplus style sort)
Submitted by p8er on Thursday, 11 May, 2006 - 08:03
I wrote a macro to sort lines of selection or whole buffer.
After I finished it I found there is another sort lines macro here. (Oh! why I don't search it before write this one. )
But my macro is more powerful than the one exist, though the dialog of that one is more pretty. Sticking out tongue

------------------------------------
Here is the description of my macro, just like the sort tool in editplus 2.

Sort selected lines or whole buffer (when nothing is selected).
This is just similar to the sort function in Editplus 2.
Features:
  • Order - Either ascending order or descending order.
  • Starting column - Enter a column number from which the sorting operation begins. The text before this column number will be sorted when string after the column is the same. Enter an integer value great than or equals to 1.
  • Case sensitive - The case-sensitive comparison option.
  • Remove duplicates - Remove any duplicated line after the sorting option.
You can download it here -> download.
Or view the download page here -> download page.

Or you like the old one created by Pascal Dal Farra.
more sophisticated 'select between quotes'
Submitted by silverquick on Saturday, 29 April, 2006 - 05:17
I was playing around with Lee Turner's script (which appears to have started here: http://community.jedit.org/?q=node/view/1128), and because I work with PHP I wanted one to recognise both single and double quotes, and there's also the problem with his that if the caret is between quotations, the space between them gets selected. The latter's not that big of a problem, but trying to allow for both types of quotes is tough.

I thought I had it with this: basically track all openings and closings of quotes in the buffer prior to the caret (in PHP a ' inside "..." doesn't count and vice-versa), and if a quote is open at the caret, search after the caret to find its mate, and select between them. But then if a comment contains apostrophes or irregular double-quotes, this won't work! I could get very complicated and detect comments, but this is language-specific and what I've been thinking from the start is that it would be nice to abstract the searching from the quote syntax.

So my real question is: is there a way for a macro to interact with jEdit's syntax highlighter? It's a waste for my macro to do the work of finding quoted sections when jEdit has obviously already done the work. I'm envisioning methods get the token type of the text under the caret, get the boundaries of a given token section, etc. I've tried looking through the API docs, but (1) I'm don't really understand how the highlighting engine works, and (2) it all feels a little over my head. I am pretty green with Java.

Thanks for reading!
Commando and console 4.2.5.1
Submitted by beaubert on Sunday, 9 April, 2006 - 12:10
Hi, I have made a smal commando script to compile (with wmake) and run an application. This script do 2 thinks, first it compiles my app and then run it (in the system shell) in a directory specified by the user. This commando script works well with Jedit 4.2final but I'm unable to make It work with Jedit 4.3pre3 with console 4.2.5.1 and 2sdk1.5-sun: the compilation with wmake works fine but I'm unable to lauch my app ? But the 4 commands in the commando dialog are there but in only do the first two ... Is it a bug with console 4.2.5.1 ? Any ideas ? Here is the commando xml file: buf = new StringBuffer("cd "); buf.append(compildir); buf.toString(); buf = new StringBuffer(); if (target.equals("wmake_all")) { buf.append("wmake"); } else if (target.equals("wmake_debug")) { buf.append(" "); } else if (target.equals("wmake_clean")) { buf.append("wclean"); } buf.toString(); buf = new StringBuffer(); if (exe) { buf.append("cd "+casedir); } buf.toString(); buf = new StringBuffer(); if (exe) { buf.append(application+" .. "); buf.append(MiscUtilities.getFileName(casedir)); } buf.toString();
SearchAndReplace problem
Submitted by turtlecove on Wednesday, 15 March, 2006 - 18:57
I am writing a Macro that enables a simple kind of Wiki link in any text file. Basically if I run my macro, it finds the nearest words in [brackets] and uses that as a file name to open. It works well, but I added the feature to jump to an anchor [filename#anchor] and I cannot figure out how to get it to jump to text in a document. Here is what I have:

newbuffer=jEdit.openFile( view, WikiWord);
if (hasAnchor) {
SearchAndReplace.setSearchString(anchor);
SearchAndReplace.find( view, newbuffer, 0, true, false);
}

It behaves very erratically. It always opens the new file ok. But then it sometimes finds the anchor text, but usually does not. I've tried resetting the cursor to the top of the file to make sure it isn't past the anchor text:

view.getTextArea.setCaretPosition(0);

But that didn't help.
Strangely, if I add this:

Macros.message(view, "finding " + anchor);

before the find, it works! I suspect the popup window causes the interface to 'refresh' in some way bringing the newly opened file to some displayed state, as opposed to some open-but-not-yet-displayed-state... but I'm just guessing here...

Any help?
Automating ProjectViewer (Creating New Projects Programatically)
Submitted by philmaker on Wednesday, 8 March, 2006 - 07:47
I'm interested in writing a macro to generate all of my projects in ProjectViewer. Anyone know if this level of interaction with ProjectViewer is possible. I'm also having trouble generating the complete JavaDoc API for ProjectViewer - anyone know if this is available online?
How determine if a file is locked?
Submitted by a992400 on Saturday, 18 February, 2006 - 22:17
One of my macros saves open buffers, but it pops up an error message anytime it tries to save a file that is in use by another process, and I'd like to avoid that error message, by not trying to say that particular buffer. Is there a way to check a buffer and see if it is being used by another process?
Formatter doesn't work
Submitted by Robert Schwenn on Sunday, 12 February, 2006 - 21:46
Running a beanshell script I got an error at the following expression, because the method "format" is not found:

java.lang.String.format("%d", 1234)

In a java sourcefile it works fine.
==> What's on with the beanshell?

Robert
Open a file at the specified line number (Textmate error handling...)
Submitted by dunnil on Sunday, 12 February, 2006 - 00:22
Hi folks,
There is a rails plugin [1] that convert errors to a url that can be opened by textmate.
Here is the main point:
html = "#{line}"
Is there a way for us to do something like this?

Thanks in advance,
- H


[1] code extracted from the plugin
def add_links_to_backtrace(lines)
lines.collect do |line|
expanded = line.gsub '#{RAILS_ROOT}', RAILS_ROOT
if match = expanded.match(/^(.+):(\d+):in/) or match = expanded.match(/^(.+):(\d+)\s*$/)
file = File.expand_path(match[1])
line_number = match[2]
html = "#{line}"
else
line
end
end
end
Reference for macros
Submitted by mariuszn3 on Thursday, 2 February, 2006 - 17:56
I miss some kind of reference for building macros in jEdit (I can't find it anywhere).. like what properties (if there's any) textArea has etc. Is there any reference on web?

My issue:
I have macro:
------------
textArea.collapseFold();
textArea.expandFold(true);
------------

I'd like first line to be exectuted only if focused line start of not folded content. I thought of something like:
------------------
if (!textArea.folded) {
textArea.collapseFold();
}
textArea.expandFold(true);
---------------------

Of course as I'm just guessing what properties or syntax to use.. it don't work.

Any help?

Thank you.
Go To Line
Submitted by uh on Monday, 30 January, 2006 - 11:16
I am looking for a "goToLine"-function, which does not open the "Go To Line"-Dialog. Is such a function available?
Setting buffer properties -- two questions
Submitted by clif2 on Tuesday, 24 January, 2006 - 00:03
In a macro how do I set the following properties?

1. buffer title
2. character encoding

Thanks,

Clif2
Duplicate Line/Selection
Submitted by Dario_Insane on Monday, 23 January, 2006 - 12:35
i'm new to jedit. and it looks promising. but also a bit overwhelming.. Smiling

how do i implement a 'duplicate line/selection' feature? i assume i have to do this with a macro?

i tried using a copy/paste approach to get at least a 'duplicate line' feature working. but it doesnt do what i want.. :/

i found some text macros for moving lines up/down.. maybe they will help me..

anyway.. any help really appreciated!

regards,

dario
How to close Console after running program in system shell?
Submitted by davmay on Tuesday, 10 January, 2006 - 17:19
I am using this one-line macro to run a program in the system shell:

runInSystemShell(view,"C:\\WINDOWS\\SYSTEM32\\mspaint.exe");

This works fine, but when I have run and closed the program I am left with a jEdit window containing the Console which I have to close manually. Can someone show me how to add a line to my macro to close that Console window? Thanks.

David
Detecting current edit mode in a macro
Submitted by Lee Elms on Monday, 12 December, 2005 - 11:50
How do you determine the current edit mode within a macro ?
Placing selection in clipboard after replacing certain characters
Submitted by ghoetker on Thursday, 24 November, 2005 - 15:29
Hi all. I'm trying to write my first macro and am stuck at multiple points. The task at hand is this. I have text in jEdit of the following format

file write `output' _tab ///
`mformat' (`r(sd)') _tab `mformat' ///
(`r(max)') _tab

I would like to be able to select this text, have the "///" and new_line characters stripped, and the remaining text put in the clipboard, so I can paste it into another application. Thus, the line I would be pasting would be

file write `output' _tab `mformat' (`r(sd)') _tab `mformat' (`r(max)') _tab

I have the sense that the code to do this would be pretty simple, but I'm stuck since it's my first attempt. Could anyone provide me some help?

Thank you in advance.
Macros encoding
Submitted by jojaba on Sunday, 13 November, 2005 - 07:10
Hello,
I'm translating jEdit 4.2 in french (see the link in my signature).
someone use my translation on unbutu (Linux) and said that the accentuated caracters didn't display correctly especially the title of the *.bsh files (macros) and the tips. I do think that's a problem of encoding.
How do I resolve this problem ?

Thanks a lot.
Do "return 1;"?
Submitted by a992400 on Monday, 24 October, 2005 - 04:14
Is there any point to doing "return 1;" instead of "return;" at the end of a macro? Or even "return;" at all? I've seen that in a few of them, but haven't been doing it in mine.
How convert string to number.
Submitted by Driezas on Tuesday, 27 September, 2005 - 07:24
Hi all, Currently i'm trying to write macro to convert degrees to decimal form and back and have some problems. Input is string and I need convert that string after splitting into parts to numbers, but macro ends with error complaining that unable to casto sting to integer. parseInt also not working. What's wrong ? Thanks for answers Here is code:
 void convert_coordinates() {
   private int Laipsniai;
   if (textArea.getSelectedText().contains(" ") == true ) {
     format = 1;
     Macros.message(view,"Degrees");
   } else {
     format = 0;
     Macros.message(view,"Decimal degrees");
   };
   
   switch (format) {
     case 1:
       Elements = textArea.getSelectedText().split(" ");
       Laipsniai = Elements[0];
       Macros.message(view,"Laipsniai: "+Laipsniai);
       textArea.setSelectedText(Laipsniai);
     break;
     
     case 0:
       Elements = textArea.getSelectedText().split("[.,]");
       textArea.setSelectedText("1:"+Elements[0]+" 2:"+Elements[1]);
     break;
   };
 }

 if (textArea.getSelectedText() == null) {
   Macros.error(view,"No coordinates selected !!!");
 } else {
   convert_coordinates();
 };
Retaining variables between calls to a macro?
Submitted by stretch6555 on Monday, 8 August, 2005 - 12:18
Hi,

I'm writing a macro which, during its execution, creates a few variables. I'd like
to somehow save or retain these variables (and their contents) when the macro ends, so
that they can be referred to the next time I execute the same macro (or indeed some other
macro). Is this possible?

At first, I thought maybe I could declare the variables as 'static', but this doesn't seem
to work. I suppose another way of saving information between calls, might be to put
the data into some of the JEdit clipboard registers. Can someone suggest a good
solution to this problem?

Also, is there some class or method that my macro can call that will tell it what the
last key the user pressed was? And what about the last macro that was executed?

Any help would be most appreciated.


Thanks.
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