2

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)

Kuba
  • 136,707
  • 13
  • 279
  • 740
Ranza
  • 1,205
  • 9
  • 22
  • 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 08 '14 at 18:21
  • Not a big problem but each Dynamic cell uses part of processor. Is my answer ok? – Kuba May 08 '14 at 19:46
  • It's perfect, thanks :) You're also right about the CPU, drains the battery waaay faster. – Ranza May 08 '14 at 21:25

1 Answers1

4

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

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • 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 08 '14 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 08 '14 at 20:32
  • Works flawlessly now! You sir are awesome! – Ranza May 08 '14 at 22:09
  • @Ranza Great, good luck :) – Kuba May 08 '14 at 22:11
  • Of course I'm interested! – Ranza May 09 '14 at 16:23
  • @Ranza So, it's in the Edit:) I'm not sure if I pointed it well. Tell me if this works for you. – Kuba May 10 '14 at 07:50
  • Can't really test it cause currently on the laptop, but it's nice to know that it's possible! thanks. – Ranza May 10 '14 at 19:48
  • It looks like selection of inline cell with SelectionMove[EvaluationCell[], All, CellContents]; is broken in MMA10 – Ranza Jul 22 '14 at 12:26
  • @Ranza I;ve just installed v10 and this command works so far, are you sure it is about this line? I have not tested whole code in v10 yet. – Kuba Jul 22 '14 at 15:33
  • It seems to select the parent cell as well as the inline cell on my machine, I've tried using Expression and Word parameters, but although it selected it properly it didn't evaluate them the way it should; converting Dynamic[x] expression to Dynamic[x] string. – Ranza Jul 22 '14 at 17:51
  • @Ranza I will take a closer look tomorrow, sorry for the delay. – Kuba Jul 22 '14 at 22:04