jEdit Community - Resources for users of the jEdit Text Editor
How to write a macro to Change Auto-Indent Behavior?
Submitted by drefty on Wednesday, 15 September, 2004 - 21:45
PROBLEM: There is one frustrating aspect of auto-indentation with jEdit that I would like to change with a macro. Here is some sample text to demonstrate what I am talking about. ...
1Potato
    2Potato
    3Potato
    4Potato

1Watermellon
    2Watermellon
    3Watermellon
    4Watermellon


If you put the cursor before "1Watermellon" and then press ENTER, jEdit will auto-indent to make it the same indentation level as "4Potato".

This is contrary to what I'd expect because I'm trying to insert some blank non-indented lines in between 'potato' and 'watermellon'. I am *not* trying to make watermellon indented beneath potato.

The problem seems to be that jEdit does auto-indentation based on the previous *non-blank* line, instead of just the previous line.

QUESTION: How can I change this behavior with a macro or with other means, short of recompiling jEdit.
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
gave myself the choice
by silverquick on Sat, 29/04/2006 - 21:06
I noticed this as well, but sometimes I do want the indenting behaviour that bothers you, as in code like this:
while (something) {
  if (first) {
    ...long series of statements...
  }
  
  if (second) {
    ...another long series...
  }
}
I like the two IF blocks to be separated by a blank. Not everyone does, but because of this I decided to give myself the choice: I have ENTER bound to "insert newline & indent" and S-ENTER to only "insert newline".
Alternative: Did you try to reassign shortcuts
by DanielKabs on Thu, 30/03/2006 - 07:50
Hello!

If I understand you correctly you wanted to disable auto-indenting when pressing ENTER. I tried your example and could change the behaviour as you wanted by removing the shortcut that is by default assigned to the ENTER key.

Go to Utilities > Global Options > Shortcuts and find "Insert Newline and Indent". Now click on the Primary Shortcut. In the pop up window click the button "Remove Current".

Btw: this is jEdit 4.3pre3
solution to the question
by Anonymous on Fri, 17/09/2004 - 04:17
/* ------------------------------

main:
  - name    :   FixAutoIndent
    desc    :   modify the default behavior of jEdit autoindent    
    date    :   Thursday, September 16, 2004
details:
  - caption:    overview of this script
    body : |
        This macro tests to see if the caret is inside the leading whitespace of the
        current line. If so, it changes the behavior of jedit autoindent.

        To use this script, put it somewhere in the jedit macros directory and
        assign the ENTER key as a shortcut.


------------------------------ */

/// begin_: init vars
    iLine           = textArea.getCaretLine();
    iLen            = textArea.getLineLength(iLine) + 1;
    iCtPos          = textArea.getCaretPosition();
    iLSOffset       = textArea.getLineStartOffset(iLine);
    iWidth          = iCtPos - iLSOffset;
    sLText          = textArea.getLineText(iLine).toString();
    gnu.regexp.RE oRegExFind
                    = new gnu.regexp.RE("^(\\s*)(.*)", 0, RESearchMatcher.RE_SYNTAX_JEDIT);
    iLeadingSpace   = oRegExFind.getMatch(sLText).toString(1).length();
    bInLeadingSpace = false;

/// begin_: modified autoindent
    if(iLeadingSpace >= iWidth){ bInLeadingSpace = true;}
    if(bInLeadingSpace){
        textArea.setCaretPosition(iLSOffset);
        textArea.userInput('\n');
        textArea.setCaretPosition(iLSOffset + iWidth + 1);
    }else{
        textArea.insertEnterAndIndent();
    }

 
Thanks!
by Anonymous on Wed, 24/11/2004 - 23:58
I had the same question after just starting to use Jedit. Your solution is perfect, thanks!

Hint to the next person: I put the file in ~/.jedit/macros/ but it wasn't noticed by Jedit until I ended it with '.bsh'.
User login
Browse archives
« November 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   101634
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