*autofmt.txt*		  Text Formatting Plugin

Maintainer:   Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
License:      public domain


This is a 'formatexpr' plugin.

1. Usage				    |autofmt-usage|
2. Language				    |autofmt-language|
3. Customize Unicode Line Break Property    |autofmt-customize|

{only works when 'encoding' is utf-8 or |+iconv| is enabled}

==============================================================================
1. Usage					   *autofmt-usage*
>
  :set runtimepath+=/path/to/autofmt/
  :set formatexpr=autofmt#compat#formatexpr()

Following method can be used:

  autofmt#compat#formatexpr():	  Vim compatible
  autofmt#uax14#formatexpr():	  Implementation of UAX #14
  autofmt#japanese#formatexpr():  Japanese

UAX #14: Line Breaking Properties: http://unicode.org/reports/tr14/.

==============================================================================
2. Language					   *autofmt-language* 

If you want to create your 'formatexpr' plugin, autofmt can be used as
framework.  You can define your language specific formatting easily.
For example: >

  set formatexpr=myfmt.formatexpr()

  let s:compat = autofmt#compat#import()

  let myfmt = {}
  call extend(myfmt, s:compat)

  function! myfmt.check_boundary(lst, i)
    if a:lst[a:i].c == "x"
      " It is possible to break a line before 'x'.
      return "allow_break"
    elseif a:lst[a:i].c == "y"
      " It is impossible to break a line before 'y'.
      return "no_break"
    else
      " Use default behavior.
      return call(s:compat.check_boundary, [a:lst, a:i], self)
    endif
  endfunction
<
==============================================================================
3. Customize Unicode Line Break Property	   *autofmt-customize*

uax14.vim is Pair Table-Based implementation of UAX #14.  It uses Unicode Line
Break Property.  But it is not useful for all language.  You can customize it
for your language.
For example, line break is not allowed before LEFT DOUBLE QUOTATION MARK
(U+201C) without space.  To change its behavior as Open Punctuation (e.g. "(",
"{", etc...):
>
  " Use uax14
  set formatexpr=autofmt#uax14#formatexpr()

  " Customize Line Break Property
  let s:unicode = autofmt#unicode#import()
  let s:orig_prop_line_break = s:unicode.prop_line_break
  function! s:unicode.prop_line_break(char)
    if a:char == "\u201c" || a:char == "\u2018"
      return "OP"   " Open Punctuation
    elseif a:char == "\u201d" || a:char == "\u2019"
      return "CL"   " Close Punctuation
    endif
    return call(s:orig_prop_line_break, [a:char], self)
  endfunction
<
Add this code in your vimrc.

See http://unicode.org/reports/tr14/ for more information.

 vim:tw=78:ts=8:ft=help:norl:
