Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Code folding and wrapping using the input->code method?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104053] Re: Code folding and wrapping using the input->code method?
  • From: telefunkenvf14 <rgorka at gmail.com>
  • Date: Sat, 17 Oct 2009 07:02:35 -0400 (EDT)
  • References: <hb70a0$8rs$1@smc.vnet.net> <hb9k06$ni$1@smc.vnet.net>

On Oct 16, 6:04 am, David Reiss <dbre... at gmail.com> wrote:
> Take a look at the following MathGroup posting of mine that addresses
> this:
>
> http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_...
>
> I also reproduce that posting below....
>
> Best,
>
> Davidhttp://scientificarts.com/worklife
>
> __________________________________________
> Original posting:
> __________________________________________
>
> There are several points to make on this.  The first is that,
> generally you want to create your Mathematica cod within a
> Mathematica notebook (unless you are using Workbench) and then set
> that notebook up so that it's Input Cells or Code cells are
> Initialization cells.  Then the notebook will save them into a
> corresponding .m file when the notebook is saved (a dialog will ask
> you this the first time you save it after you have put initialization
> cells in it).
> As for indentation, Code cells will not (by their stylesheet design)
> auto indent.  The can be changed at the style sheet level.
> As for working with .m files directly.  They do not retain any
> stylsheet information when they are saved.  However styles can be
> imposed on them while they are open.
> Cells with code in .m files make use of the Core.nb stylesheet's Code
> cellstyle.  So if you modify cells of this style in the .m file they
> will take on those modifications for the session that the .m file is
> open.
> If nb is the NotebookObject for the .m file in question then the
> following will make it behave in a way that you are desiring,
> modifying the cells with code in them.  The code comes fromhttp://scien=
tificarts.com/worklifewhere it is used in one of the
> palettes for exactly the purpose you are wanting:  I needed the same
> thing and wrote it into thehttp://scientificarts.com/worklife
> package for just this reason.
> ModifyCodeStyle[nb_NotebookObject, Selection] :=
>   Module[{},
>    NotebookFind[nb, "Code", All, CellStyle, AutoScroll -> False];
>    SetOptions[NotebookSelection[nb],
>     PageWidth -> WindowWidth,
>     AutoIndent -> Automatic,
>     AutoSpacing -> True,
>     LineBreakWithin -> Automatic,
>     LineIndent -> 1,
>     LinebreakAdjustments -> {0.85, 2, 10, 0, 1}]
>    ];
> And here is a different version which acts on the style of Code cells
> rather than on the cells directly:
> ModifyCodeStyle[nb_NotebookObject, Notebook] :=
>    Module[{styledefs, editable},
>     editable = Editable /. Options[nb, Editable];
>     SetOptions[nb, Editable -> True];
>     styledefs = StyleDefinitions /. Options[nb, StyleDefinitions];
>     Switch[Head[styledefs],
>      Notebook,
>      styledefs = Notebook[
>        {
>         First@First[styledefs],
>         Cell[StyleData["Code"],
>          PageWidth -> WindowWidth,
>          AutoIndent -> Automatic,
>          AutoSpacing -> True,
>          LineBreakWithin -> Automatic,
>          LineIndent -> 1,
>          LinebreakAdjustments -> {0.85, 2, 10, 0, 1}],
>         Rest@First[styledefs]
>         },
>        Sequence @@ Rest[List @@ styledefs]
>        ],
>      String | FileName | FrontEnd`FileName,
>      styledefs =
>       Notebook[{Cell[StyleData[StyleDefinitions -> styledefs]],
>         Cell[StyleData["Code"],
>          PageWidth -> WindowWidth,
>          AutoIndent -> Automatic,
>          AutoSpacing -> True,
>          LineBreakWithin -> Automatic,
>          LineIndent -> 1,
>          LinebreakAdjustments -> {0.85, 2, 10, 0, 1}]},
>        StyleDefinitions -> "PrivateStylesheetFormatting.nb"]
>      ];
>     SetOptions[nb, StyleDefinitions -> styledefs];
>     SetOptions[nb, Editable -> editable]
>     ];
> I hope this helps...
> --Davidhttp://scientificarts.com/worklife
> On Aug 21, 4:42 am, Benjamin Hell <h... at exoneon.de> wrote:
>
> >  Hi,
> >  this is a real beginner question for packages in mathematica. When I
> >  view a package (.m) file in mathematica, the mathematica editor does=
n't
> >  show any indentation nor does any automatic line breaks when scaling=
 the
> >  window. So whereas my code can be read quite well in a standard
> >  mathematica notebook, it looks ugly in a package file. Is there any =
way
> >  to setup some viewing options to change that behaviour?
> >  Thanks in advance,
> >  Benjamin
>
> --
> <><><><><><><><><>><><><>><><><>
>     David Reiss, Ph.D;   Scientific Arts, LLC      .
>    http://www.scientificarts.com
> <><><><><><><><><>><><><>><><><>
> This message and any attachments, may contain confidential and/or
> legally privileged information.  If you are not the intended
> recipient of the message by the original sender, please destroy it.
> Message and attachments Copyright (c) 2009, all rights reserved.
>
> On Oct 15, 7:16 am, telefunkenvf14 <rgo... at gmail.com> wrote:
>
>
>
> > Does anyone know how to make Mathematica both fold and wrap code
> > input?
>
> > I really like using the code input option (because it automatically
> > generates an autosave package for you, and I like the way it sets the
> > code off from the rest of your work in a notebook), but the lack of
> > folding and wrapping are driving me NUTS!
>
> > -RG

I'd give you a hug if I could reach ya! Thanks.

I nosed around your website as well and will keep your consultation
services in mind.

Are you interested in developing additional packages? I have some
ideas, mainly related to search and auto-linking/cross-linking and
index generation, and am curious about the economics of working on
such a project. (I'm an economist)

-RG


  • Prev by Date: Re: ChemicalData[], SMILES, EdgeRules
  • Next by Date: Re: Function of list of functions
  • Previous by thread: Re: Code folding and wrapping using the input->code method?
  • Next by thread: Re: Code folding and wrapping using the input->code method?