summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-09-13 02:44:14 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-09-13 02:44:14 (GMT)
commitacfedcf9a9a757527ba65d860790b02ffb1c8341 (patch)
tree911649c21756c7019a45da60677fc20544dd19f2
parent165859782144e453159c06909d5ddf8491ec79ff (diff)
For the do keyword -- complete braces and also insert a while
-rw-r--r--kde-emacs/kde-emacs-utils.el15
1 files changed, 11 insertions, 4 deletions
diff --git a/kde-emacs/kde-emacs-utils.el b/kde-emacs/kde-emacs-utils.el
index 3135dfa..fc984fe 100644
--- a/kde-emacs/kde-emacs-utils.el
+++ b/kde-emacs/kde-emacs-utils.el
@@ -595,7 +595,8 @@ This function does not do any hidden buffer changes."
(if (not (c-in-literal))
(let ((n nil) (o nil)
(spacep nil) (c nil)
- (oneliner nil) (cxxlambda nil) (elsekeyword nil))
+ (oneliner nil) (cxxlambda nil)
+ (clausekeyword nil) (dokeyword nil))
(save-excursion
(save-excursion
(if (re-search-forward "[a-zA-Z]" (point-at-eol) t)
@@ -620,12 +621,17 @@ This function does not do any hidden buffer changes."
(setq c (eq (car (car (c-guess-basic-syntax))) 'substatement)))
)
))
- (forward-char -3)
- (setq elsekeyword (looking-at "else"))
+
+ ; The following lines handle keywords 'else' and 'do' to insert a matching brace
+ ; if the keyword is 'do', we also insert a while.
+ (forward-char -1)
+ (setq dokeyword (looking-at "do"))
+ (setq clausekeyword (or dokeyword
+ (progn (forward-char -2) (looking-at "else"))))
)
(setq cxxlambda (looking-back "\\[.*\\]\\s-*(.*)\\(\\s-*->.*\\)?\\s-*"))
(cond
- ((or (or n elsekeyword) cxxlambda) (progn
+ ((or (or n clausekeyword) cxxlambda) (progn
(if (not spacep) (insert " "))
(self-insert-command (prefix-numeric-value arg))
(if (not c) (newline-and-indent))
@@ -639,6 +645,7 @@ This function does not do any hidden buffer changes."
(newline-and-indent)
(insert "}")
(if cxxlambda (insert ";"))
+ (if dokeyword (insert " while"))
(c-indent-line))
(c-indent-line)
))