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.

I've been playing with inline evaluation and I've came to the conclusion that it's most convenient to put the Dynamic@ inside the inline cell, so I've started to search for a way to omit typing it altogether. I've tried using CellEvaluationFunction and CellProlog, but with no luck. How can I achieve this?

Also, it would be best if the wrapping with Dynamic[] occurred only in inline cell evaluations (which happen in ordinary text cells)

share|improve this question
    
Well, that seems like a good enough solution. I mean I could do an input alias with a placeholder and set the focus to the placeholder. Why is Dynamic such a bad thing? I mean, beside the irritating information when I open the document it seems to work fine... Different, but related problem is how to evaluate an inline cell without having to select it first (even though I can do it with keyboard) –  Ranza May 8 at 18:21
    
Not a big problem but each Dynamic cell uses part of processor. Is my answer ok? –  Kuba May 8 at 19:46
    
It's perfect, thanks :) You're also right about the CPU, drains the battery waaay faster. –  Ranza May 8 at 21:25

1 Answer 1

up vote 2 down vote accepted

You need to add this piece of code and use it instead of Ctrl+9 for you own inline cell:

Item[KeyEvent["t", Modifiers -> {Control}],
     FrontEndExecute[
        FrontEnd`NotebookWrite[
          FrontEnd`InputNotebook[],
            Cell[ BoxData[ RowBox[{"Dynamic", "[", "\[Placeholder]", "]"}] ], 
                 CellEventActions -> {{"MenuCommand", "HandleShiftReturn"} :> {
                      SelectionMove[EvaluationCell[], All, CellContents];   
                      SelectionEvaluate[EvaluationNotebook[]]}}
                ]
        ];
        FrontEnd`SelectionMove[FrontEnd`InputNotebook[], Previous, Character, 2];
        FrontEnd`SelectionMove[FrontEnd`InputNotebook[], All, Character]
    ]
   ]
  • Now with Ctrl+f, or whatever you want that is free, you will create a cell with Dynamic already written.

  • Also Shift+Enter results in evaluation in place without selecting it.

Edit:

If you want numeric keypad Enter to do this Evaluation In Place you can use {"MenuCommand", "EvaluateCells"} event instead of "HandleShiftReturn". For me it would be great since I hardly ever use Shift+Enter

Ref:

Here is a tutorial how to add a new shortcut: Automating Esc [[ Esc formatting?

Here is a reference link about how to catch Shift+Enter

share|improve this answer
    
Works great, thanks! The only thing is that the focus doesn't move to the placeholder after insertion, but I can live with that. –  Ranza May 8 at 20:25
    
I'm not sure why you've removed the closing bracket - it works the same way with it. It's much better but I still need to make a some keystrokes (move selection to the left and then Tab). Thanks, for helping me out so much! –  Ranza May 8 at 20:32
    
Works flawlessly now! You sir are awesome! –  Ranza May 8 at 22:09
    
@Ranza Great, good luck :) –  Kuba May 8 at 22:11
    
Of course I'm interested! –  Ranza May 9 at 16:23

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.