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 access (or even set) the cursor position in a Notebook?

(By Cursor I refer to the keyboard input postion, or "Insertion Point". For the Mouse we have CurrentValue["MousePosition"] or just MousePosition[])

Note that calling external tools is only the seconds best option for me. See Programmatically move the cursor to a desired location on the screen (which is also about the mouse)

share|improve this question
    
One thing that makes this question difficult to answer is lack of specification of the expected position datum -- should it be X number of Cells into the Notebook, or a certain number of characters into the expression returned by NotebookGet, or...? –  Mr.Wizard Oct 18 '12 at 9:37
    
You are right. I'm sure MMA has such a specification internally, but maybe it cannot be accessed!? So I was refering to that -unknown- internal spec. –  NoEscape Oct 18 '12 at 10:02
    
Fair enough. Let me ask the question in a different way: what would you do with this internal spec if you had it? There is apparently no way to feed it to SelectionMove. What kind of interaction are you envisioning? –  Mr.Wizard Oct 18 '12 at 10:04
    
The simplest application is just saving the insertion point and setting it back later! –  NoEscape Oct 18 '12 at 10:06
    
That's just the problem though; I don't know if any way to say "move cursor to point X" but only "move cursor X units of type Y in direction Z." Perhaps you could use some marker and then do a text search for that. I don't think there are many tools provided for this kind of thing; it's typically much easier to work with the Notebook expression than with the GUI Notebook itself. –  Mr.Wizard Oct 18 '12 at 10:17

1 Answer 1

Setting the position may be easier than retrieving it as there exists SelectionMove.

No record of the insertion point appears in the output of NotebookGet. At the moment the best I can think of is to use NotebookWrite to insert a unique token and then search the expression returned by NotebookGet for this token, but this changes the target Notebook.

Perhaps if you described your application I would be able to provide other suggestions.

share|improve this answer
    
unique token... VERY good point! –  NoEscape Oct 18 '12 at 9:51
    
Aha, from experimenting with SelectionMove I come to the conclusion that a "Selection" can also be empty and then just represents the Insertion point. This is not at all evident from the naming of that function! (this happens e.g. on SelectionMove[nb, Next, Character] –  NoEscape Oct 18 '12 at 10:11
    
@NoEscape, sorry, I guess should have said that in my answer. –  Mr.Wizard Oct 18 '12 at 10:12
3  
With Developer`CellInformation you get the cursor position within the selected cell, and the selected cell serial number whatever that means –  Rojo Oct 18 '12 at 23:35

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.