Cocoa syntax highlighting text view
Branch: marta
Clone or download
Pull request Compare This branch is 3 commits ahead, 18 commits behind shysaur:master.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Applications Make a copy of the example file of Fragaria Simple to work around Xco… Mar 31, 2018
Colour Schemes Add Solarized color schemes. Mar 25, 2015
Doxygen Add a doxygen Doxyfile. Jan 18, 2016
Fragaria.xcodeproj Add marco (Marta configuration) syntax format Dec 28, 2018
Images.xcassets Sightly reduce the size of the compiled framework. Mar 16, 2016
MGSFragaria Tests Add a method for obtaining a standard list of color schemes. Oct 24, 2017
Syntax Definitions Add marco (Marta configuration) syntax format Dec 28, 2018
en-GB.lproj Update other XIBs. Jan 15, 2016
en.lproj Add the disable autocompletion space confirm option to the preference… Sep 19, 2017
.gitignore Add a doxygen Doxyfile. Jan 18, 2016
Fragaria.h Make MGSColourScheme public. Oct 22, 2017
LICENSE-2.0.txt License added Jun 2, 2010
MGSBoolToColourTransformer.h Add a doxygen Doxyfile. Jan 18, 2016
MGSBoolToColourTransformer.m Value transformed required for previous commit. Mar 22, 2015
MGSBoolToGlobalHintTransformer.h Add a doxygen Doxyfile. Jan 18, 2016
MGSBoolToGlobalHintTransformer.m Use the right localization file in MGSFragaria. May 10, 2015
MGSBreakpointDelegate.h Improve support for Swift by adding more lightweight generics. Sep 16, 2016
MGSColourScheme.h Add a method for copying a colour scheme. Nov 17, 2017
MGSColourScheme.m Don't crash on color scheme files with unknown keys. Jun 11, 2018
MGSColourSchemeController.h Add a method for obtaining a standard list of color schemes. Oct 24, 2017
MGSColourSchemeController.m Add error parameters to MGSColorScheme file read/write methods. Oct 22, 2017
MGSColourSchemeOption.h Move some properties of MGSColourScheme to a separate class. Oct 20, 2017
MGSColourSchemeOption.m Move some properties of MGSColourScheme to a separate class. Oct 20, 2017
MGSColourSchemeSaveController.h Add a doxygen Doxyfile. Jan 18, 2016
MGSColourSchemeSaveController.m Use the right localization file in MGSFragaria. May 10, 2015
MGSColourToPlainTextTransformer.h Add a doxygen Doxyfile. Jan 18, 2016
MGSColourToPlainTextTransformer.m Remove useless value transformer registration. Mar 25, 2015
MGSDragOperationDelegate.h More documentation. Feb 22, 2015
MGSExtraInterfaceController.h Add a doxygen Doxyfile. Jan 18, 2016
MGSExtraInterfaceController.m Set the current tab width as default value for the entab and detab sh… May 16, 2015
MGSFontWell.h Add a doxygen Doxyfile. Jan 18, 2016
MGSFontWell.m Fix an internal consistency issue in MGSFontWell. May 30, 2015
MGSFragaria-Info.plist Add a versioning system. Sep 21, 2017
MGSFragariaTextViewDelegate.h Make Fragaria's text view delegate protocol compatible with NSTextVie… Apr 17, 2015
MGSFragariaView+Definitions.h Add the disable autocompletion space confirm option to the preference… Sep 19, 2017
MGSFragariaView+Definitions.m Add the disable autocompletion space confirm option to the preference… Sep 19, 2017
MGSFragariaView.h Add a method in MGSFragariaView to set the colors from a color scheme. Oct 24, 2017
MGSFragariaView.m Add a method in MGSFragariaView to set the colors from a color scheme. Oct 24, 2017
MGSFragariaViewPrivate.h Make private classes truly private. Mar 4, 2016
MGSHybridUserDefaultsController.h Improve support for Swift by adding more lightweight generics. Sep 16, 2016
MGSHybridUserDefaultsController.m Spelling check and small, misc. corrections. Mar 25, 2015
MGSLineNumberView.h Pass error objects directly to MGSLineNumberView. Mar 9, 2016
MGSLineNumberView.m Do not implicitly retain self. Mar 31, 2018
MGSLineNumberViewDecoration.h Add support for having a contextual menu on breakpoint badges. Mar 9, 2016
MGSMutableSubstring.h Make NSTextStorage+Fragaria and MGSMutableSubstring public. Because w… Mar 5, 2017
MGSMutableSubstring.m Rewrite -commentOrUncomment: to take advantage of MGSMutableSubstring. May 16, 2015
MGSPreferencesProxyDictionary.h Add a doxygen Doxyfile. Jan 18, 2016
MGSPreferencesProxyDictionary.m Rename MGSMutableDictionary to MGSPreferencesProxyDictionary. Jan 15, 2016
MGSPrefsColourPropertiesViewController.h Spelling check and small, misc. corrections. Mar 25, 2015
MGSPrefsColourPropertiesViewController.m Bake MASPreferences support directly inside MGSFragaria. May 30, 2015
MGSPrefsEditorPropertiesViewController.h Remove the very fragile first responder code in the view controller b… May 29, 2015
MGSPrefsEditorPropertiesViewController.m Bake MASPreferences support directly inside MGSFragaria. May 30, 2015
MGSPrefsViewController.h Bake MASPreferences support directly inside MGSFragaria. May 30, 2015
MGSPrefsViewController.m Set the global controller as the default for the preference panels. May 31, 2015
MGSSyntaxController.h Fix an incorrect parameter name in the documentation. Oct 11, 2017
MGSSyntaxController.m Give extension "txt" to the None syntax definition. Oct 14, 2017
MGSSyntaxDefinition.h Add a doxygen Doxyfile. Jan 18, 2016
MGSSyntaxDefinition.m Nuked MGSFragariaFramework and sanitized all old imports. May 9, 2015
MGSSyntaxErrorController.h Pass error objects directly to MGSLineNumberView. Mar 9, 2016
MGSSyntaxErrorController.m Increase error popup font size a bit Jan 2, 2019
MGSUserDefaults.h Add a doxygen Doxyfile. Jan 18, 2016
MGSUserDefaults.m Fixed major disaster wherein font and color property types caused exc… Mar 15, 2015
MGSUserDefaultsController.h Improve support for Swift by adding more lightweight generics. Sep 16, 2016
MGSUserDefaultsController.m Rename MGSMutableDictionary to MGSPreferencesProxyDictionary. Jan 15, 2016
MGSUserDefaultsControllerProtocol.h Improve support for Swift by adding more lightweight generics. Sep 16, 2016
NSColor+TransformedCompare.h Add a doxygen Doxyfile. Jan 18, 2016
NSColor+TransformedCompare.m Refactor the RGBCompare stuff to be less misleading in name and purpose. Mar 25, 2015
NSObject+Fragaria.h Add a doxygen Doxyfile. Jan 18, 2016
NSObject+Fragaria.m Create a category of NSObject to avoid duplicating -propagateValue:fo… May 29, 2015
NSScanner+Fragaria.h Add a doxygen Doxyfile. Jan 18, 2016
NSScanner+Fragaria.m Fixed format specifier warnings for 32/64 bit build Nov 23, 2012
NSSet+Fragaria.h Allow MGSBreakpointDelegate to return breakpoints in an NSIndexSet. Mar 6, 2016
NSSet+Fragaria.m Allow MGSBreakpointDelegate to return breakpoints in an NSIndexSet. Mar 6, 2016
NSString+Fragaria.h Add a doxygen Doxyfile. Jan 18, 2016
NSString+Fragaria.m Some logic simplification. Dec 15, 2015
NSTextStorage+Fragaria.h Make NSTextStorage+Fragaria and MGSMutableSubstring public. Because w… Mar 5, 2017
NSTextStorage+Fragaria.m Add a method to MGSBreakpointDelegate for updating breakpoints in res… Mar 6, 2016
README.md Update the readme. Mar 6, 2016
SMLAutoCompleteDelegate.h Improve support for Swift by adding more lightweight generics. Sep 16, 2016
SMLLayoutManager.h Add support to customize the invisible character substitutions Sep 21, 2017
SMLLayoutManager.m Patch up a NSTextView bug in High Sierra which caused the height of t… Jan 16, 2018
SMLSyntaxColouring.h Add a doxygen Doxyfile. Jan 18, 2016
SMLSyntaxColouring.m Do not implicitly retain self. Mar 31, 2018
SMLSyntaxColouringDelegate.h Improve support for Swift by adding more lightweight generics. Sep 16, 2016
SMLSyntaxDefinition.h Remove removeFromFunction because it was never implemented. Mar 4, 2015
SMLSyntaxError.h Add support for having a contextual menu on breakpoint badges. Mar 9, 2016
SMLSyntaxError.m Improve SMLSyntaxError with image caching and a new factory method. May 12, 2015
SMLTextView+MGSDragging.h Nuked MGSFragariaFramework and sanitized all old imports. May 9, 2015
SMLTextView+MGSDragging.m Move the dragging delegate to a separate header file. Feb 8, 2015
SMLTextView+MGSTextActions.h Actually document the new method introduced in a39f799. Oct 6, 2017
SMLTextView+MGSTextActions.m Move the copy with highlighting action to SMLTextView. Oct 5, 2017
SMLTextView.h Add support to customize the invisible character substitutions Sep 21, 2017
SMLTextView.m Insert tabs for new lines with '}' automatically Dec 28, 2018
SMLTextViewPrivate.h Add a doxygen Doxyfile. Jan 18, 2016
SyntaxDefinitions.plist Add marco (Marta configuration) syntax format Dec 28, 2018
TODO.md Mark additional regex support and Mardown support as done. Mar 15, 2015

