ModifyingtheIndentedPastebehavior

Suggestions.ModifyingtheIndentedPastebehavior History

Hide minor edits - Show changes to markup

November 07, 2008, at 10:32 UTC by Isak Johnsson - Added a vague idea of how to remedy this in the current version
Added lines 101-103:

Is it possible to make a macro or command to paste without changing the indentation? I would like to bind that to command-V and bind option-command-V to paste with indentation, but only in Python.
-- isak@hypergene.com Isak Johnsson

April 13, 2005, at 22:07 UTC by Allan Odgaard -
Changed lines 97-100 from:

What would be outstanding is if TextMate offered the option of taking blank lines into account on indented paste so that if a blank line is above the spot you are pasting to, it pastes the code in starting in column 1.

to:

What would be outstanding is if TextMate offered the option of taking blank lines into account on indented paste so that if a blank line is above the spot you are pasting to, it pastes the code in starting in column 1.

I'm afraid this would pretty much cripple the feature for the 99% language which does have explicit scope end-markers (at least I do often have blank lines above my pastes w/o wanting to change indent level). I have changed the algorithm slightly for beta 6, so when there are blank lines above the pasted text, it will try to figure out if it should decrease indent level. But I doubt it'll improve it for OCaml/Python. There will be a second round of improvements in the future, probably involving a plugin to decide indentation level though.
-- Allan Odgaard

December 22, 2004, at 17:24 UTC by William D Neumann -
Changed lines 67-68 from:

What happens is that TextMate ignores the blank line after gen_random, and pastes the selectRandom code according to the indentation of the last line of gen_random.

to:

What happens is that TextMate ignores the blank line after gen_random, and pastes the selectRandom code according to the indentation of the last line of gen_random. The opening let of selectRandom should be aligned with the opening let of of gen_random, not with its last line.

December 22, 2004, at 17:22 UTC by William D Neumann -
Changed lines 1-97 from:

Gimme a sec... I'm still typing this up.

to:

For the most part, I love the indented paste feature, however...

TextMate has a nasty habit (some might say feature) of ignoring blank lines when it comes to indenting. This is especially annoying when I am moving code about and not pasting it inside of another function. For example, consider the following code snippet:

  let gen_random =
    let last = ref 42 and im = 139968 and ia = 3877 and ic = 29573 in
    let fim = float im in
    fun () -> last := (!last * ia + ic) mod im; (float !last) /. fim;;

  let selectRandom () =
    let rec afh r i =
      if r <= arr.(i).p then arr.(i).c else afh r (succ i)
    afh (gen_random ()) 0;;

  let makeRandomFasta id desc arr n =
    let rec loop n =
      if n > 0 then
      begin
        let x = n < length in
        for i = 0 to pred (if x then n else length) do 
          s.[i] <- (selectRandom ())
        done;
        if x then String.fill s n (length - n) ' ';
        print_endline s;
        loop (n - length)
      end in
    Printf.printf ">s\n" id desc;
    loop n;;

Now, if I want to make selectRandom local to makeRandomFasta, the indented pasting works properly:

  let gen_random =
    let last = ref 42 and im = 139968 and ia = 3877 and ic = 29573 in
    let fim = float im in
    fun () -> last := (!last * ia + ic) mod im; (float !last) /. fim;;

  let makeRandomFasta id desc arr n =
    let selectRandom () =
      let rec afh r i =
        if r <= arr.(i).p then arr.(i).c else afh r (succ i) in
      afh (gen_random ()) 0 in
    let rec loop n =
       <...SNIP...>

However, if I go the other way, and decide that I want to move selectRandom outside of makeRandomFasta, I get bit...

  let gen_random =
    let last = ref 42 and im = 139968 and ia = 3877 and ic = 29573 in
    let fim = float im in
    fun () -> last := (!last * ia + ic) mod im; (float !last) /. fim;;

    let selectRandom () =
      let rec afh r i =
        if r <= arr.(i).p then arr.(i).c else afh r (succ i) in
      afh (gen_random ()) 0 in
      (* Grrrr.... now I have to alt-shift-tab this section back to the right 
         location...*)

  let makeRandomFasta id desc arr n =  
    let rec loop n =
      <...SNIP...>

What happens is that TextMate ignores the blank line after gen_random, and pastes the selectRandom code according to the indentation of the last line of gen_random.


Making matters even worse, if I go and paste something in after selectRandom, it gets indented even further, so I have to do multiple blocks of alt-shift-tabbing to straighten out the code.

  let gen_random =
    let last = ref 42 and im = 139968 and ia = 3877 and ic = 29573 in
    let fim = float im in
    fun () -> last := (!last * ia + ic) mod im; (float !last) /. fim;;

    let selectRandom () =
      let rec afh r i =
        if r <= arr.(i).p then arr.(i).c else afh r (succ i) in
      afh (gen_random ()) 0;;
      (* Not only do I have to move this block in... *)

        let makeCumulative arr =
          ignore (Array.fold_left
            (fun b v -> let cp = (b +. v.p) in v.p <- cp; cp) 0.0 arr);
          arr;;
          (* ...but I have to move this one in twice as far. *)

  let makeRandomFasta id desc arr n =  
    let rec loop n =
      <...SNIP...>

This happens all the time in languages like OCaml, where functions rarely end with the last line unindented, and it is a major pain in the you-know-where...

What would be outstanding is if TextMate offered the option of taking blank lines into account on indented paste so that if a blank line is above the spot you are pasting to, it pastes the code in starting in column 1.

December 22, 2004, at 16:36 UTC by 134.253.26.9 -
Added line 1:

Gimme a sec... I'm still typing this up.