MATCHING PARENTHESIS

MATCHING PARENTHESIS

vishshreevT578L
Advocate Advocate
1,291 Views
10 Replies
Message 1 of 11

MATCHING PARENTHESIS

vishshreevT578L
Advocate
Advocate
(defun CopyLayerColor2 (ent1 ent2 / elist1 elist2); the function
  (setq
    elist1 (entget ent1); entity data lists
    elist2 (entget ent2)
  ); setq
  (setq elist2 (append elist2 (list (assoc 8 elist1)))); assign ent1's Layer to ent2
  (setq elist2
    (append elist2 ; Color adjustment
      (if (assoc 62 elist1); ent1 has override [non-Bylayer] Color
        (list (assoc 62 elist1)); then [give that to ent2]
        '((62 . 256)); else [make ent2's Color ByLayer]
      ); if
    ); append
  ); setq
  (entmod elist2); update properties of ent2
); defun

(defun C:CLC2 (/ en1 en2); = Copy Layer & Color 2 [whatever the 2 means]; the command
  (if
    (and
      (setq en1 (car (entsel "\nObject to copy Layer and Color FROM: ")))
      (setq en2 (car (entsel "\nObject to copy Layer and Color TO: ")))
    ); and
    (CopyLayerColor2 en1 en2); apply those entities as arguments to the function
  ); if
  (princ)
); defun

IN THE ABOVE EXAMPLE ALL THE PARENTHESIS ARE MATCHING RESPECTIVELY.
I WANT TO UNDERSTAND HOW IT IS DONE.
THANKS SIR (KENT) IN ADVANCE
Shreev
0 Likes
1,292 Views
10 Replies
Replies (10)
Message 2 of 11

john.uhden
Mentor
Mentor
I use TextPad which has parenthesis matching by hitting Ctrl+M.

John F. Uhden

0 Likes
Message 3 of 11

dbroad
Mentor
Mentor

I use vlide.  Each time you hit a closing parenthesis it indicates the open parenthesis closed.  Double clicking in front of a parenthesis will select everthing it encloses.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 4 of 11

stevor
Collaborator
Collaborator

And I use Notepad2.exe, which 'colors' the matching parens,

when one is selected by a left mouse click.

I use the older version, 1.xx,  that includes the toolbar icons

for forward and reverse finds, avoiding the Find dialog box queries.

 

 

S
0 Likes
Message 5 of 11

vishshreevT578L
Advocate
Advocate
(defun CopyLayerColor2 (ent1 ent2 / elist1 elist2); the function
  (setq
    elist1 (entget ent1); entity data lists
    elist2 (entget ent2)
  ); setq
  (setq elist2 (append elist2 (list (assoc 8 elist1)))); assign ent1's Layer to ent2
  (setq elist2
    (append elist2 ; Color adjustment
      (if (assoc 62 elist1); ent1 has override [non-Bylayer] Color
        (list (assoc 62 elist1)); then [give that to ent2]
        '((62 . 256)); else [make ent2's Color ByLayer]
      ); if
    ); append
  ); setq
  (entmod elist2); update properties of ent2
); defun

(defun C:CLC2 (/ en1 en2); = Copy Layer & Color 2 [whatever the 2 means]; the command
  (if
    (and
      (setq en1 (car (entsel "\nObject to copy Layer and Color FROM: ")))
      (setq en2 (car (entsel "\nObject to copy Layer and Color TO: ")))
    ); and
    (CopyLayerColor2 en1 en2); apply those entities as arguments to the function
  ); if
  (princ)
); defun


Sir i mean to say in the above example is what i have underlined now
for instance setq closing parenthesis ends in line vertically to setq, if to if, and to and etc.....
Shreev
0 Likes
Message 6 of 11

martti.halminen
Collaborator
Collaborator

 

While showing the closing parenthesis indented at the same level as the opening one is considered good style in C -like languages, in the mainstream Lisp culture (Common Lisp, Scheme) that is considered a waste of space. A professional CL programmer would indent your example like this:

 