README.md

MGSFragaria

A fork of https://github.com/mugginsoft/Fragaria with a focus on fixing bugs, while adding some new features along the way.

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.

Why switching to this fork makes my code not build anymore?

This fork of Fragaria is a significant departure from the original design. The MGSFragaria class was replaced by MGSFragariaView, and the old preference panels were replaced by a more flexible design. The settings which could only be set as user defaults were converted to properties of MGSFragariaView, and MGSTextMenuController was removed (you can directly make a connection to MGSFragariaView or to First Responder instead).

If you want to update your app to this fork of Fragaria, to lessen the burden you can use the legacy branch as a stepping stone.

Where can I see it in use

You can see an old version of 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

  • 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
  • Configurable breakpoint marks
  • Syntax error badges and underlines
  • Drag and drop
  • Split view support

How do I use it?

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

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

  • Fragaria Doc : a simple NSDocument based editor with the new preferences panels.

  • Fragaria Complex : a split view editor with an hard-wired options panel

  • Fragaria Prefs : a split view editor like Fragaria Complex with the new preferences panels and more complex breakpoint marker behavior.

Show me code

First, place MGSFragariaView in your nib. Then create an outlet for it in your window controller class, wiring the newly placed view to it. Alternatively you can create MGSFragariaView programmatically like any other view. Then, you can initialize Fragaria using its ivar or property.

