Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Cocoa syntax highlighting text view

branch: master
Octocat-spinner-32 English.lproj Added TODO note with regard to line number positioning. April 16, 2013
Octocat-spinner-32 Fragaria.xcodeproj Moved recent headers into MGSFragariaFramework.h April 17, 2013
Octocat-spinner-32 Syntax Definitions Reinstated the javascript syntax definition that was modeified during… April 16, 2013
Octocat-spinner-32 icu Removed erroneous file from icu folder June 02, 2010
Octocat-spinner-32 .gitattributes
Octocat-spinner-32 .gitignore Updated .gitignore and cleaned up project folder. January 26, 2012
Octocat-spinner-32 DBPrefsWindowController.h
Octocat-spinner-32 DBPrefsWindowController.m Added preference controller and views. September 21, 2012
Octocat-spinner-32 ErrorPopoverView.xib Cleaned up code April 11, 2013
Octocat-spinner-32 FRAFontTransformer.h Preference views and controllers implemented September 19, 2012
Octocat-spinner-32 FRAFontTransformer.m Preference views and controllers implemented September 19, 2012
Octocat-spinner-32 Fragaria Document Based App-Info.plist Possible buffer overflow fixed. Simple NSDocument sample target added July 27, 2010
Octocat-spinner-32 Fragaria copy-Info.plist Fixed reference counting memory management. September 26, 2012
Octocat-spinner-32 Fragaria-Info.plist Updated framework version to 1.0.1 April 17, 2013
Octocat-spinner-32 FragariaAppDelegate.h Added reload to demo app to assist with code colouring debugging March 06, 2013
Octocat-spinner-32 FragariaAppDelegate.m Updated the TODO April 17, 2013
Octocat-spinner-32 Fragaria_Document-Info.plist Possible buffer overflow fixed. Simple NSDocument sample target added July 27, 2010
Octocat-spinner-32 Fragaria_Prefix.pch add project files June 02, 2010
Octocat-spinner-32 General.png Updated smaple project preference panel to use toolbar images. September 26, 2012
Octocat-spinner-32 ICUMatcher.h Preserve changes November 09, 2010
Octocat-spinner-32 ICUMatcher.m Cast unsigned longs to ints when using uregx functions to remove buil… January 12, 2013
Octocat-spinner-32 ICUPattern.h add project files June 02, 2010
Octocat-spinner-32 ICUPattern.m
Octocat-spinner-32 LICENSE-2.0.txt License added June 02, 2010
Octocat-spinner-32 MGSBreakpointDelegate.h Adds support for setting breakpoints by clicking on the line numbers March 05, 2013
Octocat-spinner-32 MGSExtraInterfaceController.h Fixed static analyzer warnings. January 13, 2012
Octocat-spinner-32 MGSExtraInterfaceController.m Fixed static analyzer warnings. January 13, 2012
Octocat-spinner-32 MGSFragaria-Info.plist Updated framework version to 1.0.1 April 17, 2013
Octocat-spinner-32 MGSFragaria.h Added - replaceCharactersInRange:withString:options: April 27, 2013
Octocat-spinner-32 MGSFragaria.m Added - replaceCharactersInRange:withString:options: April 27, 2013
Octocat-spinner-32 MGSFragariaFontsAndColoursPrefsViewController.h Improved preferences control input validation. October 22, 2012
Octocat-spinner-32 MGSFragariaFontsAndColoursPrefsViewController.m Fixed reference counting memory management. September 26, 2012
Octocat-spinner-32 MGSFragariaFramework.h Moved recent headers into MGSFragariaFramework.h April 17, 2013
Octocat-spinner-32 MGSFragariaPreferences.h Added number syntax colouring and number colour preference. April 13, 2013
Octocat-spinner-32 MGSFragariaPreferences.m Added number syntax colouring and number colour preference. April 13, 2013
Octocat-spinner-32 MGSFragariaPrefsViewController.h Improved preferences control input validation. October 22, 2012
Octocat-spinner-32 MGSFragariaPrefsViewController.m Improved preferences control input validation. October 22, 2012
Octocat-spinner-32 MGSFragariaTextEditingPrefsViewController.h Improved preferences control input validation. October 22, 2012
Octocat-spinner-32 MGSFragariaTextEditingPrefsViewController.m Improved preferences control input validation. October 22, 2012
Octocat-spinner-32 MGSGlyphGenerator.h Fixed poor invisible character alignment problem for some fonts. September 26, 2012
Octocat-spinner-32 MGSGlyphGenerator.m Fixed poor invisible character alignment problem for some fonts. September 26, 2012
Octocat-spinner-32 MGSPreferencesController.h Improved preferences control input validation. October 22, 2012
Octocat-spinner-32 MGSPreferencesController.m Improved preferences control input validation. October 22, 2012
Octocat-spinner-32 MGSPreferencesFontsAndColours.xib Added number syntax colouring and number colour preference. April 13, 2013
Octocat-spinner-32 MGSPreferencesTextEditing.xib Improved preferences control input validation. October 22, 2012
Octocat-spinner-32 MGSSyntaxController.h Fixed GC and 32 bit builds after vlidholt merge April 13, 2013
Octocat-spinner-32 MGSSyntaxController.m
Octocat-spinner-32 MGSTextMenuController.h Adds support for setting breakpoints by clicking on the line numbers March 05, 2013
Octocat-spinner-32 MGSTextMenuController.m Refactored to remove string literal document keys. April 14, 2013
Octocat-spinner-32 MyDocument.h Possible buffer overflow fixed. Simple NSDocument sample target added July 27, 2010
Octocat-spinner-32 MyDocument.m Updated sample apps and README. September 27, 2012
Octocat-spinner-32 NSScanner+Fragaria.h Removed MGSScanner as it was not being instantiated and was an invali… January 13, 2012
Octocat-spinner-32 NSScanner+Fragaria.m Fixed format specifier warnings for 32/64 bit build November 23, 2012
Octocat-spinner-32 NSStringICUAdditions.h add project files June 02, 2010
Octocat-spinner-32 NSStringICUAdditions.m Fixed static analyzer warnings. January 13, 2012
Octocat-spinner-32 Preferences.xib Added preference controller and views. September 21, 2012
Octocat-spinner-32 README.md Updated README April 17, 2013
Octocat-spinner-32 SMLAutoCompleteDelegate.h Improved support for autocompletion April 12, 2013
Octocat-spinner-32 SMLBasicPerformer.h Fixed static anlyser warnings with regard to RC memory management. July 30, 2011
Octocat-spinner-32 SMLBasicPerformer.m Fixed static analyzer warnings. January 13, 2012
Octocat-spinner-32 SMLCommandResult.xib Fixed NIB warnings by setting deployment target to 10.6 August 01, 2011
Octocat-spinner-32 SMLDetab.xib Added preference controller and views. September 21, 2012
Octocat-spinner-32 SMLEntab.xib Added preference controller and views. September 21, 2012
Octocat-spinner-32 SMLErrorPopOver.h Cleaned up code April 11, 2013
Octocat-spinner-32 SMLErrorPopOver.m Cleaned up code April 11, 2013
Octocat-spinner-32 SMLGoToLine.xib Edit menu enhanced. Functions include selection shift left+right, got… November 23, 2010
Octocat-spinner-32 SMLGutterTextView.h Fixed GC and 32 bit builds after vlidholt merge April 13, 2013
Octocat-spinner-32 SMLGutterTextView.m Added TODO note with regard to line number positioning. April 16, 2013
Octocat-spinner-32 SMLLayoutManager.h Fixed poor invisible character alignment problem for some fonts. September 26, 2012
Octocat-spinner-32 SMLLayoutManager.m Fixed warnings. April 16, 2013
Octocat-spinner-32 SMLLineNumbers.h Fixed GC and 32 bit builds after vlidholt merge April 13, 2013
Octocat-spinner-32 SMLLineNumbers.m Prevent occasional NSString substring out of bounds exception. November 24, 2013
Octocat-spinner-32 SMLOpenPanelAccessoryView.xib Edit menu enhanced. Functions include selection shift left+right, got… November 23, 2010
Octocat-spinner-32 SMLRegularExpressionHelp.xib Fixed NIB warnings by setting deployment target to 10.6 August 01, 2011
Octocat-spinner-32 SMLStandardHeader.h Edit menu enhanced. Functions include selection shift left+right, got… November 23, 2010
Octocat-spinner-32 SMLSyntaxColouring.h Fixed coloring of names containing _<number> April 16, 2013
Octocat-spinner-32 SMLSyntaxColouring.m Added user info to notification April 27, 2013
Octocat-spinner-32 SMLSyntaxColouringDelegate.h Fixed typo April 17, 2013
Octocat-spinner-32 SMLSyntaxDefinition.h Renamed syntax definition header and copied header to public framewor… April 16, 2013
Octocat-spinner-32 SMLSyntaxError.h Fixed GC and 32 bit builds after vlidholt merge April 13, 2013
Octocat-spinner-32 SMLSyntaxError.m Fixed GC and 32 bit builds after vlidholt merge April 13, 2013
Octocat-spinner-32 SMLTextPerformer.h Edit menu enhanced. Functions include selection shift left+right, got… November 23, 2010
Octocat-spinner-32 SMLTextPerformer.m Rationalised header imports September 26, 2012
Octocat-spinner-32 SMLTextView.h Added - replaceCharactersInRange:withString:options: April 27, 2013
Octocat-spinner-32 SMLTextView.m
Octocat-spinner-32 SyntaxDefinitions.plist added CoffeeScript April 04, 2013
Octocat-spinner-32 TODO.md Updated the TODO April 17, 2013
Octocat-spinner-32 editor-breakpoint-0.png Adds support for setting breakpoints by clicking on the line numbers March 05, 2013
Octocat-spinner-32 editor-breakpoint-1.png Adds support for setting breakpoints by clicking on the line numbers March 05, 2013
Octocat-spinner-32 editor-breakpoint-2.png
Octocat-spinner-32 editor-breakpoint.png Adds support for setting breakpoints by clicking on the line numbers March 05, 2013
Octocat-spinner-32 editor-warning.png Cleaned up code April 11, 2013
Octocat-spinner-32 main.m add project files June 02, 2010
README.md

