1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

pasting text with tabs from the clipboard

Discussion in 'Suggestions' started by Frank, Jul 4, 2012.

  1. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    When I'm creating batch-scripts, I use a lot of indentation with tabs to make the code better readable.
    When I copy parts of the code or even a codeblock into the clipboard
    and paste it to the TCC command window for testing, it stops at the first tab or produces a great derangement.

    I think it is caused by filename completion, but is there a way to avoid this?
    Or shouldn't filename completion be disabled during the paste process (that's my suggestion)?

    I could imagine that many users have this problem, which is pretty annoying for me.
     
  2. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    649
    Likes Received:
    1
    I stopped using tabs for indenting eons ago.
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,091
    Likes Received:
    85
    The copy/paste can't ignore tabs, because the copying is occurring in one application (Take Command) and the pasting is done by injecting the characters into the keyboard input of another application (TCC in this instance, but it could be anything -- and only TCC would consider tabs to be a special key).
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,374
    Likes Received:
    40
    How are you pasting? Control-V works fine for me, tabs and all.
     
  5. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    That goes for me as well. Too many variations on default tab settings.
     
  6. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    David and Steve, how are you indenting? With spaces? For me it is not comfortable.
    Let's assume I have the follwing snippet copied from np++ to the clipboard (I know it's not really reasonable here but I have this actually on my monitor):
    The first line is indented with spaces, tho following with tabs.
    Code:
    set    dir=d:\IO
    set    dir=%@getdir[%dir]
    echo   "%dir"
    if     "%dir" eq "" (
    echo   no dir selected, quitting
    goto   end
    )
    
    With right mouse click in TCC I get this:
    Code:
    C:\...\TCCLE13x64 >set    dir=d:\IO
    C:\...\TCCLE13x64 >set_
     
    (and a beep)
    
    And with ctrl-v only the first line is pasted:
    Code:
    C:\...\TCCLE13x64 >set    dir=d:\IO_
     
    (no beep)
    
    (note the underscore which represents the cursor)

    What could be against ignoring tabs during the paste process respectively replacing them with spaces?
    I'm often annoyed by this. I have to go back to the editor, convert tabs to spaces, copy to clipboard, paste it in TCC and finally perform an undo of the convert in the editor.

    regards
     
  7. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    649
    Likes Received:
    1
    All my code uses spaces for indenting. My editor automatically indents using spaces when I press Enter or Tab.
     
  8. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    np++ has this option, too. But I'm soooo used to indenting with tabs.
     
  9. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    649
    Likes Received:
    1
    How is using spaces harder if the editor does the indenting (and undenting) for you? I suppose pressing backspace is different.
     
  10. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    hmmm. dont' know. have to think (and sleep) about it.
     
  11. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,374
    Likes Received:
    40
    Code:
    tpipe /input=clip: /number=0,4 /output=clip:
    
    The second argument to /NUMBER appears to be the tab width.
     
  12. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    For 2 days I tried to get familiar with "space-indenting", but it drives me crazy.
    In my actual script I do a lot of echoing and it is definitly a difference if you
    echo<tab>text
    or
    echo<space><space><space><space>text.
    I "believe" I've also seen functional differences when using

    if conditiion (
    <space><space><space><space><space><space><space><space>blah
    <space><space><space><space><space><space><space><space>blah
    )
    and so on.
    But I changed back to "tab-indenting" (never change a running system ;-)

    So PLEASE make it possible to ignore tabs (convert them to a space) when pasting text into then TCC console window.
     
  13. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Thank you, looks like a convenient solution, in special as an alias.
    I will try it when I've got a licenced V.14.
     
  14. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,374
    Likes Received:
    40
    I was going to suggest DETAB < CLIP: > CLIP: and then thought there might be some clever way to do it using TPIPE. But if you don't have TPIPE, there must be a dozen implementations of DETAB out there.
     
  15. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Just to make it clear: If you are a programmer and are developing code with an IDE, you're right. In this case I wouldn'd care about space- or tab-indenting, too, because that doesn't has an influence on the binary.
    But I use TCC as my "native" language, so all formatting in the script has direct impact to the output.

    Is that comprehensible (because english is not my first language)?
     
  16. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    649
    Likes Received:
    1
    What effect in a script are you achieving with tab that you can't achieve with spaces?
     
  17. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    I had an inexplicable error and for a moment I thought to isolate and prepare it for the forum.
    But it was late in the evening and I reverted to space-indenting.
    It was something like
    Code:
    for /L ... (
        set /a array[0]=%array[0] + ...
    )
    
    I first changed it to @eval (no improvement)l, then to a DO loop (no improvement) and finally changed it to tab-indenting (worked as expected).
    Sorry, I don't remember it exactly. I know, this is unsatisfying for the forum.
     
  18. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    I just forgot it. This is the script I was working on ( and stumbled over tab- vs. space-indenting again :) )
    It's just to share the code with you. Perhaps someone can profit from it.
    Code:
    @echo    off
    rem    fcpy.btm (file count per year)
    rem    usage: fcpy [/y:n] n=years back [> filename] filename= csv-file for excel
    rem
    rem    - generating a statistical report of # files / size of files for a choosen directory
    rem    - values too old or in the future ( generated e.g. by misconfigured digicams ) are summarized
    rem    - uses "logparser" as an external utility
    rem    - the output can be used in ms excel ( convert text to columns )
    rem    frank, july 2012
     
    setlocal
    on      break goto end
     
    rem    standard for back is 10 years. did user supply /y:n ?
    set    yearsback=10
    if      %@word[":",0,%1] eq /y set yearsback=%@word[":",1,%1]
     
    rem    array-index, 0-based
    set    /a lastindex=%yearsback + 1
    rem    number of elements, 1-based
    set    /a nelements=%yearsback + 2
    set    /a baseyear=%_year - %yearsback
     
    unsetarray /q  array
    setarray        array[%nelements,2]
    unsetarray /q  sumarray1
    setarray        sumarray1[2]
     
    set    dir=n:\dv\dlfj
    rem    @getdir returns empty string if the user selects "Cancel" or presses Esc
    set    dir=%@getdir[%dir]
    if      "%dir" eq "" (
            echo    no dir selected, quitting
            goto    end
            )
           
    rem    generating header lines
    echo    Distribution of File-Age and -Size for Directory "%dir"
    echo.
    echos  Dir,,older,,
    for    /L %y in (1,1,%@eval[%lastindex - 1]) echos %@eval[%baseyear + %y],,
    echo    future,,totals
    echos  ,# Files,MB,
    for    /L %y in (1,1,%@eval[%lastindex - 1]) echos # Files,MB,
    echo    # Files,MB,# Files,MB
     
    setdos  /x-56
     
    rem    first only the basedir
    set    subdir=%dir
    gosub  count -recurse:0
     
    rem    then all subdirs
    do      subdir in /o:n /a:d "%dir"\*.*
     
            gosub count -recurse:-1
     
    enddo
    setdos  /x0
     
    :end
    endlocal
    quit
     
    :count [ recurse ]
     
    rem echoerr %subdir
           
    rem if      %@files["%subdir",d] eq 0 (
    rem        echo        %subdir,
    rem        return
    rem        )
     
    rem    zeroing all array-elements
    do      loop = 0 to %lastindex
     
            set array[%loop,0]=0
            set array[%loop,1]=0
     
    enddo
    del    /qe filecount_per_year.csv
     
    rem    logparser produces something like this (year,#files,size):
    rem    1997,8,1820999
    rem    1999,6,786109
    rem    2002,174,100661945
    rem    2003,188,132494748
    rem    2008,113,1935912035
    rem    2009,58,52290671
    rem    2010,148,581229337
    rem    2011,95,4742529049
    rem    2012,105,718922410
     
    logparser -i:fs  %recurse %=
            "select to_string(LastWriteTime,'yyyy') as year, count(*) as count, sum(size) as total      %=
            into    filecount_per_year.csv  %=
            from    '%subdir\*.*'    %=
            where  attributes not like 'D%%'      %=
            group  by year order by year"  %=
            -o:csv -q:on -filemode:0 -headers:off
     
    if %? ne 0 (
            echoerr pause fehler in "%subdir"
            pause "%subdir"
            )
    set    count=0
    set    tsize=0
    set    sumarray1[0]=0
    set    sumarray1[1]=0
     
    do      line in @filecount_per_year.csv
     
            set    year=%@word[",",0,%line]
            set    count=%@word[",",1,%line]
            set    tsize=%@word[",",2,%line]
            set    tsize=%@eval[ %tsize / 2**20]
            set    tsize=%@formatn[ .0,%tsize]
           
            rem    too old / too young ?
            iff    %year LE %baseyear then
                   
                    rem    older
                    set    /a array[0,0]=%array[0,0] + %count
                    set    /a array[0,1]=%array[0,1] + %tsize
           
            elseiff %year GT %_year then
           
                    rem    future dates
                    set    /a array[%lastindex,0]=%array[%lastindex,0] + %count
                    set    /a array[%lastindex,1]=%array[%lastindex,1] + %tsize
           
            else
                    set    /a aindex=%year - %baseyear
                    set    array[%aindex,0]=%count
                    set    array[%aindex,1]=%tsize
                   
            endiff
           
            set    /a sumarray1[0]=%sumarray1[0] + %count
            set    /a sumarray1[1]=%sumarray1[1] + %tsize
    enddo
     
    echos  "%subdir",
    do      loop = 0 to %lastindex
     
            echos  %array[%loop,0],%array[%loop,1],
    enddo
    echos  %sumarray1[0],%sumarray1[1]
     
    echo.
     
    return
    
     

Share This Page