(defun CopyLayerColor2 (ent1 ent2 / elist1 elist2); the function
  (setq elist1 (entget ent1); entity data lists
        elist2 (entget ent2))
  (setq elist2 (append elist2 (list (assoc 8 elist1)))); assign ent1's Layer to ent2
  (setq elist2
        (append elist2 ; Color adjustment
                (if (assoc 62 elist1); ent1 has override [non-Bylayer] Color
                    (list (assoc 62 elist1)); then [give that to ent2]
                    '((62 . 256))))); else [make ent2's Color ByLayer]
  (entmod elist2)); update properties of ent2


(defun C:CLC2 (/ en1 en2); = Copy Layer & Color 2 [whatever the 2 means]; the command
  (if
   (and
     (setq en1 (car (entsel "\nObject to copy Layer and Color FROM: ")))
     (setq en2 (car (entsel "\nObject to copy Layer and Color TO: "))))
   (CopyLayerColor2 en1 en2)); apply those entities as arguments to the function
  (princ))

That is easy to achieve with an editor that understands Lisp syntax; about 90 % of CL programmers use some variant of Emacs.

 

0 Likes
Message 7 of 11

Kent1Cooper
Consultant
Consultant

@vishshreevT578L wrote:
....
IN THE ABOVE EXAMPLE ALL THE PARENTHESIS ARE MATCHING RESPECTIVELY.
I WANT TO UNDERSTAND HOW IT IS DONE.
THANKS SIR (KENT) IN ADVANCE

It's all a matter of personal preference, but I tend to put right parentheses, if they are not on the same line as the left parentheses they go with, at the same level of indentation, mostly because:

A)  I find it easier to "see what's going on" than in the "mainstream" Common Lisp practice mentioned by @martti.halminen in Post 6; and

B)  Many [though certainly not all] examples in the AutoLisp Reference do it this way, for example the entry about (lambda).

 

I just do it manually, with two spaces per level of indentation.  Many people use tabs, which is too much indentation for my taste, and often requires one to scroll to see the end of a line of code when that would not be necessary with less extreme indentations.  One space doesn't seem to be enough for visible differentiation [again, to my eye].  No indentation is required at all, functionally, so do what you prefer.

Kent Cooper, AIA
0 Likes
Message 8 of 11

Shneuph
Collaborator
Collaborator

Also.. in the VLIDE you can go to Tools>Format Code in Editor or Ctrl+Alt+F.  End result on your code:

 

VLIDE Format Code.JPG

 

I don't like how it does the comments, but other than that it generally gets me to a format I like.

 

 

EDIT:

Since you asked I just found that you can also edit these format options with Tools>Environment Options>Visual LISP Formatting Options. Thanks!

Format Options.png

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 9 of 11

ВeekeeCZ
Consultant
Consultant
My favourite tool for formatting is
VLIDE >> Edit / Extra commands / Indent to Current Level.
0 Likes
Message 10 of 11

john.uhden
Mentor
Mentor
I don't want to sound overly defensive, but I also like TextPad because of
colorized syntax (thanks to Michael Puckett) and the ability to set tabs at
2 (or whatever) spaces while at the same time automatically translating
tabs to spaces. Plus I can work on multiple lisp files without running
AutoCAD and without the VLIDE environment.

I guess the funniest thing is that I still use ZTree to find, search, view,
rename, copy, and open files. I was a CAD Manager dating back to DOS days,
and every app we used we ran from XTree complete with maintaining a dwg
history (though that was via AutoLisp). The users weren't really aware
that I could track how much time they wasted (er, uh, spent) on a drawing
or who created "that" dwg. It could probably still work, but I haven't
bothered with it since my unwilling retirement.

John F. Uhden

0 Likes
Message 11 of 11

vishshreevT578L
Advocate
Advocate

Thank You Sir!

Shreev
0 Likes