Skip to content

Instantly share code, notes, and snippets.

View martinh's full-sized avatar

Martin Hedenfalk martinh

  • Stockholm, Sweden
View GitHub Profile

Keybase proof

I hereby claim:

  • I am martinh on github.
  • I am martinh (https://keybase.io/martinh) on keybase.
  • I have a public key whose fingerprint is 7B3C F22E 9DE8 7300 AEB5 1D8D 68C4 7593 9ACE 10A8

To claim this, I am signing this object:

@martinh
martinh / gist:1159097
Created August 20, 2011 13:16
Automatically hard-wrap text in Vico
(global NSMaxRange (do (range) (+ (range first) (range second))))
(global NSBackwardsSearch 4)
(set $textwidth 72) ; set to zero to disable
(if (defined $autoTextWrapEventId)
(eventManager remove:$autoTextWrapEventId))
(set $autoTextWrapEventId (eventManager on:"didModifyDocument" do:(do (doc range delta)
; Only wrap lines when inserting, and only in text documents, not in source code.
(if (and (gt $textwidth 0) (gt delta 0) (((doc language) name) hasPrefix:"text."))
; The range parameter is wrapped in an NSValue object.
(set range (range rangeValue))