Commenting Code

I am in XCode 4.2 and I am trying to use the keyboard shortcut to comment out a block of code (command-/). When I do this it puts a double slash at the beginning of each line. The code does not become greyed out to indicate it is a comment. If I use the old “–” the line becomes greyed out.

I though this was just a visual problem, but I actually tried commenting out a problem line with the double-slash and when I build the project still errors. It appears that commenting out with double-slash actually doesn’t do anything.

Anyone know what is going on? I find it really useful to be able to select a section of code and just comment it all in one keystroke. Right now I have to go in line by line and type “–”.

Model: iMac
Browser: Firefox 3.6.4
Operating System: Mac OS X (10.6)

You should use the AppleScript way of commenting code, eventually the code is interpreted by the interpreter and will ignore the comments.

(*multi-line comments
should be used this way
to comment blocks*)

--a single line comment

As DJ says, you need to use the AS comment strings: “–”, “#” or “()”. The “//” sequence is for C code.

Cool. Thanks. I wish there was a preference to change the default commenting from // to – so I could use the keyboard shortcut. I guess if I need to comment out a huge block I will use the shortcut and then do a find/replace on // to --.

Thanks.

You can do the editing in an external editor. Blatant plug time: If you use my AppleScriptObjC Explorer, it has comment/uncomment commands (and lots of other ASObjC-related goodies).

Cool! I’ll check it out. Yeah, I don’t like the editor at all. I looked at Late Night Software’s script editor but it is expensive. I don’t know that I can get my complany to spend the money to buy it.

I’ll take a look today. Thanks.

Model: iMac
Browser: Firefox 3.6.4
Operating System: Mac OS X (10.6)

Strange. I downloaded AppleScript ObjC Explorer, but when I right-click on my applescript file in XCode the item “Open in External Editor” is greyed out. I looked through all the preferences and I can’t find a place to set an external editor.

What am I missing??

It’s covered in the documentation. Essentially you find a .applescript file in the Finder, choose Get Info, change the Open with: app, and click the Change All button.

Ahhhh. Thanks. I saw that and thought it was just for the convenience of being able to double-click the file and open it in the right app.

It works now. Thanks!

Model: iMac
Browser: Firefox 3.6.4
Operating System: Mac OS X (10.6)