Skip to content

Version 37/43 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc/tags
127 changes: 81 additions & 46 deletions README
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
This is a mirror of http://www.vim.org/scripts/script.php?script_id=294

[ALIGN/ALIGNMAPS NEEDS VIM 7.0 AS OF V29/34]
[ALIGN/ALIGNMAPS NEEDS VIM 7.0 AS OF V29/34]

Align and AlignMaps lets you align statements on their equal signs, make comment boxes, align comments, align declarations, etc.
Align and AlignMaps lets you align statements on their equal signs, make
comment boxes, align comments, align declarations, etc.

Note: this plugin is not a left&right margin justification tool! See vimscript#177, vimscript#2324, or vimscript#3728 for that.
Note: if you have vim 7.1 or later, your vimball should unpack just fine without having to update it.
Note: this plugin is not a left&right margin justification tool! See
vimscript#177, vimscript#2324, or vimscript#3728 for that.
Note: if you have vim 7.1 or later, your vimball should unpack just fine
without having to update it.

There are two basic commands provided by this package:

AlignCtrl options sep1 sep2 sep3 ...
[range]Align sep1 sep2 sep3 ...
AlignCtrl options sep1 sep2 sep3 ...
[range]Align sep1 sep2 sep3 ...

The "sep#" are regular expressions which describe separators that delineate fields; Align will line up the separators. The range may be any Vim range, _including_ visual-blocks. Align works on lines of the form:
(ws==whitespace, sep==separator, field==text)
The "sep#" are regular expressions which describe separators that delineate
fields; Align will line up the separators. The range may be any Vim range,
_including_ visual-blocks. Align works on lines of the form: (ws==whitespace,
sep==separator, field==text)

ws-field-ws-sep-ws-field-ws-sep-ws-field-...
ws-field-ws-sep-ws-field-ws-sep-ws-field-...
Expand All @@ -22,18 +27,27 @@ Note that white-space (ws) surrounding separators is ignored.

The Align package includes:

Align : the basic alignment command
AlignCtrl : provides options for the next call to :Align
AlignMaps : many three or four key maps which support aligning C/C++ style declarations, ()?..:.., expressions, C/C++ comments, numbers, C preprocessor definitions, tables based on tabs or spaces, and more.
Align : the basic alignment command
AlignCtrl : provides options for the next call to :Align
AlignMaps : many three or four key maps which support aligning C/C++ style
declarations, ()?..:.., expressions, C/C++ comments, numbers, C
preprocessor definitions, tables based on tabs or spaces, and
more.

