It looks that ‘smart-operator’ minor mode is very interesting. The .el could help c programmer to add spaces embrace some kinds of operators, such as turning ‘a+b’ to ‘a + b’. I just gave a shot on it. Except the following problem, it works well. Here is the situation.
As to ‘-‘ operator, it could be used in both ‘a – b’ and ‘-1’, ‘-ENOMEM’ cases. Smart-operator covers the first use case. However, it doesn’t work with the latter. Here is the code related to this part.
(defun smart-operator-- ()
"See `smart-operator-insert'."
(interactive)
(cond ((and c-buffer-is-cc-mode (looking-back "\\- *"))
(when (looking-back "[a-zA-Z0-9_] +\\- *")
(save-excursion
(backward-char 2)
(delete-horizontal-space)))
(smart-operator-insert "-" 'middle)
(indent-according-to-mode))
(t
(smart-operator-insert "-"))))
How could I modify the code to get it worked with ‘-ENOMEM’ case?
Finally, I got some time to work on this issue. Having the small problem fixed in smart-operator.el is just fun. Paste the patch here for anyone who had the same problem.
All these cases are covered by the patch.