0
I'm often using comments (using =====
) to divide sections within my files in the same way which look always the same, e.g.:
#===========================================#
#============== IMPORT STUFF ===============#
import blaa as foo
#===========================================#
#================ SETTINGS =================#
cfg_var1 = 1
cfg_var2 = 2
I'd like to have them the same width and the text being placed in the middle. It's annoying to copy/paste such a section and changing the section-name, e.g.:
#===========================================#
#============== ANOTHER SECTION HERE ===============#
foobar
I have to remove/add =
's to match the width of the line and to place the text in the center. Is there a way to do this automatically?
Actually, the macro would be something like:
- Define a global linewidth, e.g. 50 characters
- Create new section, i.e. enter the text which should be placed in the middle
- Calculate the length of the text; SETTINGS would have a length of 8
- Number of
=
's to place: num=LINEWIDTH-textlength-4 (4 because of two #'s and two spaces surrounding the section-name), so on each side num/2
Thanks in advance