How can I get Emacs to put padding spaces around opening brackets and operators on indentation ()?
You could advise the indent-region
function to apply the padding after indenting the region, like so:
(defadvice indent-region (after pad-brackets-and-operators activate)
(save-excursion
(save-restriction
(narrow-to-region (point) (mark))
(goto-char (point-min))
(while (re-search-forward " *\\([()+-*/]\\) *")
(replace-match " \\1 ")
(backward-char 1)))))
As stated in other answers there are solutions to solve your problem. But, code beautifying is not always available as an option as you may be working on another project with another coding standard. The last thing you want to be doing when contributing to a project is messing with the style of the code before you submit your patch for these reasons:
- You will submit a large DIFF which will be made up of the bugs you have fixed PLUS your beautification efforts. Many projects have policy where the only change to the code should be fixes (no style changes) unless there is an effort to change the style.
- If you want to submit a clean diff (with just your bug fixes) you would have to go back through the code undoing your style difference.
Luckily, there is a half-way-house which will keep you and maintainers sane, glasses-mode
:
Glasses minor mode (indicator o^o): Minor mode for making identifiers likeThis readable. When this mode is active, it tries to add virtual separators (like underscores) at places they belong to.
Not only will it make identifiers more readable, it will also place a space before your function brackets. glasses-mode
just 'pretends' that the code is beautiful, for your eyes only. Note-worthy at the very least.