[ jEdit-users ] BeanShell

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[ jEdit-users ] BeanShell

Zoltán Kócsi
Can I save a temporary buffer?

I'd like to keep a sort of a resource file (actually more than one) in
the background, used by some BeanShell macros. When the user fires up
the macro, I'd like to load the file into a temporary buffer, manipulate
it and then save it back to disc, without modifying the rest of jEdit's
state or opening new views or anything else.

To make it clearer, here's a hypotethical example:

We need a BeanShell macro which is bound to a key. It has to append a
one-line timestamp to a (text) file every time the key is pressed. No
need to worry about multi-threading, race conditions, file locking or
any other stuff; absolute basic single-everything situation. Also,
initially we can ignore error handling.

So, I thought this skeleton would be an acceptable solution:

buffer = open_a_temporary_buffer_and_load( "my_path/my_file" );
buffer.insert( end_of_the_text, get_time_as_text() + "\n" );
buffer.save();
buffer.close();

The first bit looked promising:

buffer = openTemporary( view, "my_path", "my_file", false );

is just what I want. But I encountered two problems:

- The call returns a buffer even if the file does not exist. Which I
  don't understand: the last argument being 'false' tells the method
  that I want the file to be loaded from the disc. According to the
  docs I supposed to get a null if the file cannot be loaded.

- I found a method to close a buffer, which will then ask the user
  whether changes should be saved. There's also a method which saves
  all buffers, no questions asked. But I couldn't find a method that
  saves a single buffer or a method which closes a buffer, silently
  saving it if its dirty.

So, I have two questions:

1. Is the above described behaviour of openTemporary() is a bug
(unlikely) or user error (probable). If the latter, what have I missed?

2. How can I save (or save-and-close) a single buffer, without user
interaction?

Thanks,

Zoltan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
--
-----------------------------------------------
jEdit Users' List
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jedit-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ jEdit-users ] BeanShell

Zoltán Kócsi
> 2. How can I save (or save-and-close) a single buffer, without user
> interaction?

Never mind, I figured out.

jEdit has a static closeBuffer() method but no saveBuffer().
Buffer has a save() method but no close().

Yes, I know, RTFM.

Sorry,

Zoltan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
--
-----------------------------------------------
jEdit Users' List
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jedit-users
Loading...