Instead of this solution that requires to restart Electrum, I'm providing another one that doesn't have this requirement.
You don't need to restart Electrum with this. When you change the gap limit, it does so instantly and generates new addresses up to your gap limit. If they show up with a red background, which signals they are still below your gap limit (this shouldn't happen), then a restart should remove the red background.
The solution you have given generates new addresses beyond the gap limit. Since these addresses are beyond the gap limit, they will always a red background.