Notepad++: Insert comment-sections of same length via Macro/Shortcut?

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

tim

Posted 2014-06-12T10:06:35.377

Reputation: 302

Answers

0

Using the Plugin "Python Script" in Notepad++ and then adding a new script with the following content:

LENGTH = 70
user_input = notepad.prompt("Section-Name eingeben. Laenge ist fest auf " + str(LENGTH) + " Zeichen gesetzt", "User input", "Name hier...")
title = " " + user_input.strip() + " "
width = LENGTH - 4

line = "="
print "#" + line.center(width, "=") + "#"
print "#" + title.center(width, "=") + "#"

works very well :-) For quick access to it, just add a toolbar button to start the macro/script.

tim

Posted 2014-06-12T10:06:35.377

Reputation: 302