How to execute this code on startup?How to change the default Notebook stylesheetMake cursor stay in input cellHow to execute kernel command from Front End?Simple question about startup optionsIs there a way to hide or toggle the visibility of code?How would I improve this Karaoke machine code?Frontend cursor movement speed depends on the position in large notebook fileAutomatically execute command after saveHow to execute code on FrontEnd quit?How to execute a notebook in backgroundIs it possible to get rid of this information box?Evaluate Initialization cells at startup
Is using 'echo' to display attacker-controlled data on the terminal dangerous?
How long is it safe to leave marker on a Chessex battle map?
C++ logging library
How creative should the DM let an artificer be in terms of what they can build?
Can a human be transformed into a Mind Flayer?
Why did Intel abandon unified CPU cache?
Java Servlet & JSP simple login
Is it okay to have a sequel start immediately after the end of the first book?
How to write a convincing religious myth?
Separate SPI data
empApi with Lightning Web Components?
2019 gold coins to share
Has there been a multiethnic Star Trek character?
Is it possible to have 2 different but equal size real number sets that have the same mean and standard deviation?
The usage of kelvin in formulas
What is the color of artificial intelligence?
I have a problematic assistant manager, but I can't fire him
What is the logic behind charging tax _in the form of money_ for owning property when the property does not produce money?
Why did the World Bank set the global poverty line at $1.90?
Can I utilise a baking stone to make crepes?
Do you have to have figures when playing D&D?
Why am I getting a strange double quote (“) in Open Office instead of the ordinary one (")?
Who voices the small round football sized demon in Good Omens?
Can we completely replace inheritance using strategy pattern and dependency injection?
How to execute this code on startup?
How to change the default Notebook stylesheetMake cursor stay in input cellHow to execute kernel command from Front End?Simple question about startup optionsIs there a way to hide or toggle the visibility of code?How would I improve this Karaoke machine code?Frontend cursor movement speed depends on the position in large notebook fileAutomatically execute command after saveHow to execute code on FrontEnd quit?How to execute a notebook in backgroundIs it possible to get rid of this information box?Evaluate Initialization cells at startup
$begingroup$
Every time I open a new notebook I have to manually evaluate this code in that notebook. In order order to stop my cursor moving to a new cell.
How would I automate this?
I would love this functionality to auto-load on startup.
I have tried putting it in a file.m
file and adding a Get["/path/to/file.m"]
line, to my FileNameJoin[$UserBaseDirectory , "Kernel", "init.m"]
. Unfortunately this does not work. As it seems to need to be evaluated in the SelectedNotebook[]
to work.
Here is the code by @Kuba
With[
nb := EvaluationNotebook[]
, c := EvaluationCell[]
, With[
cv := CurrentValue[nb, "TaggingRules", "LastCursorPosition"]
, pos := FrontEndExecute@FrontEnd`UndocumentedGetSelectionPacket[nb]
, With[
savePosition := (
cv = If[MemberQ[pos, "CharacterRange" -> _], Last["CharacterRange" /. pos], False]
)
, SetOptions[nb
, CellEventActions :>
"MenuCommand", "HandleShiftReturn" :> savePosition
, "MenuCommand", "EvaluateCells" :> savePosition
, PassEventsDown -> True
, CellEpilog :> If[
IntegerQ[cv]
, SelectionMove[c, Before, CellContents]
; SelectionMove[nb, Next, Character, cv]
; cv = False
]
]
]
]
]
front-end notebooks interface
$endgroup$
add a comment |
$begingroup$
Every time I open a new notebook I have to manually evaluate this code in that notebook. In order order to stop my cursor moving to a new cell.
How would I automate this?
I would love this functionality to auto-load on startup.
I have tried putting it in a file.m
file and adding a Get["/path/to/file.m"]
line, to my FileNameJoin[$UserBaseDirectory , "Kernel", "init.m"]
. Unfortunately this does not work. As it seems to need to be evaluated in the SelectedNotebook[]
to work.
Here is the code by @Kuba
With[
nb := EvaluationNotebook[]
, c := EvaluationCell[]
, With[
cv := CurrentValue[nb, "TaggingRules", "LastCursorPosition"]
, pos := FrontEndExecute@FrontEnd`UndocumentedGetSelectionPacket[nb]
, With[
savePosition := (
cv = If[MemberQ[pos, "CharacterRange" -> _], Last["CharacterRange" /. pos], False]
)
, SetOptions[nb
, CellEventActions :>
"MenuCommand", "HandleShiftReturn" :> savePosition
, "MenuCommand", "EvaluateCells" :> savePosition
, PassEventsDown -> True
, CellEpilog :> If[
IntegerQ[cv]
, SelectionMove[c, Before, CellContents]
; SelectionMove[nb, Next, Character, cv]
; cv = False
]
]
]
]
]
front-end notebooks interface
$endgroup$
add a comment |
$begingroup$
Every time I open a new notebook I have to manually evaluate this code in that notebook. In order order to stop my cursor moving to a new cell.
How would I automate this?
I would love this functionality to auto-load on startup.
I have tried putting it in a file.m
file and adding a Get["/path/to/file.m"]
line, to my FileNameJoin[$UserBaseDirectory , "Kernel", "init.m"]
. Unfortunately this does not work. As it seems to need to be evaluated in the SelectedNotebook[]
to work.
Here is the code by @Kuba
With[
nb := EvaluationNotebook[]
, c := EvaluationCell[]
, With[
cv := CurrentValue[nb, "TaggingRules", "LastCursorPosition"]
, pos := FrontEndExecute@FrontEnd`UndocumentedGetSelectionPacket[nb]
, With[
savePosition := (
cv = If[MemberQ[pos, "CharacterRange" -> _], Last["CharacterRange" /. pos], False]
)
, SetOptions[nb
, CellEventActions :>
"MenuCommand", "HandleShiftReturn" :> savePosition
, "MenuCommand", "EvaluateCells" :> savePosition
, PassEventsDown -> True
, CellEpilog :> If[
IntegerQ[cv]
, SelectionMove[c, Before, CellContents]
; SelectionMove[nb, Next, Character, cv]
; cv = False
]
]
]
]
]
front-end notebooks interface
$endgroup$
Every time I open a new notebook I have to manually evaluate this code in that notebook. In order order to stop my cursor moving to a new cell.
How would I automate this?
I would love this functionality to auto-load on startup.
I have tried putting it in a file.m
file and adding a Get["/path/to/file.m"]
line, to my FileNameJoin[$UserBaseDirectory , "Kernel", "init.m"]
. Unfortunately this does not work. As it seems to need to be evaluated in the SelectedNotebook[]
to work.
Here is the code by @Kuba
With[
nb := EvaluationNotebook[]
, c := EvaluationCell[]
, With[
cv := CurrentValue[nb, "TaggingRules", "LastCursorPosition"]
, pos := FrontEndExecute@FrontEnd`UndocumentedGetSelectionPacket[nb]
, With[
savePosition := (
cv = If[MemberQ[pos, "CharacterRange" -> _], Last["CharacterRange" /. pos], False]
)
, SetOptions[nb
, CellEventActions :>
"MenuCommand", "HandleShiftReturn" :> savePosition
, "MenuCommand", "EvaluateCells" :> savePosition
, PassEventsDown -> True
, CellEpilog :> If[
IntegerQ[cv]
, SelectionMove[c, Before, CellContents]
; SelectionMove[nb, Next, Character, cv]
; cv = False
]
]
]
]
]
front-end notebooks interface
front-end notebooks interface
asked May 25 at 12:50
Conor CosnettConor Cosnett
3,3871031
3,3871031
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Here's a stylesheet version that mimics Kuba's code:
With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
SetOptions[EvaluationNotebook[],
StyleDefinitions -> Notebook[
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[StyleData["Input"],
CellEventActions ->
"MenuCommand","HandleShiftReturn" :> Set[
cv,
Replace[
Lookup[
Developer`CellInformation @ EvaluationCell[],
"CursorPosition"
],
_, i_ -> i,
_ -> False
]
],
PassEventsDown->True
,
CellEpilog :> Replace[cv,
i_Integer :> (
SelectionMove[EvaluationCell[], Before, CellContents];
SelectionMove[EvaluationNotebook[], Next, Character, i];
cv = False
)
],
TaggingRules ->
]
,
StyleDefinitions->"PrivateStylesheetFormatting.nb"
]
]
]
You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.
$endgroup$
$begingroup$
Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet fromDefault.nb
toDefaultModified.nb
. I am confused. Where do I put your code? Do I paste it somewhere insideDefaultModified.nb
?
$endgroup$
– Conor Cosnett
May 26 at 14:11
2
$begingroup$
@ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
$endgroup$
– Carl Woll
May 27 at 5:09
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199085%2fhow-to-execute-this-code-on-startup%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Here's a stylesheet version that mimics Kuba's code:
With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
SetOptions[EvaluationNotebook[],
StyleDefinitions -> Notebook[
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[StyleData["Input"],
CellEventActions ->
"MenuCommand","HandleShiftReturn" :> Set[
cv,
Replace[
Lookup[
Developer`CellInformation @ EvaluationCell[],
"CursorPosition"
],
_, i_ -> i,
_ -> False
]
],
PassEventsDown->True
,
CellEpilog :> Replace[cv,
i_Integer :> (
SelectionMove[EvaluationCell[], Before, CellContents];
SelectionMove[EvaluationNotebook[], Next, Character, i];
cv = False
)
],
TaggingRules ->
]
,
StyleDefinitions->"PrivateStylesheetFormatting.nb"
]
]
]
You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.
$endgroup$
$begingroup$
Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet fromDefault.nb
toDefaultModified.nb
. I am confused. Where do I put your code? Do I paste it somewhere insideDefaultModified.nb
?
$endgroup$
– Conor Cosnett
May 26 at 14:11
2
$begingroup$
@ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
$endgroup$
– Carl Woll
May 27 at 5:09
add a comment |
$begingroup$
Here's a stylesheet version that mimics Kuba's code:
With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
SetOptions[EvaluationNotebook[],
StyleDefinitions -> Notebook[
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[StyleData["Input"],
CellEventActions ->
"MenuCommand","HandleShiftReturn" :> Set[
cv,
Replace[
Lookup[
Developer`CellInformation @ EvaluationCell[],
"CursorPosition"
],
_, i_ -> i,
_ -> False
]
],
PassEventsDown->True
,
CellEpilog :> Replace[cv,
i_Integer :> (
SelectionMove[EvaluationCell[], Before, CellContents];
SelectionMove[EvaluationNotebook[], Next, Character, i];
cv = False
)
],
TaggingRules ->
]
,
StyleDefinitions->"PrivateStylesheetFormatting.nb"
]
]
]
You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.
$endgroup$
$begingroup$
Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet fromDefault.nb
toDefaultModified.nb
. I am confused. Where do I put your code? Do I paste it somewhere insideDefaultModified.nb
?
$endgroup$
– Conor Cosnett
May 26 at 14:11
2
$begingroup$
@ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
$endgroup$
– Carl Woll
May 27 at 5:09
add a comment |
$begingroup$
Here's a stylesheet version that mimics Kuba's code:
With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
SetOptions[EvaluationNotebook[],
StyleDefinitions -> Notebook[
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[StyleData["Input"],
CellEventActions ->
"MenuCommand","HandleShiftReturn" :> Set[
cv,
Replace[
Lookup[
Developer`CellInformation @ EvaluationCell[],
"CursorPosition"
],
_, i_ -> i,
_ -> False
]
],
PassEventsDown->True
,
CellEpilog :> Replace[cv,
i_Integer :> (
SelectionMove[EvaluationCell[], Before, CellContents];
SelectionMove[EvaluationNotebook[], Next, Character, i];
cv = False
)
],
TaggingRules ->
]
,
StyleDefinitions->"PrivateStylesheetFormatting.nb"
]
]
]
You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.
$endgroup$
Here's a stylesheet version that mimics Kuba's code:
With[cv := CurrentValue[EvaluationCell[], TaggingRules, "LastCursorPosition"],
SetOptions[EvaluationNotebook[],
StyleDefinitions -> Notebook[
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[StyleData["Input"],
CellEventActions ->
"MenuCommand","HandleShiftReturn" :> Set[
cv,
Replace[
Lookup[
Developer`CellInformation @ EvaluationCell[],
"CursorPosition"
],
_, i_ -> i,
_ -> False
]
],
PassEventsDown->True
,
CellEpilog :> Replace[cv,
i_Integer :> (
SelectionMove[EvaluationCell[], Before, CellContents];
SelectionMove[EvaluationNotebook[], Next, Character, i];
cv = False
)
],
TaggingRules ->
]
,
StyleDefinitions->"PrivateStylesheetFormatting.nb"
]
]
]
You can modify the default stylesheet to use for new notebooks, see the answers to How to change the default Notebook stylesheet.
edited May 25 at 14:00
answered May 25 at 13:55
Carl WollCarl Woll
83k3105216
83k3105216
$begingroup$
Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet fromDefault.nb
toDefaultModified.nb
. I am confused. Where do I put your code? Do I paste it somewhere insideDefaultModified.nb
?
$endgroup$
– Conor Cosnett
May 26 at 14:11
2
$begingroup$
@ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
$endgroup$
– Carl Woll
May 27 at 5:09
add a comment |
$begingroup$
Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet fromDefault.nb
toDefaultModified.nb
. I am confused. Where do I put your code? Do I paste it somewhere insideDefaultModified.nb
?
$endgroup$
– Conor Cosnett
May 26 at 14:11
2
$begingroup$
@ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
$endgroup$
– Carl Woll
May 27 at 5:09
$begingroup$
Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet from
Default.nb
to DefaultModified.nb
. I am confused. Where do I put your code? Do I paste it somewhere inside DefaultModified.nb
?$endgroup$
– Conor Cosnett
May 26 at 14:11
$begingroup$
Thanks for your answer. I followed the link and I have successfully changed my default notebook stylesheet from
Default.nb
to DefaultModified.nb
. I am confused. Where do I put your code? Do I paste it somewhere inside DefaultModified.nb
?$endgroup$
– Conor Cosnett
May 26 at 14:11
2
2
$begingroup$
@ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
$endgroup$
– Carl Woll
May 27 at 5:09
$begingroup$
@ConorCosnett If you have a stylesheet that you want to modify to include the above styles, you can open a new notebook and run the above code in the notebook. Then, edit the notebook stylesheet, copy the "Input" style, and paste it into the stylesheet you want to modify.
$endgroup$
– Carl Woll
May 27 at 5:09
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199085%2fhow-to-execute-this-code-on-startup%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown