Author Topic: Get rid of comments (Using NP++ or VLIDE)  (Read 12618 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #15 on: December 18, 2017, 03:19:46 PM »
You can write a simple lisp routine to clear out comments.  You will need to decide whether to
you want to deal with inline/multiline notes as well  ie

Code: [Select]
  ;|   This is a comment |;
-David

Yeah, David - I was thinking about writing some conditional that switches few booleans if comment is active.
And would process the list of strings from the .lsp file. But just left it as starting conception (not finished) :
Code: [Select]
(cond ( (not row) ) ( (setq row (car L)) (setq L (cdr L)) ) )
(cond
  ( (not row) row)
  (cmt (setq row nil) ) ; comment mode is on
  ( (wcmatch row "*;|*") (setq cmt T) (setq row nil) ) ; comment mode on
  ( (wcmatch row "*|;*") (setq cmt nil) (setq row (TrimStingUpTo row "|;")) ) ; comment mode off
  ( (wcmatch row "*;*") ; theres a code'n'comment
    (setq row (TrimStingUpTo row ";"))
  )
  ( (wcmatch row "*;") ; code and a single ';'
    (setq row (TrimStingUpTo row ";"))
  )
  ( (wcmatch row ";*") ; comment
    (setq row nil)
  )     
  (T row) ; no comment, only code
); cond

Unfortunately I'm tight on free time again, but would finish it if it was very important (although initially I didn't think the task would translate into coding).


Don't have time for more than quick & dirty ...

Seems to work - Thanks for sharing your skills, Michael! :)


Question, why do you want to remove comments?

Simply said: over commenting
Say I wanted to learn someone's code by reading whats happening in the plain code, but there are too many comments that I loose my mind in a redundant descriptions, (thru the mid-evaluation).
Other reason would be, if the code is commented in Spanish/Russian/German/Chineese - a lisper might don't know the language, but still would be able to understand whats happening in there (and the comments still get in the way).

Few times I had such problem, so that brought my question that there might be a global solution for this.
And I'm not talking about removing any copyrighted footers or headers(that'd be silly), but a stuff like:
Code - Auto/Visual Lisp: [Select]
  1. (+
  2.   ; Hey hey
  3.   ; This is ..
  4.   ; ...
  5.   ; ...
  6.   (1+
  7.     ; bla-bla
  8.     ; bla-bla
  9.     2
  10.   )
  11.   ; ...
  12.   3
  13. )



It's a Trump directive.

That would be "How do I remove twitter comments":laugh:

EDIT:

MP, I've forgot to mention that I did a small addition to your code:
inside nom's def.. :
Code: [Select]
(and (or (and lisp (findfile lisp)) (setq lisp (getfiled "Specify LISP file" (strcat (getenv "userprofile") "\\Desktop\\") "lsp" 16))) (setq handle (open lisp "r")))so then:
Code: [Select]
(_CleanLisp "sample.lsp") or (_CleanLisp nil);)
« Last Edit: December 18, 2017, 03:25:52 PM by Grrr1337 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #16 on: December 18, 2017, 03:28:09 PM »

Seems to work - Thanks for sharing your skills, Michael! :)

My pleasure. PS: Removes ;| This is a comment |; type comments too.

That would be "How do I remove twitter comments":laugh:

Exactly.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #17 on: December 18, 2017, 03:31:46 PM »
I don't see the point in (_CleanLisp nil) hand holding code.

Yeah, if you pass it a nil it will crash.

So will passing nils to native functions that expect non nil values, e.g. (+ nil nil).

/2¢
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #18 on: December 18, 2017, 03:55:34 PM »

My pleasure. PS: Removes ;| This is a comment |; type comments too.


Yeah, I've expected this after a quick glance, still not tested if would work for multiline ;| ... \n ... \n ... |; comments.



Yeah, if you pass it a nil it will crash.


Nonono, the point is that now you could either pass a filename or use nil to prompt for a file.
Not talking about error-proofing the argument(s).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #19 on: December 18, 2017, 03:58:37 PM »
Yeah, I've expected this after a quick glance, still not tested if would work for multiline ;| ... \n ... \n ... |; comments.

it will. :)

Nonono, the point is that now you could either pass a filename or use nil to prompt for a file.

My bad, please accept my apologies, read it was too fast with bleary eyes. I actually do that in a utility I have to harvest cvs/tsv data.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #20 on: December 18, 2017, 04:13:06 PM »
My bad, please accept my apologies, read it was too fast with bleary eyes. I actually do that in a utility I have to harvest cvs/tsv data.

No worries MP, that'd be stupid of me to pick on a newly offered code which I'm unable to write myself.  :uglystupid2:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #21 on: December 18, 2017, 04:16:59 PM »
Disagree. What I wrote does not step outside your skill set. I was surprised to beat you to the punch to be honest. And critique away! I may not agree but any code posted should be equal candidate for examination, improvement, yada.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #22 on: December 18, 2017, 04:47:28 PM »
Disagree. What I wrote does not step outside your skill set. I was surprised to beat you to the punch to be honest.

I'd take this as a compliment, problem is that I'm so confused recently that I cannot estimate what I'm able to write and what I can't (so usually then im invoking the 'HelpFromTheSwamp method).
I think its like "I'm unable to find the right words to describe it" for coding.

And critique away! I may not agree but any code posted should be equal candidate for examination, improvement, yada.

I agree about criticism on codes, just trying to avoid the obvious stuff (nitpick).
Because saying to you that you should check'n' error-proof the input args sounds like "Hey Lee, (strcase str) for str = nil will error out":-D
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

VovKa

  • Water Moccasin
  • Posts: 1628
  • Ukraine
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #23 on: December 18, 2017, 05:10:44 PM »
Code: [Select]
(alert "\"Test1;Test2\"")

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #24 on: December 18, 2017, 05:48:44 PM »
Code: [Select]
(alert "\"Test1;Test2\"")

Fun!

And revised. :P
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #25 on: December 18, 2017, 05:51:08 PM »
I'd take this as a compliment

that was the intention

problem is that I'm so confused recently that I cannot estimate what I'm able to write and what I can't (so usually then im invoking the 'HelpFromTheSwamp method).
I think its like "I'm unable to find the right words to describe it" for coding.

you're doing fine from what I've read

I agree about criticism on codes, just trying to avoid the obvious stuff

generally a good strategy
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1628
  • Ukraine
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #26 on: December 18, 2017, 06:03:16 PM »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #27 on: December 18, 2017, 06:08:02 PM »

My pleasure. PS: Removes ;| This is a comment |; type comments too.


Yeah, I've expected this after a quick glance, still not tested if would work for multiline ;| ... \n ... \n ... |; comments.



Yeah, if you pass it a nil it will crash.


Nonono, the point is that now you could either pass a filename or use nil to prompt for a file.
Not talking about error-proofing the argument(s).

Personally I'd leave the original as is and write a wrapper function to test/prompt for a filename ... have the wrapper call the function that does the work.

I've assumed the question/statement about 'why do you want to remove comments' was rhetorical.


Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #28 on: December 18, 2017, 06:38:16 PM »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1628
  • Ukraine
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #29 on: December 18, 2017, 07:28:19 PM »