Reputation: 994
How can I get Emacs to put padding spaces around opening brackets and operators on indentation ()?
Upvotes: 0
Views: 263
Reputation: 5494
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:
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.
Upvotes: 1
Reputation: 29772
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)))))
Upvotes: 0