#import <Fragaria/Fragaria.h>

// Objective-C is the place to be
[fragaria setSyntaxDefinitionName:@"Objective-C"];

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

You can further customize the look of Fragaria by setting the appropriate properties. Have a look at MGSFragariaView.h for detailed documentation.

Breakpoint Highlighting

Use the breakpointDelegate property to define a breakpoint delegate that conforms to MGSBreakpointDelegate. This delegate will act as a data source for the gutter view.

[fragaria setBreakpointDelegate:self];

If the delegates implements either -colouredBreakpointsForFragaria: or -breakpointColourForLine:ofFragaria:, you can set a custom color for your breakpoints. For example you can return a transparent NSColor for disabled breakpoints.

When the user clicks on a line number in the gutter, Fragaria sends the -toggleBreakpointForFragaria:onLine: message to the delegate, which will then update its breakpoint data. If you need to manually update the breakpoints, you should refresh the gutter view manually afterwards:

[fragaria reloadBreakpointData];

Syntax Error Highlighting

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

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

fragaria.syntaxErrors = @[syntaxError];

You can specify a custom warningLevel to change the icon shown for the syntax error and its priority in case multiple syntax errors are assigned to the same line. To define custom priorities and icons you can subclass SMLSyntaxError and use the subclass.

Using the new preference panels

The new preferences system allows for having multiple preference groups in the same apps, which can control all or some of the available options. Every MGSFragariaView that you want to be controlled by preferences must be added manually to a preference group; after you've done that, everything's automatic.

The easiest way to use the new preference panels is to only use the global group; this results in a single set of preferences for all the instances of Fragaria in the app, which is what you want 90% of the time.

First, you set the persistent flag on the group when the application initializes. This is typically done by the application delegate inside -applicationWillFinishLaunching: (not in -applicationDidFinishLaunching: because other initialization code which uses the defaults controller may be called before -applicationDidFinishLaunching:)

- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
    [[MGSUserDefaultsController sharedController] setPersistent:YES];
}

The global controller by default manages all the available properties of MGSFragariaView. If you want to manage some of these properties manually, you should also remove them from the managed properties set in this stage.

Then, when you create a new MGSFragariaView, you register it to the global group in this way:

[[MGSUserDefaultsController sharedController] addFragariaToManagedSet:fragaria];

Before an MGSFragariaView registered to a defaults controller is deallocated, you should remove it from the controller's managed set. Not doing this may result in seemingly random crashes because the defaults controller does not retain the registered views (doing that would create a retain cycle).

[[MGSUserDefaultsController sharedController] removeFragariaFromManagedSet:fragaria];

Done this, to use the standard preference panels, you just use MGSPrefsColourPropertiesViewController and MGSPrefsEditorPropertiesViewController. See ApplicationDelegate.m in the Fragaria Doc example to see how to use these view controllers with the popular preference panel library MASPreferences.

This feature is very new and still needs improvements, so it may change in potentially breaking ways.

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, asm-m68k, 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.

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

The plist structure is simple and browsing the existing definitions should provide some enlightenment. The plist keys are defined in MGSSyntaxDefinition.m.

For much deeper insight see the -colour...InRange:withRangeScanner:documentScanner methods in SMLSyntaxColouring and the detailed comments in MGSSyntaxDefinition.h.

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.