What is it?

Fragaria is an OS X Cocoa syntax colouring NSTextView implemented within a framework named MGSFragaria. It supports a wide range of programming languages and includes preference panel support.

The MGSFragaria framework now properly supports both traditional reference counting memory management and garbage collection.

Where can I see it in use

You can see Fragaria used in the following projects and products:

  • Appium Recorder : Appium is an open source, cross-platform test automation tool for native and hybrid mobile apps. (repo).

  • cocoa-rest-client A native OS X cocoa application for testing HTTP endpoints.

  • CocosBuilder. CocosBuilder is a free tool (released under MIT-licence) for rapidly developing games and apps. (repo)

  • Cocoduino is an IDE for the Arduino platform written in native Cocoa.

  • KosmicTask is a multi (20+) language scripting environment for OS X that features script editing, network sharing, remote execution, and file processing.

  • nib2objc This utility converts NIB files (or XIB ones) into Objective-C code

If you use Fragaria in your app and want it added to the list just let us know or edit the README.

Features

Most features are accessed via the framework preferences.

  • Configurable syntax colouring
  • Configurable font type, size and colour.
  • Invisible character display
  • Line numbering
  • Brace matching and auto insertion
  • Page guide
  • Simple word auto complete
  • Tab and indent control
  • Line wrapping

How do I use it?

The best way to learn how to use the framework is to look at the sample apps.

  • Fragaria : a simple editor window that features language selection, a wired up text menu and a preferences panel.

  • Fragaria GC : a GC version of the above.

  • Fragaria Doc : a simple NSDocument based editor.

Show me code

A Fragaria view is embedded in a content view.

#import "MGSFragaria/MGSFragaria.h"

// we need a container view to host Fragaria in
NSView *containerView = nil; // loaded from nib or otherwise created

// create our instance
MGSFragaria *fragaria = [[MGSFragaria alloc] init];

// we want to be the delegate
[fragaria setObject:self forKey:MGSFODelegate];

// Objective-C is the place to be
[self setSyntaxDefinition:@"Objective-C"];

// embed in our container - exception thrown if containerView is nil
[fragaria embedInView:containerView];

// set initial text
[fragaria setString:@"// We don't need the future."];

The initial appearance of a Fragaria view is determined by the framework preferences controller. The MGSFragaria framework supplies two preference view controllers whose views can be embedded in your preference panel.

MGSFragariaTextEditingPrefsViewController * textEditingPrefsViewController = [MGSFragariaPreferences sharedInstance].textEditingPrefsViewController;

MGSFragariaFontsAndColoursPrefsViewController *fontsAndColoursPrefsViewController = [MGSFragariaPreferences sharedInstance].fontsAndColoursPrefsViewController;

