Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there a way to configure Mathematica so that the code does not move around while one is typing? It is driving me crazy and I can't see what I am typing as the code is being reformatted while typing.

This is standard notebook, V10. Here is a small animation to show the problem. This happens while I am changing some code, where I see other lines are moving based on what I type in a different line. This below is just an example. This happens in many other cases.

I once tried a code cell, but that caused many other problems, so I do not use Code cell anymore.

Is there a setting or some solution to prevent this? I am on windows 7.

enter image description here

Here is the actual code snippet above if needed.

SetDirectory[NotebookDirectory[]];
Do[
 fileName = "ode" <> ToString[i] <> ".tex";
 DeleteFile[fileName];
 PutAppend[TeXForm[ode[[i]]], fileName];
 res = DSolve[ode[[i]] == 0, y[x], x];
 PutAppend[TeXForm[res], fileName];
 , {i, 10}]
share|improve this question
    
@LeonidShifrin Yes, as I mentioned that is a solution, but there are other problems with using Code Cells. For example, not allowed in a Demonstration style sheet. I also remember other issues with it, but can't remember exactly now what they are, I just know I had another problem using code cells. Thanks. –  Nasser Jul 14 at 1:39
    
Ok, sorry, I didn't notice that you mentioned that. –  Leonid Shifrin Jul 14 at 1:42
1  
If you like how code cells work, you can turn the autoindenting off for Input cells –  Rojo Jul 16 at 15:58

1 Answer 1

up vote 4 down vote accepted

If you want Mathematica to indent your code, then there is no complete way around it. You can of course turn indentation completely off and then there would be not shuffling anymore, but the automatic indentation is generally a good thing and you should not consider this way.

There is something you can do to minimize this shuffling, but you have to change the way you type code. This is btw a good thing, because you will be faster and you will make less errors. Assume you want to erase the PutAppend expression and then, you want to type it again.

enter image description here

Why doesn't my code jiggle at all? Because I don't wildly erase stuff. I mark the expression I want to erase by expanding the selection with Ctrl+.. If you delete code this way, you don't erase closing ] which confuses the indenter because it thinks the rest of the code is now in another scope.

Secondly, use Alt+] to insert a pair of [] (or Ctrl+Shift+}). Your braces need to be paired anyway and as long as you don't need to surround an expression by braces, you can always insert both at the same time. Again, by inserting paired braces, you keep the rest of your code consistent and the indenter won't touch it.

Final note: The shortcut for Check Balance plays in the same league as Extend Selection, only that it always extends the selection to the next level of matching braces. Try it out. Place the cursor anywhere inside your code and use Ctrl+Shift+B.

share|improve this answer
    
Thanks, but as I said this was an example, where I was copying and adding a large expression. I know that what you are showing are rules of thumbs to remember and follow to reduce this shuffling problem. Do you know of a more fundamental solution to allow one to code as they want and not have the code move around? Something like with Code cell but in a standard Input cell? I also need now to try Code Cell to see if it works with CDF's. I never tried that. Thanks for your hints –  Nasser Jul 14 at 2:35
    
The problem is, that the indenter cannot be adjusted this way. Maybe turning it off completely is really an option for you, but then you have to do all the linebreaks and indents by yourself. Otherwise you will have you code aligned at the left margin. –  halirutan Jul 14 at 2:46
    
+10 for the Alt+] alone –  seismatica Jul 14 at 6:00
    
How do you deal with comments. Is there a shortcut for (* *) , you created one, or you just live with it (like I've been doing)? –  Rojo Jul 16 at 16:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.