Stop Xcode from converting text into hyperlinks? - xcode

I've got Xcode 3.2.1, and enjoy using it, but when I'm editing a file with hyperlinks in the text (for example, a comment with a reference: # see http://example.com) Xcode turns the text into a clickable hyperlink. This is a royal PITA when trying to edit that hyperlink, as it means I can't click inside it to edit a piece of the link -- I have to select it all and retype, or backspace/arrow-key eleventy-bajillion times to get to the part that needs changing.
Anyone know how to turn that off? I don't see it anywhere in the preferences, and have Googled until my fingers fell off, to no avail.

Dug a little further, and I found that Xcode 3.x hides its syntax highlighting rules in xclangspec files, so editing the appropriate file will allow you to change the rules to an extent.
Files are stored here:
/Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources
In that directory, I opened BaseSupport.xclangspec and found the line that identified the URL protocol:
Syntax = {
StartChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;/:#&=+$,-_.!~*'()%#";
Match =
"^(acap|afp|afs|cid|data|fax|feed|file|ftp|go|gopher|http|https|imap|ldap|mailserver|mid|modem|news|nntp|opaquelocktoken|pop|prospero|rdar|rtsp|service|sip|soap\\.beep|soap\\.beeps|tel|telnet|tip|tn3270|urn|vemmi|wais|z39\\.50r|z39\\.50s)://([a-zA-Z0-9\\-_.]+/)?[a-zA-Z0-9;/?:#\\&=+$,\\-_.!~*'()%#]+$",
"^(mailto|im):[a-zA-Z0-9\\-_]+#[a-zA-Z0-9\\-_\\.!%]+$",
"^radar:[a-zA-Z0-9;/?:#\\&=+$,\\-_.!~*'()%#]+$",
); */
Type = "xcode.syntax.url";
};
and changed the line for Match = to read:
Match = ();
This eliminated URL matching, but not mailto matching (which is in a separate rule below the first). I'm leaving that as an exercise for the reader ;-)
Obviously, I could have been more selective, and I suspect that changing the Type line would be sufficient as well. Also, future versions of Xcode will likely overwrite this change, so I'll have to investigate putting the change into my own copy of BaseSupport.xclangspec and see if sticking it in ~/Library/Application Support works.

Use the option key when selecting text in the link or more drastically, turn off syntax highlighting for the file.

For anyone coming here for Xcode 7, things have changed a bit since #Zee's original posting.
For starters, the BaseSupport.xclangspec file is now located /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources.
Secondly, you must also modify the Built-in Syntax Types.xcsynspec file, which is in the same directory as BaseSupport.xclangspec. After opening this file, go down to the comment MARK: URLs and get rid of the url identifiers.
For safety purposes, I would recommend just commenting:
// MARK: URLs
//{
// Identifier = "xcode.syntax.url";
// Name = "URLs";
// Color = "0.055 0.055 1.000";
// IncludeInPrefs = YES;
// IsLink = YES;
// URLFormat = "%#";
//},
//{
// Identifier = "xcode.syntax.url.mail";
// BasedOn = "xcode.syntax.url";
// Color = "0.055 0.055 1.000";
// IncludeInPrefs = NO;
// IsLink = YES;
// URLFormat = "mailto:%#";
//},

Related

XCode 7.3 bug with code marking (in Swift)

In XCode 7.3, document items (toggled with ctrl-6) is not displaying properly beyond a certain point. (There is nothing wrong above the screen shot)
Not many people will experience this since it happens (as far as I've found out) in specific situations.
let i = 0
switch i {
default: "\(i) ©"
}
Copy and pasting the above code will make the same thing happen in any file with // MARK: // FIXME: // TODO: code markings.
The condition for this to happen is the combination of the three:
Using switch: if {} won't cause the same problem.
Using string interpolation: String(format: "%d ©", i) or "stringText ©" won't cause the same problem.
Using Emoji & Symbols with a space in front: "\(i)©" won't cause the same problem.
Any one of the three conditions are not met, the bug won't happen. So in case you look at document items a lot and don't want to see the mangled dropdown list, try changing any one of three conditions.

How to deselect the contents of a TextField in swift

I have a simple desktop app where a TextField should be focused when the window loads. I have this working, but it's a little annoying that, having loaded the users content into the TextField, the entire contents of the field become selected automatically. The user may want to start editing the content, but they will rarely/never want to replace it all at once (imagine a text editor doing this, to see what I mean).
I see there is an Action for selectAll: but what I want is the opposite Action of selectNone:
I tried passing nil to the selectText method, but that doesn't work:
textField.selectText(nil)
I found a number of answers on StackOverflow that mention a selectedTextRange, but this appears to be outdated, because Xcode 6.3 doesn't recognize this as a valid property on TextField.
Can anyone explain how I do this?
It's been a while since I've dealt with NSTextFields to this level (I work mostly in iOS these days).
After doing a little digging I found this on the net:
NSText* textEditor = [window fieldEditor:YES forObject:textField];
NSRange range = {start, length};
[textEditor setSelectedRange:range];
window is the window containing your field, textField.
This requires the field editor to be managing your field, what can be done simply by previously selecting the whole text of the field using the selectText:sender method.
Here is the final swift code that I got working based on what Duncan C posted:
if let window = NSApplication.sharedApplication().mainWindow {
let textEditor = window.fieldEditor(true, forObject: textField)!
let range = NSRange(0..<0)
textEditor.selectedRange = range
}

How to Fix Error: Incompatible Pointer Types Assigning to

Let me preface this by saying I'm new so I might not be the best at asking questions but here it goes. I am getting this error when I hit build in XCode with this code.
-(IBAction)unwindToRecipeDetails:(UIStoryboardSegue*)segue
{
ChangeRecipeDetailViewController *source = [segue sourceViewController];
recipeLabel = source.textView; // error: Incompatible Pointer Types Assigning to UILabel from UITextField
}
Here's what I'm trying to do. I based the code off of this snippet which works...
-(IBAction)unwindToRecipeBook:(UIStoryboardSegue *)segue;
{
AddRecipeViewController *source = [segue sourceViewController];
RecipeItem *item = source.recipeItem;
}
This is supposed to make AddRecipeViewController the data source for the initial RecipeBook page when the user navigates backward. I'm trying to implement the same thing for when a user navigates backward from the ChangeRecipe page to the RecipeDetails page.
Apparently I mixed two different types of code in the error, UILabel and UITextField. I get that they are incompatible but what could I change either one to in order to make it work. It is a little different than what I am basing my code off of in that I don't just want to transfer the same text, I want to change its format as well.
Again, I'm new at this so if anyone needs more information I'll gladly post it. Thanks.
Update 1: Palpatim: Thank you. Your solution worked. So to clarify, in order to transfer text I have to put .text after the initial source. This combines two unlike objects and transfers only text to text. Is this correct? I'm new at coding and am just trying to learn.
Philip Mills: I meant I wanted to change the format of the text when I transfer it from something that is editable like a textview to something static like a label.
Thanks for the help.

NSAlert beginSheetModalForWindow:completionHandler:

While setting up an NSAlert object to be displayed as a modal sheet in Xcode 5.0.2, I hit an interesting surprise.
I was planning on using beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:
As I started to enter it, Xcode autofilled beginSheetModalForWindow:completionHandler: for me (even though I cannot find this in any NSAlert documentation).
I prefer to use completion handlers rather than delegate/selector as a callback mechanism, so I went ahead and tried it. I was pleasantly surprised to find that it worked perfectly.
Three quick questions before I commit to this.
Am I missing something in the documentation?
Is it "safe" to use this feature if it is undocumented? (i.e. will it magically disappear as mysteriously as it appeared?)
I'd rather not hardcode the response values based on what I'm seeing via logging. Does anybody know the "proper" NS...Button constants?
This call is “safe” but it’s 10.9+ only. Here it is from the header file:
#if NS_BLOCKS_AVAILABLE
- (void)beginSheetModalForWindow:(NSWindow *)sheetWindow completionHandler:(void (^)(NSModalResponse returnCode))handler NS_AVAILABLE_MAC(10_9);
#endif
It appears they just accidentally left it out of the current docs. The headers are generally considered the “truth” in Cocoa, though—they authoritatively tell you what’s deprecated and what’s new. (Unlike in X11, for instance, where the documentation was declared to be correct over the actual implementations or the headers.)
These are the constants you want to use inside your completionHandler block:
/* These are additional NSModalResponse values used by NSAlert's -runModal and -beginSheetModalForWindow:completionHandler:.
By default, NSAlert return values are position dependent, with this mapping:
first (rightmost) button = NSAlertFirstButtonReturn
second button = NSAlertSecondButtonReturn
third button = NSAlertThirdButtonReturn
buttonPosition 3+x = NSAlertThirdButtonReturn + x
Note that these return values do not apply to an NSAlert created via +alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat:, which instead uses the same return values as NSRunAlertPanel. See NSAlertDefaultReturn, etc. in NSPanel.h
*/
enum {
NSAlertFirstButtonReturn = 1000,
NSAlertSecondButtonReturn = 1001,
NSAlertThirdButtonReturn = 1002
};

Highlighting the current line in TextMate 2

In TM 1.x, there was a preferences setting to enable the highlighting of the current line. This option seems to have disappeared in TM2. I assume there is some setting in tm_properties that can be set, but I cannot figure it out. I've tried setting lineHighlight to be a color, but this does not work. Has anyone figured this out?
It is not possible in TM2 yet, but there is an open ticket on github regarding this issue. The lead developer is assigned to it, however it doesn't seem to have that high priority.
Eventually you should be able to do like this:
settings = {
lineHighlight = '#FF483E';
};
This is from the Monokai Theme.
It's possible to set the colour for the current line in the line number and folding column on the left side of the window. Add the following after the first { in the beginning of the theme:
gutterSettings = {
foreground = '#BBBBBB';
background = '#333333';
divider = '#BBBBBB';
selectionBackground = '#FF8800';
selectionForeground = '#000000';
};

Resources