Setting preferences

Preference strings are defined in MGSFragaria/MGSFragariaPreferences.h. Each preference name is prefixed with Fragaria for easy identification within the application preferences file.

// default to line wrap off
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsLineWrapNewDocuments];

All preferences are observed and instances of Fragaria views update immediately to reflect the new preference.

Breakpoint Highlighting

Use the MGSFOBreakpointDelegate key to define a breakpoint delegate that responds to conforms to MGSBreakpointDelegate

[fragaria setObject:self forKey:MGSFODelegate];

The breakpoint delegate returns an NSSet of breakpoint line numbers. The implementation of this feature is at an early stage. Feel free to improve it.

Syntax Error Highlighting

To add clickable syntax error highlights define an NSArray of SMLSyntaxErrors.

// define a syntax error
SMLSyntaxError *syntaxError = [[SMLSyntaxError new] autorelease];
syntaxError.description = @"Syntax errors can be defined";
syntaxError.line = 1;
syntaxError.character = 1;
syntaxError.length = 10;

fragaria.syntaxErrors = @[syntaxError];

The implementation of this feature is at an early stage. Feel free to improve it.

Custom colouring

The SMLSyntaxColouringDelegate protocol allows a delegate to influence the syntax colouring for each of a number of syntactical groups such as numbers, attributes, comments or keywords.

Pseudo code for the protocol method flow looks something like:

// query delegate if should colour this document
doColouring = fragariaDocument:shouldColourWithBlock:string:range:info
if !doColouring quit colouring

// send *ColourGroupWithBlock methods for each group defined by SMLSyntaxGroupInteger
foreach group

    // query delegate if should colour this group
    doColouring = fragariaDocument:shouldColourGroupWithBlock:string:range:info

    if doColouring

        colour the group

        // inform delegate group was coloured
        fragariaDocument:didColourGroupWithBlock:string:range:info

    end if
end

// inform delegate document was coloured
fragariaDocument:willDidWithBlock:string:range:info

The delegate can completely override the colouring for a given group or provide additional colouring support (you will have to provide you own scanning logic). Document level delegate messages provide an opportunity to provide colouring for custom group configurations.

For more details see SMLSyntaxColouringDelegate.h and the example code in FragariaAppDelegate.m.

Supported languages

Fragaria supports syntax colouring for a wide range of programming languages and configuration file formats:

A

actionscript, actionscript3, active4d, ada, ampl, apache (config), applescript, asm-mips, asm-x86, asp-js, asp-vb, aspdotnet-cs, aspdotnet-vb, awk

B

batch (shell)

C

C, cobol, coffeescript, coldfusion, cpp, csharp, csound, css

D

D, dylan

E

eiffel, erl, eztpl

F

F-script, fortran, freefem

G

gedcom, gnuassembler, graphviz

H

haskell, header, html

I

idl

J

java, javafx, javascript, jsp

L

latex, lilypond, lisp, logtalk, lsl, lua

M

matlab, mel, metapost, metaslang, mysql, nemerle,

N

nrnhoc

O

objectivec, objectivecaml, ox

P

pascal, pdf, perl, php, plist, postscript, prolog, python

R

r, rhtml, ruby

S

scala, sgml, shell, sml, sql, stata, supercollider

T

tcltk, torquescript

U

udo

V

vb, verilog, vhdl

X

xml

Defining a new language syntax

To define a new syntax definition:

  1. Generate a plist that defines the language syntax. The plist structure is simple and browsing the existing definitions should provide some enlightenment. The plist keys are defined in SMLSyntaxDefinition.h. For much deeper insight see SMLSyntaxColouring - recolourRange:.

  2. Insert a reference to the new plist into SyntaxDefinitions.plist

How can I contribute

Take a look at the TODO list.

Where did it come from?

Fragaria started out as the vital pulp of Smultron, now called Fraise. If you want to add additional features to Fragaria then looking at the Fraise and other forked sources is a good place to start. Fraise is a GC only app so you will need to consider memory management issues when importing code into Fragaria.

Something went wrong with that request. Please try again.