Initial implementation of an emacs mode for scad files.

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Initial implementation of an emacs mode for scad files.

Len Trigg
Hey all,

I had a quick lash at writing an emacs major mode for openscad files.
It supports font locking and managing indentation etc. I haven't
written a major mode before, so suggestions (and even better patches)
are welcome.

Cheers,
Len.

scad.el (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Initial implementation of an emacs mode for scad files.

kintel
Administrator
On Mar 31, 2010, at 11:58 AM, Len Trigg wrote:

> I had a quick lash at writing an emacs major mode for openscad files.
> It supports font locking and managing indentation etc. I haven't
> written a major mode before, so suggestions (and even better patches)
> are welcome.
>

I've been using the C++ mode so far, but this looks like a possible improvement!
A few comments/wishes:
o Make indentation indent one extra level if the previous line didn't end with a semicolon.
o Note that it's a difference between functions and modules in scad. Not sure if they need to be indented differently though.

FYI: These are lists of built-in functions and modules in OpensCAD:

functions:
"dxf_dim" "dxf_cross" "abs" "min" "max" "sin" "cos" "asin" "acos" "tan" "atan" "atan2" "round" "ceil" "floor" "pow" "sqrt" "exp" "log" "ln" "str" "lookup"

modules:
"minkowski" "glide" "subdiv" "child" "echo" "assign" "for" "intersection_for" "if" "union" "difference" "intersection" "dxf_linear_extrude" "linear_extrude" "dxf_rotate_extrude" "rotate_extrude" "import_stl" "import_off" "import_dxf" "group" "cube" "sphere" "cylinder" "polyhedron" "square" "circle" "polygon" "projection" "render" "surface" "scale" "rotate" "mirror" "translate" "multmatrix" "color"


I can add this to a contrib section in subversion once you're ready.

Keep up the good work :)

~/= Marius

--
We are Elektropeople for a better living.





Reply | Threaded
Open this post in threaded view
|

Re: Initial implementation of an emacs mode for scad files.

Len Trigg
Marius Kintel wrote:
> I've been using the C++ mode so far, but this looks like a possible improvement!

I wasn't sure if I should make my mode derive from cc-mode - it looked trickier.


> A few comments/wishes:
> o Make indentation indent one extra level if the previous line didn't end with a semicolon.

Will look into it.


> o Note that it's a difference between functions and modules in scad. Not sure if they need to be indented differently though.
>
> FYI: These are lists of built-in functions and modules in OpensCAD:

Cool, I'll update it to reflect that distinction (I don't think it was
really apparent when I was reading the user manual).


Cheers,
Len.

Reply | Threaded
Open this post in threaded view
|

Re: Initial implementation of an emacs mode for scad files.

kintel
Administrator
On Apr 1, 2010, at 05:49 AM, Len Trigg wrote:

> Cool, I'll update it to reflect that distinction (I don't think it was
> really apparent when I was reading the user manual).
>

The user manual is kind of a community effort - sadly, it's one of the tasks that never manage to make it to the top of the list whenever we get some time for OpenSCAD hacking..
Any help updating or improving the manual is very much appreciated! ..and I'd be happy to help/guide anyone working on it to understanding how stuff really works.

~/= Marius

--
We are Elektropeople for a better living.





Reply | Threaded
Open this post in threaded view
|

Re: Initial implementation of an emacs mode for scad files.

Giles Bathgate
On 01/04/2010 13:30, Marius Kintel wrote:
>
> The user manual is kind of a community effort - sadly, it's one of the tasks that never manage to make it to the top of the list whenever we get some time for OpenSCAD hacking..
> Any help updating or improving the manual is very much appreciated! ..and I'd be happy to help/guide anyone working on it to understanding how stuff really works.
>
>    

While on that topic I made a change to this page
http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Modules some time ago,
regarding the $children variable the page has never been "sighted" so
the change remains as a draft.

To be honest the wikibook manual...its good and all, but have you
considered using asciidoc, thats what all the cool kids are doing (git
documenation for example) it has backends to generate man pages, aswell
as nicely formatted html.

Regards

Giles.

Reply | Threaded
Open this post in threaded view
|

Re: Initial implementation of an emacs mode for scad files.

kintel
Administrator
On Apr 1, 2010, at 14:36 PM, Giles Bathgate wrote:

