m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Way for macro to know it's indentation in source?


From: m4-discuss
Subject: Way for macro to know it's indentation in source?
Date: Mon, 08 May 2017 10:00:30 -0500

Might there be a way for a macro to know the number of
spaces to the left of itself on the line that the macro appears in the source?

--
To preserve indentation , my work around is to pass in
the number spaces that the macro output should be indented;
would be nice to automate.

--
thanks,
Tom

--
Example workaround (sorry, an overly messy example):

md_dnl The number of spaces to indent is passed in as $1.

m4_changequote(`[<{', `}>]')
m4_changecom(`#<{',`}>#')

m4_define(_ED_spaces, [<{m4_format(%[<{$1}>]s, [<{ }>])}>])                     
               
                                                                                
               
m4_define(_SH_cmd_subst_assign, [<{m4_dnl                                       
               
_ED_spaces([<{$1}>])# errexit workaround. errexit in foo() breaks in: x=$(foo 1 
2 3)           
_ED_spaces([<{$1}>])_SH_cmd_subst_assign_tmpf=$(mktemp ~/tmp/$2[<{.XXXXX}>])    
               
_ED_spaces([<{$1}>])$3 $4 > $_SH_cmd_subst_assign_tmpf                          
               
_ED_spaces([<{$1}>])$2=$(< $_SH_cmd_subst_assign_tmpf)                          
               
_ED_spaces([<{$1}>])rm -f $_SH_cmd_subst_assign_tmpf                            
               
_ED_spaces([<{$1}>])unset _SH_cmd_subst_assign_tmpf}>]m4_dnl                    
               
)                                                                               
               
                                                                                
               
    #<{                                                                         
               
                                                                                
               
    $ _m42 <<< '_SH_cmd_subst_assign([<{4}>],[<{rem_cfg_dir}>], 
[<{rem_cfg_dir}>], [<{-a asd}>])'
        # errexit workaround. errexit in foo() breaks in: x=$(foo 1 2 3)        
               
        _SH_cmd_subst_assign_tmpf=$(mktemp ~/tmp/rem_cfg_dir.XXXXX)             
               
        rem_cfg_dir -a asd > $_SH_cmd_subst_assign_tmpf                         
               
        rem_cfg_dir=$(< $_SH_cmd_subst_assign_tmpf)                             
               
        rm -f $_SH_cmd_subst_assign_tmpf                                        
               
        unset _SH_cmd_subst_assign_tmpf                                         
               
                                                                                
               
    }>#                                                                         
              



reply via email to

[Prev in Thread] Current Thread [Next in Thread]