Notepad++ syntax highlighting for CAD LISP

Notepad++, abbreviated npp, has a LISP template built-in. But LISP for CAD is quite different from LISP for “plain” programming.

Several templates for CAD circulate on the net, none made me 100% happy. So, after starting npp, it was time to choose “Language” -> “Define User Language”. It did not take much time to make something and I’m happy with it. This is the result:

I would like to share the XML file. You can download it and I hope it helps you. I also hope that some feedback can improve the file. See below.

But that is not all, a discussion here https://forum.bricsys.com/discussion/comment/33907 did lead to another version with all (!) commands build in. Special thanks to Torsten Moses for his contribution (and CADbloke for inspiring). Torsten’s extensive function list for UltraEdit was included.

If you use UltraEdit, visit https://www.bricsys.com/bricscad/help/en_US/CurVer/DevRef/index.html and choose “LISP” > “Support for UltraEdit Editor”.

Anyway, the result is a second download below and despite its size, you probably prefer this one.

Assumptions

A long program must be readable. Therefore, all comments have a light background colour. Just get used to it and notice that it works well. Toggle for comments: Ctrl-q. Because functions like (princ “information”) contribute to the readability of a program, strings have also a light background.

An exhibition of colours does not contribute to proper readability. On the other hand: differences between functions, variables and texts must be clear enough.

“Lost In Stupid Parenthesis”: Parenthesis should be very clear. Everyone forgets one now and then, but it should be very easy to find the ones that do not match. They are notably visible. Highlighting works well in npp and parenthesis turn red when the cursor is next to it. Ctrl-b and or Ctrl+DLMB to select a block is also very helpful.

LISP as used in BricsCAD is extremely compatible with AutoCAD. However, at Bricsys they are doing product development. So they have commands that do not work in AutoCAD. Those functions have the same colour but are – as a warning – italic. At Bricsys they try to solve that problem with “VLE functions”. These are native and fast functions in BricsCAD and Bricsys offers a variant in LISP written for AutoCAD. You can even distribute these functions with your app for AutoCAD. They are a bit slower then but that is in line with recent AutoCAD versions.

The function list was based on the AutoCAD function list for OS-X. But if you have an Apple and want to run CAD software and think about it, you’ll skip Autodesk and go to Bricsys. So I changed the function list and took AutoCAD 2016 as a base and added the BricsCAD V17 extra functions. All in all, this xml code now covers thousands of functions.

 

Installation and use

  • ¬†Installing Notepad++:
  • Configuring:
    • General for CAD LISP:
      • Check word delimiters in “Settings” > “Preferences” > “Delimiter
        • At “Add your character…“, add these characters without (!) space:
          -_:* (In LISP you use these characters in variables, just DLMB on a var, see this post: http://nedcad.nl/en/lisp-and-variables/ )
        • While there, “Delimiter Selection Settings“:
          • Open“: (
          • Close“: )
          • Select “Allow on several lines“.
    • Get your CAD_LISP language package from this page.
      • Choose from the menu “Language” and “Define your language“.
        • Click on “Create New …” button and give the definition a name, for example “CAD_LISP“.
        • Now click on “Import …” and select the xml file.

Files for download

  • This is the simple light weight xml file for Notepad++: NedCAD_LISP.xml
  • You’ll probably prefer this file, containing all functions: CAD_LISP.xml

Example

Why all the work to put thousands of functions in this language file? A real world example gives a clue:

In a complex LISP file (many hundreds of lines) , some functions are defined: “primer”, “position”, “shapes”, and “varset”. They are called in a sequence:

In AutoCAD you will not notice anything. However, BricsCAD has a more modern and richer LISP environment and “position” is an internal function that is lacking in AutoCAD. Since functions are red and differing functions are in italics, you see a problem arise. Ask yourself, hoe would it be if all functions would appear similar? Exactly, crashes and seeking needles in haystacks.

Bonus

Some things to remember. You have a powerful editor configured, giving you the possibility to drive your efficiency to new heights. Take advantage of that:

  • Mark your code as CAD_LISP: Menu > Language > CAD_LISP
  • Selecting:
    • Parts including opening and closing parenthesis: put cursor right before or after ( or ) and Ctrl-Alt-b.
    • Parts between parenthesis: Ctrl+DLMB (double-click left mouse button).
    • A complete line, carriage return etc. included (for Ctrl-x, Del, …): TLMB (triple-click left mouse button).
  • Indent: Select block and Tab or Shift-Tab.
    • So aligning is a few times Shift-Tab and then¬†Tab if needed.
  • Find and Replace with regex turned on:
    • Find something at start of line: ^Find Me or ^.FirstCharacter.
    • End of line: Find Me$.
    • End of lines -> Space: \r\n -> LiteralSpace
  • Remove empty lines: “Edit” > “Line operations” > …
  • Duplicate line: Ctrl-d
  • Delete lines: Ctrl-l
  • Comment lines as mentioned above: Ctrl-q

You can do more smart things…

I hope you like it, best regards,

Wiebe van der Worp

Comments? More than welcome!

Some additional comments:

  • quoted parts were green. For something like '(a,b) that is fine. However, when using function '(lambda () ...), a large range of parenthesis could be excluded from bracket matching. So this item has been disabled.