TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: nobody on November 03, 2017, 02:44:25 PM

Title: Is there software way to refactor autolisp routine?
Post by: nobody on November 03, 2017, 02:44:25 PM
Is there a way to rename lisp variables / functions through entire files easily?
Title: Re: Is there software way to refactor autolisp routine?
Post by: BIGAL on November 03, 2017, 06:49:07 PM
Its called Replace  :2funny:

You could write a lisp that looks for "setq" in a line, then "setq variable" and change the variable name, only problem is code with (setq a 1 b 2) when using wcmatch it gives a starting point so step across the string till the next space after the variable. change the variable name and rewrite the line. It is doable needs a lambda function for the replace bit. Need to think about it a bit more.

In my case I want to add AH- to variable names to make them individual its a bit easier than changing the whole name. Oh yeah need to check the starting (defun statement also ( / pt1 pt2 ) etc



Title: Re: Is there software way to refactor autolisp routine?
Post by: JohnK on November 03, 2017, 08:11:10 PM
Use a good text editor. Any good editor should support regex.
Title: Re: Is there software way to refactor autolisp routine?
Post by: CAB on November 03, 2017, 08:16:39 PM
I think it can be a bit tricky just doing a replace across multiple list files.
Some variables share letters that may be replaced.
Setq can have many variables  (setq a 2 b5 c 8)
Title: Re: Is there software way to refactor autolisp routine?
Post by: BIGAL on November 03, 2017, 10:17:04 PM
Like you Cab as you run it would ask old variable new variable name making a list which will grow its a bit of a task. Using a macro in word may be easier looking for a number of predefined variable names. I use stuff like pt pt1 all the time but the names could be a bit trickier. layname layername lname etc all the same depending on what I feel like when typing. It may need a 1st pass get all variable names make a list with pairs old new then second pass actually change them. Obviously making a new file.

Title: Re: Is there software way to refactor autolisp routine?
Post by: nobody on November 03, 2017, 11:22:38 PM
Thanks guys, looks like I'll need to just grind through.  Appreciate it!
Title: Re: Is there software way to refactor autolisp routine?
Post by: BIGAL on November 04, 2017, 07:58:56 PM
Yeah no quick solution just me though I stay away from *acad* as variable names always get worried about using characters like *.

I know that commercially I would add a prefix to all my defuns.

Making c:now can be a risk if someone else uses now, so usually make my defun naming a bit obscure c:ahfindints
Title: Re: Is there software way to refactor autolisp routine?
Post by: Biscuits on November 06, 2017, 04:36:27 PM
Look into "TextCrawler".
Title: Re: Is there software way to refactor autolisp routine?
Post by: nobody on November 07, 2017, 03:36:25 AM
Look into "TextCrawler".

Thanks!
Title: Re: Is there software way to refactor autolisp routine?
Post by: JohnK on November 07, 2017, 03:05:11 PM
Any good editor should allow you to use regex.

Also, you could also use the preprocessor I built (it's called LiFP) to do simple search and replace.
https://www.theswamp.org/index.php?topic=37700.0
Title: Re: Is there software way to refactor autolisp routine?
Post by: nobody on November 13, 2017, 02:12:45 AM
Any good editor should allow you to use regex.

Also, you could also use the preprocessor I built (it's called LiFP) to do simple search and replace.
https://www.theswamp.org/index.php?topic=37700.0

Thanks seven...impressive as always.