forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Rearranging tabbed code from another editor
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Plato
View previous topic :: View next topic  
Author Message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Thu Jan 07, 2010 7:44 am    Post subject: Rearranging tabbed code from another editor Reply with quote

It sometimes happes that one get Fortran 77 code that was edited in another editor. Depending on how tabs and spaces are handled, an import in Plato can mean that many lines are not within the 72 character limit. Furthermore, a line break can also be a problem.

In case of a few lines it is no problem to do it by hand. Is there perhaps some trick a method to get the code correct in case of a few thousand lines?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5437
Location: Salford, UK

PostPosted: Thu Jan 07, 2010 8:32 am    Post subject: Reply with quote

FTN95 assumes that a tab is the same as 8 spaces. Plato on the other hand can be configured to any tab size that you want to use.

You can view the tabs in Plato by showing all white space (Ctrl+Shift+W on my machine but I may have configured it this way. See Tools menu, Options dialog, under Keyboard, Edit.ShowWhiteSpace).

The best way forward is to use the same Options dialog to set "Replace tabs with spaces" under Text Editor and General. Then what you see in Plato will be the same as what the compiler interpretes.
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Thu Jan 07, 2010 10:37 am    Post subject: Reply with quote

Thanks, making the tabs and spaces visible helps a lot. It would be nice to have a "smart indent" function in Plato, i.e. some function that automatically takes care of the indent.

Find and replace is an option, but this often (with the code I have) ends up in something even worse than before. Or are the perhaps some known example on the web just waiting to be downloaded?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5437
Location: Salford, UK

PostPosted: Thu Jan 07, 2010 12:53 pm    Post subject: Reply with quote

Plato already has some smart indenting when typing Fortran.
Constructs such as DO etc. auto-indent provided you select "Automatic block indentation" from the Options dialog under Text Editor and General.

If you want to reduce the indentation then press SHIFT and ENTER.
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Fri Jan 15, 2010 2:09 pm    Post subject: Reply with quote

Thanks for the tips. What possibilities do I have to rearrange the code when I "import" source code that was not edited from the begining with Plato. The code that I am working on originated in the time before PC's. The over 10 000 lines of code is not "organised" which makes reading it extremely difficult. Luckily all the carination characters are in the correct column!
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5437
Location: Salford, UK

PostPosted: Fri Jan 15, 2010 2:28 pm    Post subject: Reply with quote

In the Options dialog under Environment and Keyboard, you will find an entry Edit.ReplaceTabs. This is set to Ctrl+Shift+T on my machine but I do not remember if this is the default.

You can use this when you first open a file but make sure that your tab size for fixed Fortran is set correctly before you do this.

If you want to remove the tabs in all the files in one go then you could write a little Fortran program to do this. Alternatively you could experiment with the Plato macro recorder but it probably isn't clever enough to handle this task. Another editor like Word for Windows or Visual Studio might manage it via a macro.
Back to top
View user's profile Send private message
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Fri Jan 22, 2010 10:20 am    Post subject: Re: Reply with quote

PaulLaidler wrote:
Plato already has some smart indenting when typing Fortran.
Constructs such as DO etc. auto-indent provided you select "Automatic block indentation" from the Options dialog under Text Editor and General.

If you want to reduce the indentation then press SHIFT and ENTER.


I get auto-indentation of DO even though I don't have that option checked!? On the other hand, I can't make any sense of SHIFT-ENTER at all, whether I have the option checked or not. If I select some lines and hit S-E, they just get deleted. If I place the cursor at the start of a line and hit S-E, I get a new blank line and the original line doubles its original indentation. How is it supposed to work?

I agree with Johann, improving the indentation would be a really good thing to do. All it would require would be assigning a keystroke combination to the existing menu item. Having to navigate to the third level of the menu with the mouse, to achieve one space of indentation per navigation, is extremely inefficient.

Andy
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5437
Location: Salford, UK

PostPosted: Fri Jan 22, 2010 1:05 pm    Post subject: Reply with quote

I will have a look at this to see if I can see any problems with Plato.
SHIFT + ENTER is supposed to reduce the indentation so that you can use this before a new line for ENDDO etc.
Back to top
View user's profile Send private message
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Fri Jan 22, 2010 3:30 pm    Post subject: Re: Reply with quote

PaulLaidler wrote:
I will have a look at this to see if I can see any problems with Plato.
SHIFT + ENTER is supposed to reduce the indentation so that you can use this before a new line for ENDDO etc.


OK, now I understand how it's supposed to work, I've tried again (on a different machine). For me (in Plato v4.10), Shift-Enter just introduces a new line and maintains the current indentation.

Even if it worked, it would be complementary to a more slick way to indent and outdent blocks of existing code.

Andy
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5437
Location: Salford, UK