In addition, AutoAlign (vimscript#884) uses the Align function to align =s as you type.
In addition, AutoAlign (vimscript#884) uses the Align function to align =s as
you type.

Align handles alignment on multiple separators, not just the first one, and the separators may be the same across the line or different. With AlignCtrl one may specify that separators are cyclic (re-used sequentially) or equivalent (all separators are simultaneously active).
Align handles alignment on multiple separators, not just the first one, and the
separators may be the same across the line or different. With AlignCtrl one
may specify that separators are cyclic (re-used sequentially) or equivalent
(all separators are simultaneously active).

There are several options to help with deciding what to do with initial white space. By default Align re-uses the first line's initial white space, but one may use AlignCtrl to retain or remove each line's initial white space.

The <Align.vim> and <AlignMaps.vim> files are plugins and require vim 6.1 or higher.
There are several options to help with deciding what to do with initial white
space. By default Align re-uses the first line's initial white space, but one
may use AlignCtrl to retain or remove each line's initial white space.

The <Align.vim> and <AlignMaps.vim> files are plugins and require vim 6.1 or
higher.

EXAMPLES:

Expand All @@ -46,8 +60,8 @@ EXAMPLES:

:AlignCtrl =lp1P1I
which means:
= all separators are equivalent
l fields will be left-justified
= all separators are equivalent
l fields will be left-justified
p1 pad one space before each separator
P1 pad one space after each separator
I preserve and apply the first line's leading white space to all
Expand All @@ -56,74 +70,95 @@ EXAMPLES:
:help align
Gives help for Align


ALIGNMENT CONTROL

Alignment control allows for left or right justification or centering of fields, cyclic (sequentially active) or equivalent (simultaneously active) regular expressions to specify field separators, initial white space control, optional visual-block use (ie. apply Alignment only within a block), user-specified white-space padding about separators, and multiple separators.
Alignment control allows for left or right justification or centering of
fields, cyclic (sequentially active) or equivalent (simultaneously active)
regular expressions to specify field separators, initial white space control,
optional visual-block use (ie. apply Alignment only within a block),
user-specified white-space padding about separators, and multiple separators.

MANY ALIGNMENT MAPS

AlignMaps.vim provides a number of maps which make using this package easy. They typically either apply to the range 'a,. (from mark a to current line) or use the visual-selection (V, v, or ctrl-v selected):
AlignMaps.vim provides a number of maps which make using this package easy.
They typically either apply to the range 'a,. (from mark a to current line) or
use the visual-selection (V, v, or ctrl-v selected):

\t= : align assignments (don't count logic, like == or !=)
\t, : align on commas
\t| : align on vertical bars (|)
\tsp : align on whitespace
\tt : align LaTeX tabular tables

\t= : align assignments (don't count logic, like == or !=)
\t, : align on commas
\t| : align on vertical bars (|)
\tsp : align on whitespace
\tt : align LaTeX tabular tables
AlignMaps also provides some internally complex maps for aligning C
declarations, Ansi C function arguments, html tables, LaTeX tabulars, and
trailing comments:

AlignMaps also provides some internally complex maps for aligning C declarations, Ansi C function arguments, html tables, LaTeX tabulars, and trailing comments:
\acom : align comments
\adec : align C declarations (one variable per line)
\afnc : align ansi-style C function input arguments
\Htd : align html tables

\acom : align comments
\adec : align C declarations (one variable per line)
\afnc : align ansi-style C function input arguments
\Htd : align html tables

To see some examples of this, check out

http://www.drchip.org/astronaut/vim/align.html#Examples

(the proportional fonts used by most browsers in showing you this page preclude showing the examples here). The help for Align and AlignCtrl also contains many examples.
(for those of you who prefer not to have the maps that AlignMaps.vim provides, simply remove the AlignMapsPlugin.vim from .vim/plugin and AlignMaps.vim from .vim/autoload - that's why AlignMaps is separate from Align)
(the proportional fonts used by most browsers in showing you this page preclude
showing the examples here). The help for Align and AlignCtrl also contains many
examples.
(for those of you who prefer not to have the maps that AlignMaps.vim provides,
simply remove the AlignMapsPlugin.vim from .vim/plugin and AlignMaps.vim from
.vim/autoload - that's why AlignMaps is separate from Align)

ALIGNMENT ON VISUAL BLOCKS AND g,v-LIKE CONTROL

Sometimes one wants to align only a subset of text in a range, based on patterns or column extents. Align supports both types of restrictions!

Sometimes one wants to align only a subset of text in a range, based on
patterns or column extents. Align supports both types of restrictions!

Visual-block selection may be used to restrict Align to operate only
within that visual block.

AlignCtrl supports "g" and "v" patterns that restrict Align to

AlignCtrl supports "g" and "v" patterns that restrict Align to
operate on lines which match (or don't match, respectively) those
patterns.

NEW STUFF:

There's a number of new AlignCtrl options:

- allows one to skip a separator (treat it as part of a field)
+ repeat the last lrc justification (ex. lr+ == lrrrrrr... )
: treat the rest of the line as a field; acts as a modifier
to the last lrc.
to the last lrc.
< left-justify the separator
> right-justify the separator
| center the separator

These are, except for the ":", cyclic parameters. In other words, >< is equivalent to ><><><><... . Thus separators can be of differing lengths (ex. -\+ as a separator pattern can match -, --, ---, etc and the separators will be left/right/center justified as you wish).

To get automatic, as-you-type, aligning of = in the C, vimL, and other languages, check out vimscript#884 for several ftplugins (which use Align).
These are, except for the ":", cyclic parameters. In other words, >< is
equivalent to ><><><><... . Thus separators can be of differing lengths (ex.
-\+ as a separator pattern can match -, --, ---, etc and the separators will be
left/right/center justified as you wish).

To get automatic, as-you-type, aligning of = in the C, vimL, and other
languages, check out vimscript#884 for several ftplugins (which use Align).

Alternative Aligners:
Gergely Kontra's vimscript#176
Gergely Kontra's vimscript#176

Thank you for rating Align!

---------------------------------------
DISCUSSION and COMMENTS:
---------------------------------------

Please use email for bugs. Enjoy!
Please use email for bugs. Enjoy!

(alpha/beta version available at
http://mysite.verizon.net/astronaut/vim/index.html#ALIGN)

(alpha/beta version available at http://mysite.verizon.net/astronaut/vim/index.html#ALIGN)
install details

You'll need to have plugins enabled: in your home directory, have at least the
following two lines in your .vimrc file:
set nocp
filetype plugin on
68 changes: 40 additions & 28 deletions autoload/Align.vim
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
" Align: tool to align multiple fields based on one or more separators
" Author: Charles E. Campbell, Jr.
" Date: Jun 18, 2012
" Version: 36
" Author: Charles E. Campbell
" Date: Mar 12, 2013
" Version: 37
" GetLatestVimScripts: 294 1 :AutoInstall: Align.vim
" GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim
" Copyright: Copyright (C) 1999-2012 Charles E. Campbell, Jr. {{{1
" Copyright: Copyright (C) 1999-2012 Charles E. Campbell {{{1
" Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free,
Expand All @@ -25,7 +25,7 @@
if exists("g:loaded_Align") || &cp
finish
endif
let g:loaded_Align = "v36"
let g:loaded_Align = "v37"
if v:version < 700
echohl WarningMsg
echo "***warning*** this version of Align needs vim 7.0"
Expand All @@ -43,7 +43,11 @@ set cpo&vim
" ---------------------------------------------------------------------
" Options: {{{1
if !exists("g:Align_xstrlen")
if &enc == "latin1" || $LANG == "en_US.UTF-8" || !has("multi_byte")
if exists("g:drawit_xstrlen")
let g:Align_xstrlen= g:drawit_xstrlen
elseif exists("g:netrw_xstrlen")
let g:Align_xstrlen= g:netrw_xstrlen
elseif &enc == "latin1" || !has("multi_byte")
let g:Align_xstrlen= 0
else
let g:Align_xstrlen= 1
Expand Down Expand Up @@ -529,19 +533,19 @@ fun! Align#Align(hasctrl,...) range
" call Decho(" ")
" call Decho("---- Pass ".pass.": ----")

let line= begline
while line <= endline
let curline= begline
while curline <= endline
" Process each line
let txt = getline(line)
let txt = getline(curline)
" call Decho(" ")
" call Decho("Pass".pass.": Line ".line." <".txt.">")
" call Decho("Pass".pass.": Line ".curline." <".txt.">")

" AlignGPat support: allows a selector pattern (akin to g/selector/cmd )
if exists("s:AlignGPat")
" call Decho("Pass".pass.": AlignGPat<".s:AlignGPat.">")
if match(txt,s:AlignGPat) == -1
" call Decho("Pass".pass.": skipping")
let line= line + 1
let curline= curline + 1
continue
endif
endif
Expand All @@ -551,20 +555,20 @@ fun! Align#Align(hasctrl,...) range
" call Decho("Pass".pass.": AlignVPat<".s:AlignVPat.">")
if match(txt,s:AlignVPat) != -1
" call Decho("Pass".pass.": skipping")
let line= line + 1
let curline= curline + 1
continue
endif
endif

" Always skip blank lines
if match(txt,'^\s*$') != -1
" call Decho("Pass".pass.": skipping")
let line= line + 1
let curline= curline + 1
continue
endif

" Extract visual-block selected text (init bgntxt, endtxt)
let txtlen= s:Strlen(txt)
let txtlen= s:Strlen(txt)
if begcol > 0
" Record text to left of selected area
let bgntxt= strpart(txt,0,begcol)
Expand Down Expand Up @@ -655,7 +659,7 @@ fun! Align#Align(hasctrl,...) range
if alignop == '*' && exists("g:AlignSkip") && type(g:AlignSkip) == 2
" call Decho("Pass".pass.": endfield=match(txt<".txt.">,seppat<".seppat.">,bgnfield=".bgnfield.")=".endfield." alignop=".alignop)
" a '*' acts like a '-' while the g:AlignSkip function reference is true except that alignop doesn't advance
while g:AlignSkip(line,endfield) && endfield != -1
while g:AlignSkip(curline,endfield) && endfield != -1
let endfield = match(txt,seppat,skipfield)
let sepfield = matchend(txt,seppat,skipfield)
let skipfield = sepfield
Expand Down Expand Up @@ -688,22 +692,20 @@ fun! Align#Align(hasctrl,...) range
let field = bgntxt.field
let bgntxt= ""
endif
let fieldlen = s:Strlen(field)
let sFieldSize = "FieldSize_".ifield
if !exists(sFieldSize)
let fieldlen= s:Strlen(field)
if !exists("FieldSize_{ifield}")
let FieldSize_{ifield}= fieldlen
" call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">")
" call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field."> (init)")
elseif fieldlen > FieldSize_{ifield}
let FieldSize_{ifield}= fieldlen
" call Decho("Pass".pass.": oset FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">")
" call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field."> (fieldlen>FieldSize_".ifield.")")
endif
let sSepSize= "SepSize_".ifield
if !exists(sSepSize)
if !exists("SepSize_{ifield}")
let SepSize_{ifield}= seplen
" call Decho(" set SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">")
" call Decho("Pass".pass.": set SepSize_{".ifield."}=".SepSize_{ifield}." <".field."> (init)")
elseif seplen > SepSize_{ifield}
let SepSize_{ifield}= seplen
" call Decho("Pass".pass.": oset SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">")
" call Decho("Pass".pass.": set SepSize_{".ifield."}=".SepSize_{ifield}." <".field."> (seplen>SepSize_".ifield.")")
endif

else
Expand All @@ -714,6 +716,8 @@ fun! Align#Align(hasctrl,...) range
let alignprepad = strpart(alignprepad,1).strpart(alignprepad,0,1)
let alignpostpad = strpart(alignpostpad,1).strpart(alignpostpad,0,1)
let field = substitute(strpart(txt,bgnfield,endfield-bgnfield),'^\s*\(.\{-}\)\s*$','\1','')
" call Decho("Pass".pass.": alignprepad <".alignprepad."> prepad =".prepad)
" call Decho("Pass".pass.": alignpostpad<".alignpostpad."> postpad=".postpad)
if s:AlignLeadKeep == 'W'
let field = bgntxt.field
let bgntxt= ""
Expand All @@ -724,21 +728,26 @@ fun! Align#Align(hasctrl,...) range
endif
let fieldlen = s:Strlen(field)
let sep = s:MakeSpace(prepad).strpart(txt,endfield,sepfield-endfield).s:MakeSpace(postpad)
" call Decho("Pass".pass.": sep<".sep."> (after prepad, sepfield-endfield,postpad)")
if seplen < SepSize_{ifield}
if alignsepop == "<"
" left-justify separators
let sep = sep.s:MakeSpace(SepSize_{ifield}-seplen)
" call Decho("Pass".pass.": sep<".sep."> (left-justified)")
elseif alignsepop == ">"
" right-justify separators
let sep = s:MakeSpace(SepSize_{ifield}-seplen).sep
" call Decho("Pass".pass.": sep<".sep."> (right-justified)")
else
" center-justify separators
let sepleft = (SepSize_{ifield} - seplen)/2
let sepright = SepSize_{ifield} - seplen - sepleft
let sep = s:MakeSpace(sepleft).sep.s:MakeSpace(sepright)
" call Decho("Pass".pass.": sep<".sep."> (center-justified)")
endif
endif
let spaces = FieldSize_{ifield} - fieldlen
" call Decho("Pass".pass.": spaces=[FieldSize_".ifield."=".FieldSize_{ifield}."] - [fieldlen=".fieldlen."]=".spaces)
" call Decho("Pass".pass.": Field #".ifield."<".field."> spaces=".spaces." be[".bgnfield.",".endfield."] pad=".prepad.','.postpad." FS_".ifield."<".FieldSize_{ifield}."> sep<".sep."> ragged=".ragged." doend=".doend." alignop<".alignop.">")

" Perform alignment according to alignment style justification
Expand Down Expand Up @@ -786,18 +795,20 @@ fun! Align#Align(hasctrl,...) range

if pass == 2
" Write altered line to buffer
" call Decho("Pass".pass.": bgntxt<".bgntxt."> line=".line)
" call Decho("Pass".pass.": bgntxt<".bgntxt."> curline=".curline)
" call Decho("Pass".pass.": newtxt<".newtxt.">")
" call Decho("Pass".pass.": endtxt<".endtxt.">")
keepj call setline(line,bgntxt.newtxt.endtxt)
keepj call setline(curline,bgntxt.newtxt.endtxt)
endif
" call Decho("Pass".pass.": line#".curline."<".getline(".")."> (end-of-while)")

let line = line + 1
endwhile " line loop
let curline = curline + 1
endwhile " curline loop

let pass= pass + 1
endwhile " pass loop
" call Decho("end of two pass loop")
" call Decho("ENDWHILE: cursor at (".line(".").",".col(".").") curline#".curline)

" restore original leading whitespace
if s:AlignLeadKeep == 'W'
Expand Down Expand Up @@ -1059,6 +1070,7 @@ fun! s:Strlen(x)
call setline(line("."),a:x)
let ret= virtcol("$") - 1
d
keepj norm! k
let &l:mod= modkeep

else
Expand Down
Loading