EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     How to know a doc's return method
Register To Post

Threaded | Oldest First Previous Topic | Next Topic | Bottom
Poster Thread
chjfth
Posted on: 7/5/2010 4:13 am
Quite a regular
Joined: 10/20/2006
From:
Posts: 41
Re: How to know a doc's return method
Many thanks to your final clear reply. Now I know that EmEditor supports mixed EOL mark. And thank you for pointing out


str = document.GetLine( 1, eeGetLineWithNewLines )


can find out the EOL of line 1. (Yes, I must use 1 as first parameter instead of 0. 0 will cause script error "Invalid procedure call or argument".

Now, I realize that I pratically don't have to care if current text file has LF or CRLF as end-of-line marker; I can simply replace all occurence of "\r\n" to "\n" before counting slen, then my goal is fulfilled.

So my script becomes:


' This VBScript macro do the following:
' For a block of selected text, 
' * if a / is found, replace all occurance of / to \ .
' * else if a \ is found, replace all \ to / .
' After the macro is executed, the converted text will remain at its select state(invert-colored).

Set ds = document.selection
TextCopy = Replace(ds.Text, chr(13)+chr(10), chr(10)) 'replace \r\n to be one \n
slen = Len(TextCopy) 'get selected text length, \r\n counted as only one char
posSlash = InStr(ds.Text, "/")
posBkSlash = InStr(ds.Text, "\")

If posSlash>0 and (posBkSlash=0 or posBkSlash>posSlash) Then
	' / in selected text and / appears before \ 
	ds.Text = Replace(ds.Text, "/", "\")
	ds.CharLeft True, slen 'make the new text in selected state(inverted color)
ElseIf posBkSlash>0 Then
	' \ in selected text
	ds.Text = Replace(ds.Text, "\", "/")
	ds.CharLeft True, slen
Else
	Set WshShell = CreateObject( "WScript.Shell" )
	n = WshShell.Popup( "There is no / or \ in your selected text. This macro can do nothing.", 0, "EmEditor Macro running", 0 )
End If


EmEditor is so great with custom script.
Yutaka
Posted on: 7/4/2010 5:55 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2397
Re: How to know a doc's return method
dc.FileSave.ReturnMethod usually always returns 0. This means the configuration will not alter the return method of a document. EmEditor supports files that have mixed return methods.

If you want to find the return method of the current document and if you know the return method is the same in the entire document, you can write:

str = document.GetLine( 0, eeGetLineWithNewLines )

Then you can find what the return method of the current document is.

I hope this helps.
If you have further questions, please let me know.
Thanks!


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

chjfth
Posted on: 7/4/2010 5:24 pm
Quite a regular
Joined: 10/20/2006
From:
Posts: 41
Re: How to know a doc's return method
Excuse me, I cannot tell how document.GetLine() can help. In order to call GetLine, I have to know the line numbers of the selected text, which seems to stray away from my topic.

This issue is not urgent. I can wait until next EmEditor release when you add a document property to tell current document's return method.

Regards.
Yutaka
Posted on: 7/4/2010 12:27 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2397
Re: How to know a doc's return method
Hi,

GetLine method (Document object) allows you to add new line character(s) (CR, LF, or CR+LF) at the end of the line.


str = document.GetLine( yLine, eeGetLineWithNewLines )


Then you can correctly count the line length.

I hope this helps.


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

chjfth
Posted on: 7/3/2010 10:27 pm
Quite a regular
Joined: 10/20/2006
From:
Posts: 41
Re: How to know a doc's return method
Oh, yes, I do have a further question.

I'm writing a slash-cvt.vbee macro.


' This VBScript macro do the following:
' For a block of selected text, 
' * if a / is found, replace all occurance of / to \ .
' * else if a \ is found, replace all \ to / .
' After the macro is executed, the converted text will remain at its select state(invert-colored).

Set ds = document.selection
slen = Len(ds.Text) ' get selected text length
posSlash = InStr(ds.Text, "/")
posBkSlash = InStr(ds.Text, "\")

If posSlash>0 and (posBkSlash=0 or posBkSlash>posSlash) Then
	' / in selected text and / appears before \ 
	ds.Text = Replace(ds.Text, "/", "\")
	ds.CharLeft True, slen 'make the new text in selected state(inverted color)
ElseIf posBkSlash>0 Then
	' \ in selected text
	ds.Text = Replace(ds.Text, "\", "/")
	ds.CharLeft True, slen
Else
	Set WshShell = CreateObject( "WScript.Shell" )
	n = WshShell.Popup( "There is no / or \ in your selected text. This macro can do nothing.", 0, "EmEditor Macro running", 0 )
	Set dc = document.config
	crlf_style = dc.FileSave.ReturnMethod
	WshShell.Popup "abc" & crlf_style
End If


If the selection is partial line, or, multiple lines of a Unix text file, it works well. However, if the selection is multiple lines of a CRLF text file, there is something wrong: <code>ds.CharLeft True, slen</code> will move(select) visually more characters than I expect, --because, at end of a line, <code>ds.CharLeft True, 1</code> will actually step 2 characters(CR and LF).

So, If I can know whether a text file is CRLF-ed, I can replace all CRLF to LF before I count slen=Len(ds.Text) , so that the finally selection length will be correct.

I hope you can add this property in future version. On the other hand, is there another way to achieve the same goal(implement the slash-cvt.vbee macro)?
Yutaka
Posted on: 7/3/2010 9:03 am
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2397
Re: How to know a doc's return method
Hello chjfth,

If you just want to know the Return method of the current document, you can display that information on the Status Bar. Please go to Customize on the Tools menu, and select the "Status" tab, and check "Return Method".

Please let me know if you have further questions.

Thank you for using EmEditor!


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

chjfth
Posted on: 7/3/2010 4:00 am
Quite a regular
Joined: 10/20/2006
From:
Posts: 41
How to know a doc's return method
Hello, Yukata,

I want to know the return method of current active document from macro code in Emeditor. So I tried the following VBS snippet,


Set WshShell = CreateObject( "WScript.Shell" )
Set dc = document.config
crlf_style = dc.FileSave.ReturnMethod
WshShell.Popup "crlf_style " & crlf_style


However, whether I run this macro on a Windows text file(CRLF) or Unix text file(LF), I always get "crlf_style 0". Is there a way to work me out?

Tried on EmEditor v8 and v10.0, same result.

Thank you.

Threaded | Oldest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文