summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-09-13 02:01:40 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-09-13 02:01:40 (GMT)
commite5247721d73dc1c43bbccafa1a33bb42aaa334c7 (patch)
tree4b8c039591813147758be83f9272041ebf47c16d
parent8fec1e36554992027468a4e2aaba158b578948f7 (diff)
When a brace is inserted for a C++ lambda, insert ; after close-brace
The emacs lisp function insert-curly-brace in kde-emacs changes the behavior of inserting a '{' in C-mode to also insert a matching '}'. This works well when definitng methods, writing if and for statements etc. However, with C++1x lambdas, there needs to be a ; following the definition of the lambda. This patch incorporates that behavior by matching lambda syntax. REQUIRES more TESTING.
-rw-r--r--kde-emacs/kde-emacs-utils.el23
1 files changed, 13 insertions, 10 deletions
diff --git a/kde-emacs/kde-emacs-utils.el b/kde-emacs/kde-emacs-utils.el
index 73afe08..1cf0e81 100644
--- a/kde-emacs/kde-emacs-utils.el
+++ b/kde-emacs/kde-emacs-utils.el
@@ -594,8 +594,8 @@ This function does not do any hidden buffer changes."
(defun insert-curly-brace (arg) (interactive "*P")
(if (not (c-in-literal))
(let ((n nil) (o nil)
- (spacep nil) (c nil)
- (oneliner nil))
+ (spacep nil) (c nil)
+ (oneliner nil) (cxxlambda nil))
(save-excursion
(save-excursion
(if (re-search-forward "[a-zA-Z]" (point-at-eol) t)
@@ -621,20 +621,23 @@ This function does not do any hidden buffer changes."
)
)
)
+ (setq cxxlambda (looking-back "\\[.*\\]\\s-*(.*)\\(\\s-*->.*\\)?\\s-*"))
(cond
- (n (progn
+ ((or n cxxlambda) (progn
(if (not spacep) (insert " "))
(self-insert-command (prefix-numeric-value arg))
(if (not c) (newline-and-indent))
(if oneliner (end-of-line))
(save-excursion
- (if c
- (progn
- (next-line 1)
- (end-of-line)
- ))
- (newline-and-indent)
- (insert "}")(c-indent-line))
+ (if c
+ (progn
+ (next-line 1)
+ (end-of-line)
+ ))
+ (newline-and-indent)
+ (insert "}")
+ (if cxxlambda (insert ";"))
+ (c-indent-line))
(c-indent-line)
))
(o (progn