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.

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

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

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

Cheat sheet Notepad++

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 (and add to clipboard): Ctrl-l
  • Toggle comment lines as mentioned above (one ;, use ;; for comments that should not be activated by accident): Ctrl-q
  • Navigating: Bookmark line with Ctrl-F2 or LMDC left of line, use F2 or Shift-F2 to navigate to bookmarks.

You can do more smart things…

About using Blade

Bricsys developer Torsten Moses improved the LISP development environment BLADE in many aspects. It runs also on Scintilla, just as Notepad++. So if you’re using BricsCAD V19, you may consider using BLADE instead. Even if you code for AutoCAD, you may want to use BricsCAD with BLADE for that purpose, it is simply a way better tool than the autodesk visual Lisp ide. Combined with ACME autoloader you can switch from BricsCAD to AutoCAD and back. Then again, you can simply keep on using npp with this extension for straightforward code writing. Time for a comparison:

Task NPP+CAD_LISP BLADE
Selecting parts including opening and closing parenthesis cursor near ( or ) and Ctrl-Alt-B Ctrl-Shift-R
Selecting parts between parenthesis Ctrl+DLMB ?
Select a complete line, carriage return etc. included TLMB TLMB
Indent Select block and Tab or Shift-Tab Select block and Tab or Shift-Tab
Line duplicate Ctrl+D Alt-O
Line delete Ctrl-L Shift-Del
Commenting Ctrl-Q toggles comment / uncomment Comment Alt-L, Uncomment Alt-N

Short history

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”.

I hope you like it, best regards,

Wiebe van der Worp

Comments? More than welcome!

Notepad++ syntax highlighting for CAD LISP
Scroll to top