Skip to content

Commit

Permalink
Reformatted README
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Alekseyev committed Jan 11, 2012
1 parent 34e7901 commit 3fe377e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 21 deletions.
9 changes: 6 additions & 3 deletions LVAcontext.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@

setPrivate[x_String]:=setPrivate[{x}];
setPrivate[x_Integer]:= setPrivate["Notebook$$" <> ToString[x] <> "`"];
setAutosave[] := setAutosave[True];
setAutosave[True] := SetOptions[EvaluationNotebook[],NotebookAutoSave->True];
setAutosave[False] := SetOptions[EvaluationNotebook[],NotebookAutoSave->False];


SetAttributes[SelfDestruct, HoldAllComplete];
Expand All @@ -67,6 +64,12 @@
writeAndEval[nb,boxExpr];
]


setAutosave[] := setAutosave[True];
setAutosave[True] := SetOptions[EvaluationNotebook[],NotebookAutoSave->True];
setAutosave[False] := SetOptions[EvaluationNotebook[],NotebookAutoSave->False];


(* TODO: make sure context path order is sensible (e.g. wrt system context) when adding
new elements to the path *)
ExposeContexts[list___,OptionsPattern[{UseSaved->False,SaveNotebookContext->False,RestoreSaved->False,Prepend->False}]]:=
Expand Down
60 changes: 42 additions & 18 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ easily access this private context from other notebooks.
To load a package in Mathematica, execute the following in the front end:

: AppendTo[$Path, "/path/to/package/dir"];
: (or AppendTo[$Path, "c:\\path\\to\\package\\dir"] if in Windows)
: Needs["PackageName`"]; (don't forget the backquote)
: Needs["PackageName`"]; (* don't forget the backquote *)

Note: under Windows, the path will involve double backslashes, e.g.

: AppendTo[$Path, "c:\\path\\to\\package\\dir"]


To autoload the package, append the above lines to init.m in
: $UserBaseDirectory/Autoload/Kernel/init.m
e.g. /home/leo/.Mathematica/Autoload/Kernel/init.m
e.g. ~/home/leo/.Mathematica/Autoload/Kernel/init.m~

(To obtain exact location of $UserBaseDirectory, evaluate $UserBaseDirectory
in mma.)

Expand All @@ -39,26 +44,22 @@ e.g. =?setPrivate= in the notebook.

** setPrivate

Usage:

*setPrivate[]*
Usage: =setPrivate[]=

Creates a private context by calling =SetOptions[EvaluationNotebook[],
CellContext -> Notebook]= and replaces the "setPrivate" notebook input string
with the "SetOptions..." command string.

Resultant assigned context can be checked via =$Context= or =$ContextPath=.

*setPrivate["foo`"] or setPrivate[{"foo`","bar`"}]*
Alternative forms: *setPrivate["foo`"] or setPrivate[{"foo`","bar`"}]*

Functions as above, but adds contexts "foo`" or "foo`", "bar`" to the
=$ContextPath=.

** spawnScratch

Usage:

*spawnScratch[]*
Usage: =spawnScratch[]=

Opens a new notebook with a private context, but its =$ContextPath= will
include the context of the invoking notebook (i.e. the notebook where
Expand All @@ -70,19 +71,42 @@ saved.

** setAutosave

Usage:

*setAutosave[]* or *setAutosave[True]*

*setAutosave[False]*
Usage: =setAutosave[]= or =setAutosave[True]=; =setAutosave[False]=

This is a convenience wrapper around
=SetOptions[SelectedNotebook[],NotebookAutoSave->True|False]=.

** ExposeContexts

Usage:

*ExposeContexts[{"foo`","bar`"}]
Usage: =ExposeContexts[{"foo`","bar`"}]=

Appends contexts to =$ContextPath=.

* Fancy autoreplacement hack

In my Mathematica installations, I invoke the above functions by typing
=_private= (which automatically expands to =setPrivate[]=) and =_scratch=
(which automatically expands to =spawnScratch[]=). This is accomplished by
tapping into the InputAutoReplacements mechanism that is ordinarily
responsible for replacing ~->~, ~:>~, etc. with fancy arrows in notebooks.
Below are my notes on how I set it up. Instructions are provided
as is; use them at your own risk, and make sure to back up any system files if you choose
to modify them :)

: Go to Format->Edit Stylesheet
: This will pull up a notebook of sorts. Copy the following Cell[] code:
: Cell[StyleData["StandardForm"],
: InputAutoReplacements->{
: "_private" -> "setPrivate[]","_scratch" -> "spawnScratch[]",
: "->" -> "\[Rule]", ":>" -> "\[RuleDelayed]", "<=" -> "\[LessEqual]", ">=" ->
: "\[GreaterEqual]", "!=" -> "\[NotEqual]", "==" -> "\[Equal]", ParentList}]
:
: Paste the above cell (you can make other additions) into that
: style-editing notebook thing. Click "Install"; choose a filename. That
: name will now show up in the Stylesheets menu. To apply this as a default,
: choose the name of an existing stylesheet (like Default.nb). After
: restart, the autoreplacements will work for all notebooks using that
: stylesheet. (Under linux, should have a file under
: /home/leo/.Mathematica/SystemFiles/FrontEnd/StyleSheets/Default.nb. Check
: that this file is present, correctly named, and has the necessary code if
: problems arise.)

0 comments on commit 3fe377e

Please sign in to comment.