; -!- emf -!- ; This is part of the JASSPA MicroEmacs macro files ; Copyright (C) 2006 JASSPA (www.jasspa.com) ; See the file me.emf for copying and conditions. ; ; Created: Thu Nov 30 23:31:29 2006 ; Synopsis: Vertical column character alignment ; Authors: Jon Green ; Given a region then promt the user for a set of characters to be aligned. ; Within the given region then the maximum absolute column position is ; determined and all of the specified charcters are aligned vertically by ; insertion of a space immediately before the specified character. define-macro align-char ; Test the region first before we destroy the region by executing some ; macro commands 0 show-region !if &equ &band $result 5 5 !if ¬ &band $result 2 3 show-region !endif ; Save the position for later. set-position "\x82" ; Determine if there is a hilight region in effect. -2 show-region set-variable #l0 $window-line set-variable #l2 $window-col 2 show-region set-variable #l1 $window-line set-variable #l3 $window-col !if &les #l0 #l1 ; If we are in the firat column then back up a line as the user ; will have selected the previous lines not this one. !if &equ #l3 0 set-variable #l1 &sub #l1 1 !endif !elif &gre #l0 #l1 !if &equ #l2 0 set-variable #l0 &sub #l0 1 !endif ; Swap #l0<=>#l1, #l2<=>#l3 set-variable #l4 #l0 set-variable #l0 #l1 set-variable #l1 #l4 !endif !force -3 show-region !force 3 show-region !force -1 show-region !else ; No region assume a single line. set-position "\x82" set-variable #l0 $window-line set-variable #l1 #l0 !endif ; If there is a numeric argument then we loose the region and use the ; numeric argument as the number of lines to process. !if @? goto-position "\x82" set-variable #l0 $window-line !if &les @# 0 ; -ve argument then abort. !abort !elif &gre @# 1 set-variable #l1 &add #l0 &sub @# 1 !endif !endif ; Get the character to align to. set-variable #l9 @ml2 "Alignment character" "=" ; Goto the first line of the region and find the maximum column position ; in the region. goto-line #l0 set-variable #l4 0 !repeat beginning-of-line ; Find the character in the line. !while &and ¬ &sin @wc #l9 ¬ &seq @wc "\n" forward-char !done ; Determine current column position. !if &and &and &sin @wc #l9 &les $window-acol $buffer-fill-col &les #l4 $window-acol set-variable #l4 $window-acol !endif ; Next line - check for end of buffer or end of region. !force forward-line !until &or ¬ $status &gre $window-line #l1 ; Go back and adjust all of the colum positions for the search ; characters. goto-line #l0 !repeat beginning-of-line ; Find the character in the line. !while &and ¬ &sin @wc #l9 ¬ &seq @wc "\n" forward-char !done ; Pad out the line at the current cursor position until we reach our ; target column position. !while &and &and &sin @wc #l9 &les $window-acol $buffer-fill-col &les $window-acol #l4 insert-string " " !done ; Next line - check for end of buffer or end of region. !force forward-line !until &or ¬ $status &gre $window-line #l1 ; Restore our position. goto-position "\x82" !emaccro