Master Your Documents with EmEditor, the Powerful Open-Source Text Editor

Master Your Documents with EmEditor, the Powerful Open-Source Text Editor

Jason Lv8

Master Your Documents with EmEditor, the Powerful Open-Source Text Editor

July 30, 2014 at 11:36 am #18710

Stefan

Participant

Sorry, update again.

Better logic:
if last line have whitespace only, just remove these blanks and done.
Else, if last line is not empty, but not whitespace only, add a new line.
(This way we not end up with too “visible blank” lines)

I also added cursor handling to went back from EOF to origin cursor place.
(Not needed for this thread purpose as event script, but if script is used on demand)

Not asked for, but just done for the fun:

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
32
33
34
35
36
37
38
39
//JavaScript Macro for EmEditor, v0.02 by Stefan
//Purpose: Ensure that last line is a blank one, by adding one if need.

//// Don't show the cursor move////
//EmEditor Help - EmEditor Macro Reference - Window Object
//prevents changes in EmEditor from being redrawn:
Redraw = false;

////Store cursor position////
//EmEditor Help - EmEditor Macro Reference - Selection Object
//Returns the column number of the cursor position.
xPos = document.selection.GetActivePointX(eePosLogical);
//Returns the line number of the cursor position:
yPos = document.selection.GetActivePointY(eePosLogical);

////Check status of last line////
//EmEditor Help - EmEditor Macro Reference - Document Object
//Retrieves the number of the lines in the document:
nLines = document.GetLines();
//Retrieves the text on the specified line:
str = document.GetLine(nLines);
//Moves the cursor to the end of the document:
document.selection.EndOfDocument();
//If last line only contains indenting white space, just remove the whitespace//
if(str.match(/^\s+$/) != null){
//Selects a line at the cursor:
document.selection.SelectLine();
//Deletes the selected text:
document.selection.Delete();
}else if (str.length != 0){
//If last line is NOT empty, but not whitespace only, add one blank line//
document.selection.NewLine();

////Restore cursor position////
//Sets the cursor position:
bExtendSelection = false;
document.selection.SetActivePoint(eePosLogical, xPos, yPos, bExtendSelection);

//<EOF>

Also read:

  • Title: Master Your Documents with EmEditor, the Powerful Open-Source Text Editor
  • Author: Jason
  • Created at : 2024-11-26 00:55:21
  • Updated at : 2024-11-30 19:59:35
  • Link: https://win-luxury.techidaily.com/master-your-documents-with-emeditor-the-powerful-open-source-text-editor/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
Master Your Documents with EmEditor, the Powerful Open-Source Text Editor