PostPosted: Fri Jan 22, 2010 4:10 pm    Post subject: Reply with quote

The auto indent option is only for curly brackets in C etc.

The auto indent is always on for Fortran and it has the effect of providing additional indentation (when pressing ENTER) after lines beginning with DO, IF etc.

If you press SHIFT+ENTER there is no indentation.

For fixed Fortran you get extra help in the label field etc.

This was the best I could do with the time available. I can put this on the wish list if you want to tell me how it could be improved.
Back to top
View user's profile Send private message
brucebowler



Joined: 02 Feb 2006
Posts: 153

PostPosted: Fri Jan 22, 2010 4:58 pm    Post subject: Reply with quote

Here's how I'd improve it - Have a look at the matlab editor

When I type a line that starts with for (ML equivalent of do) all subsequent lines are indented until I enter an end, which is outdented to line up with the do. Similarly for if (although I suspect you'd really need to check for the the "then")

The ML editor also has a "clean up the indenting" option where I can type ctrl/a ctrl/i (select all and auto indent) which "does the right thing" for the whole file.

I realize that fortran is a little more complex than the matlab language and that none of this is a trivial task (else it would have been done long ago) but it's a goal worth aiming for.

Bruce
Back to top
View user's profile Send private message
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Fri Jan 22, 2010 5:54 pm    Post subject: Re: Reply with quote

PaulLaidler wrote:
The auto indent option is only for curly brackets in C etc.

The auto indent is always on for Fortran and it has the effect of providing additional indentation (when pressing ENTER) after lines beginning with DO, IF etc.

If you press SHIFT+ENTER there is no indentation.

For fixed Fortran you get extra help in the label field etc.

This was the best I could do with the time available. I can put this on the wish list if you want to tell me how it could be improved.


Paul - sorry, but I'm having trouble understanding what you are saying here, relative to what you said before.

Are you agreeing that the Tools-Options -Text Editor-General "Automatic block indentation" setting has no effect on FORTRAN source code? This is certainly how it seems to me, but it's different to what (I thought) you were saying earlier in the thread.

I also misunderstood what you meant about Shift-Enter until just before I hit Send. Then I read it again and a potential light went on. But it still doesn't behave as I (currently) understand you to mean: if I enter a DO line of source code and hit Shift-Enter rather than simply Enter, not only do I get no indentation, I get outdentation (new line starts two spaces to the left of the DO rather than two spaces to the right). Again, this is true whether or not I have the Text Editor-General setting checked.

As to wish list ... most of the Plato menu items seem to have keyboard shortcuts. Edit-Advanced-Increase/Decrease Indentation are unusual in not doing so, and I'm not sure why - they seem to me to be more deserving candidates than many, because they only work one space at a time and thus usually need to be iterated more than once. Provision of a keyboard shortcut for these two menu items would be on my wish list - but since I'm not paying maintenance at the moment, you'd need independent support for the suggestion.

Andy

(1) no slight on FTN95, just an anticipated decrease in usage
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5437
Location: Salford, UK

PostPosted: Sat Jan 23, 2010 9:08 am    Post subject: Reply with quote

Andy

You are correct and it has been necessary for me to correct myself in this thread. The auto indent switch only applies to curly brackets (in C type languages) and you don't get these in Fortran!

The behaviour that you describe of SHIFT+ENTER in Fortran is near enough to what I expected.

I can add the accelerator key quite easily. Not now. Perhaps on Monday.
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Sun Jan 24, 2010 10:46 am    Post subject: Reply with quote

The Matlab editor is also what I have in mind. There you can mesh up the code indentation and afterwords select an option to "smart indent" it again. The need for such an option can arise, among others, in the following situations:
1.) import code from another text editor and
2.) when one copy some code into a if-statement or do-loop.

However, the Matlab editor has some disadvantage (at least in my memory). Once you used the latest editor you cannot go back to the previous one (without getting some problems). This would be a problem in Fortran since we have to cope with all the language developments. I think that it will be really tricky to "fix" some code if one mixes the syntax.

The free code converters form Metcalf and Allan works OK, but not really as I would like it to work. Anyway, it will be difficult to find some editor that can do everthing. Plato works fine for me and I quite often use it instead of Wordpad or Notebook for "general" purpose tasks!
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 1968
Location: Sydney

PostPosted: Sun Jan 24, 2010 1:27 pm    Post subject: Reply with quote

Without wanting to create a new wave of ed discussions, the editor I use has block mode which is good for re-doing indenting. ( ed 4 windows )
Lots of us forum participants use different editors, which we are very loyal to. There are many posts on this issue.

I think you can redefine the indent size in Allan Miller's program, but it does come with a lot of other reformatting baggage (which can be very useful if you are, like me, a supporter of implicit none). In the end, it is not too hard to write your own program for limited indenting.

John
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Plato All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group