Author Topic: How to expand tabs to spaces for only modified lines  (Read 4504 times)

Prax

  • Community Member
  • Posts: 11
  • Hero Points: 0
How to expand tabs to spaces for only modified lines
« on: April 19, 2012, 07:56:54 AM »
Dear All :

I want to know how to set "expand tabs to spaces for only modified lines".

I try to modify "Save->Expand tabs to spaces" to "True",but it expand tabs to spaces for all lines.
The save setting have unnecessary changes for my svn or git repo.

Phil Barila

  • Senior Community Member
  • Posts: 745
  • Hero Points: 61
Re: How to expand tabs to spaces for only modified lines
« Reply #1 on: April 19, 2012, 02:44:16 PM »
You don't mention what version you are using.  v16 (and v17 Beta) will strip trailing space from modified lines only, but it appears that tabs to spaces is an all or nothing proposition.  Seems like a good feature request.

Prax

  • Community Member
  • Posts: 11
  • Hero Points: 0
Re: How to expand tabs to spaces for only modified lines
« Reply #2 on: April 19, 2012, 03:52:19 PM »
My version is 16000300_win32.

Do you mean that the feature for only modified lines had been not ready?

Phil Barila

  • Senior Community Member
  • Posts: 745
  • Hero Points: 61
Re: How to expand tabs to spaces for only modified lines
« Reply #3 on: April 19, 2012, 04:03:04 PM »
I mean it doesn't exist.  I posted it, with a link to this thread, in the feature request thread.

Prax

  • Community Member
  • Posts: 11
  • Hero Points: 0
Re: How to expand tabs to spaces for only modified lines
« Reply #4 on: April 19, 2012, 04:35:35 PM »
ok, thank you, Phil Barila

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: How to expand tabs to spaces for only modified lines
« Reply #5 on: April 19, 2012, 04:49:54 PM »
This topic shows how the macro was written to strip trailing whitespace only from modified lines, before the feature was built into the editor.

It would be pretty straightforward to change it to call convert_tabstospaces on each line.

Prax

  • Community Member
  • Posts: 11
  • Hero Points: 0
Re: How to expand tabs to spaces for only modified lines
« Reply #6 on: April 20, 2012, 06:25:38 AM »
 ;) Thanks, chrisant.

It's very useful for me.
I modified saveload.e and work well, as follow :
1. Fix some error for "Attempt to call deprecated function"
2. Implemented "Expand tabs to spaces only from modified lines"

Code: [Select]
#pragma option(pedantic,on)
#region Imports
#include "slick.sh"
#include "os390.sh"
#import "backtag.e"
#import "files.e"
#import "main.e"
#import "stdcmds.e"
#import "stdprocs.e"
#import "tagform.e"
#require "se/lang/api/LanguageSettings.e"
#require "se/lang/api/ExtensionSettings.e"
#import "filewatch.e"
#import "util.e" // [Prax+2012-04-20]
#endregion

_str save_file(_str filename,_str options)
{
#if 0
   int renumber_flags=numbering_options();
   if (renumber_flags&VSRENUMBER_AUTO) {
      if (renumber_flags&VSRENUMBER_COBOL) {
         renumber_lines(1,6,'0',false,true);
      }
      if (renumber_flags&VSRENUMBER_STD) {
         renumber_lines(73,80,'0',false,true);
      }
   }
#endif

//----->>>[Prax+2012-04-20]
#if 1
   _str as_dir=def_as_directory;
   if (as_dir=='') {
      as_dir=_ConfigPath():+'autosave':+FILESEP;
   }
   if (pos(as_dir,filename,1,'I')!=1) {
      typeless p;
      _save_pos2(p);
      top();
      do {
         if (_lineflags()&(MODIFY_LF|INSERTED_LINE_LF)) {
            _str line,stripped;
            get_line(line);
            stripped=expand_tabs(line);
            if (line:!=stripped) {
               replace_line(stripped);
            }
         }
      } while (down()==0);
      _restore_pos2(p);
   }
#endif
//-----<<<<[Prax+2012-04-20]

   typeless status=_save_file(options " "filename);
   if (!status && file_eq(strip(filename,'B','"'),p_buf_name)) {
      //_cbsave_filewatch();
#if 1
      call_list('_cbsave_');
      //10:51am 7/3/1997
      //Dan modified for auto-tagging
      if (def_autotag_flags2&AUTOTAG_ON_SAVE) {
         //messageNwait(nls('got here'));
         TagFileOnSave();
      }
#endif
   }
   return(status);

}