> While on that topic I made a change to this page [...]
> [...] but have you considered using asciidoc

Actually, the wikibooks manual is not maintained by the OpenSCAD developers at all. It was started and is maintained by Someone Else.
I applaud the initiative to write a manual, and personally I have no wishes or plans to challenge any of the choices being made as long as someone voluntarily actually writes documentation :)

~/= Marius

--
We are Elektropeople for a better living.





Reply | Threaded
Open this post in threaded view
|

Re: Initial implementation of an emacs mode for scad files.

Len Trigg
In reply to this post by kintel
Here is an updated version that uses your full list of functions and
modules. It also uses a different face for highlighting functions vs
modules.  I haven't yet had a look at adding extra indentation when
the previous line didn't end with a semicolon.  You can add it to svn
as an initial version if you want.


Cheers,
Len.


On Thu, Apr 1, 2010 at 1:47 AM, Marius Kintel <[hidden email]> wrote:

> On Mar 31, 2010, at 11:58 AM, Len Trigg wrote:
>
>> I had a quick lash at writing an emacs major mode for openscad files.
>> It supports font locking and managing indentation etc. I haven't
>> written a major mode before, so suggestions (and even better patches)
>> are welcome.
>>
>
> I've been using the C++ mode so far, but this looks like a possible improvement!
> A few comments/wishes:
> o Make indentation indent one extra level if the previous line didn't end with a semicolon.
> o Note that it's a difference between functions and modules in scad. Not sure if they need to be indented differently though.
>
> FYI: These are lists of built-in functions and modules in OpensCAD:
>
> functions:
> "dxf_dim" "dxf_cross" "abs" "min" "max" "sin" "cos" "asin" "acos" "tan" "atan" "atan2" "round" "ceil" "floor" "pow" "sqrt" "exp" "log" "ln" "str" "lookup"
>
> modules:
> "minkowski" "glide" "subdiv" "child" "echo" "assign" "for" "intersection_for" "if" "union" "difference" "intersection" "dxf_linear_extrude" "linear_extrude" "dxf_rotate_extrude" "rotate_extrude" "import_stl" "import_off" "import_dxf" "group" "cube" "sphere" "cylinder" "polyhedron" "square" "circle" "polygon" "projection" "render" "surface" "scale" "rotate" "mirror" "translate" "multmatrix" "color"
>
>
> I can add this to a contrib section in subversion once you're ready.
>
> Keep up the good work :)
>
> ~/= Marius
>
> --
> We are Elektropeople for a better living.
>
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>

scad.el (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Initial implementation of an emacs mode for scad files.

EdEarl
I downloaded scad.el and it works well, tyvm.

Emacs can start and communicate with servers, which means integrating Emacs with OpenSCAD on Linux should be simple. I believe A server can be a command line program with data and commands piped into it; although, I'm not a Linux guru. The Emacs manual describes how to do it, and it tells how to do similar things on Windows (via API) and Mac .

I notices in another thread there was consideration of making a front end for OpenSCAD so that it has another language to do some things that it cannot. Emacs is programmed by Lisp, which is extremely powerful, and Emacs is a superb (albeit different) editor. IMO marrying Emacs and OpenSCAD would provide an exceptional tool.  

The main disadvantages of Emacs are its jargon, which predates Windows by about ten years, and its unusual editing keys. Although, Emacs does provide ctrl-c, ctrl-x and ctrl-v compatibility, it uses ctrl-s for search instead of ctrl-f for find, and many other unusual keys. Thus, many people find it strange and do not want to learn it.

On the other hand, Emacs has no equal. I was a programmer for over 30 years, and used Emacs for much of that time, and it gave me a significant advantage over those who used other editors. Being able to code Lisp functions and subsystems to do complex edits can be very beneficial. For example, it would be possible to add syntax checking to the SCAD mode (scad.el) that detects misspelled variable, function, and module names, among other things.

Lisp is also a decent language for writing AI; thus, someone might write smart front ends for SCAD programs for various purposes, for example a program to process several pictures taken from different angles into a 3D SCAD program.

These things can be done without marrying Emacs with SCAD via a client-server connection, but it would make the process easier and a bit faster.

A less ambitious approach is to write a make script that will launch OpenSCAD command line and render drawings.