jEdit Community - Resources for users of the jEdit Text Editor
Reading and writing settings in ini-files
Submitted by tvojeho on Saturday, 26 November, 2011 - 13:05
Hi, I wanted to ask if anybody might have written a beanshell macro or function to be able to read and write settings in inifiles. The jedit properties do not handle the [Section] parts of the inifiles.

I have been trying to rewrite some functions written for the autohotkey language but the regexes seem to go over my head. I managed to scramble together one function (ini_get, see below), but it was more trial and error than knowing what I was doing, and I was wondering if someone already has written something similar.

Code:
ini_get(_Content, _Section, _Key, Flags, Default)
{
_Section = "\\[\\s*?\\Q"+_Section+"\\E\\s*?]";

//-- Note: The regex of this function was rewritten by Mystiq.
RegEx = "(?im)(?:\\n|^)\\s*"+_Section+"\\s*(?:\\n\\s*|\\n\\s*.+\\s*=\\s*.*?\\s*(?=\\n)|\\n\\s*[;#].*?(?=\\n))*\\n(\\s*\\Q"+_Key+"\\E\\s*=(.*))(?=\\n|$)";

//-- Kompilovat regex expression
Pattern p = Pattern.compile(RegEx);
//-- Vytvořit matcher (boolean)
Matcher m = p.matcher(_Content);
if(m.find())
{
Section = m.group(0);
Key = m.group(1);
Value = m.group(2);
}

if(Flags.indexOf('s') != -1)
return Section;
else if(Flags.indexOf('v') != -1)
return Value;
else if(Flags == null || Flags == "" || Flags.indexOf('k') != -1)
return Key;
}

Regards, tvojeho
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Solved
by tvojeho on Fri, 16/12/2011 - 22:33
Only wanted to mention that I managed to solve this issue with [ini4j]
library (http://ini4j.sourceforge.net/index.html).

tvojeho
User login
Browse archives
« October 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   100936
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17481
Advanced HTML edit mode   1.0   16213
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14300