summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-cmds.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/cc-cmds.el')
-rw-r--r--lisp/progmodes/cc-cmds.el212
1 files changed, 106 insertions, 106 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 241fb0cf04f..84b4ed02316 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -12,8 +12,8 @@
;; 1985 Richard M. Stallman
;; Maintainer: bug-cc-mode@gnu.org
;; Created: 22-Apr-1997 (split from cc-mode.el)
-;; Version: See cc-mode.el
-;; Keywords: c languages oop
+;; Keywords: c languages
+;; Package: cc-mode
;; This file is part of GNU Emacs.
@@ -266,8 +266,10 @@ With universal argument, inserts the analysis as a comment on that line."
(symbol-value 'subword-mode))
"w"
"")))
+ ;; FIXME: Derived modes might want to use something else
+ ;; than a string for `mode-name'.
(bare-mode-name (if (string-match "\\(^[^/]*\\)/" mode-name)
- (substring mode-name (match-beginning 1) (match-end 1))
+ (match-string 1 mode-name)
mode-name)))
;; (setq c-submode-indicators
;; (if (> (length fmt) 1)
@@ -1086,104 +1088,76 @@ numeric argument is supplied, or the point is inside a literal."
(interactive "*P")
(let ((c-echo-syntactic-information-p nil)
- final-pos close-paren-inserted)
+ final-pos close-paren-inserted found-delim)
(self-insert-command (prefix-numeric-value arg))
(setq final-pos (point))
- (c-save-buffer-state (c-parse-and-markup-<>-arglists
- c-restricted-<>-arglists
- <-pos)
+;;;; 2010-01-31: There used to be code here to put a syntax-table text
+;;;; property on the new < or > and its mate (if any) when they are template
+;;;; parens. This is now done in an after-change function.
- (when c-recognize-<>-arglists
- (if (eq last-command-event ?<)
- (when (and (progn
- (backward-char)
- (= (point)
- (progn
- (c-beginning-of-current-token)
- (point))))
+ ;; Indent the line if appropriate.
+ (when (and c-electric-flag c-syntactic-indentation c-recognize-<>-arglists)
+ (setq found-delim
+ (if (eq last-command-event ?<)
+ ;; If a <, basically see if it's got "template" before it .....
+ (or (and (progn
+ (backward-char)
+ (= (point)
+ (progn (c-beginning-of-current-token) (point))))
+ (progn
+ (c-backward-token-2)
+ (looking-at c-opt-<>-sexp-key)))
+ ;; ..... or is a C++ << operator.
+ (and (c-major-mode-is 'c++-mode)
+ (progn
+ (goto-char (1- final-pos))
+ (c-beginning-of-current-token)
+ (looking-at "<<"))
+ (>= (match-end 0) final-pos)))
+
+ ;; It's a >. Either a C++ >> operator. ......
+ (or (and (c-major-mode-is 'c++-mode)
(progn
- (c-backward-token-2)
- (looking-at c-opt-<>-sexp-key)))
- (c-mark-<-as-paren (1- final-pos)))
-
- ;; It's a ">". Check if there's an earlier "<" which either has
- ;; open paren syntax already or that can be recognized as an arglist
- ;; together with this ">". Note that this won't work in cases like
- ;; "template <x, a < b, y>" but they ought to be rare.
-
- (save-restriction
- ;; Narrow to avoid that `c-forward-<>-arglist' below searches past
- ;; our position.
- (narrow-to-region (point-min) final-pos)
-
- (while (and
- (progn
- (goto-char final-pos)
- (c-syntactic-skip-backward "^<;}" nil t)
- (eq (char-before) ?<))
- (progn
- (backward-char)
- ;; If the "<" already got open paren syntax we know we
- ;; have the matching closer. Handle it and exit the
- ;; loop.
- (if (looking-at "\\s\(")
- (progn
- (c-mark->-as-paren (1- final-pos))
- (setq close-paren-inserted t)
- nil)
- t))
+ (goto-char (1- final-pos))
+ (c-beginning-of-current-token)
+ (looking-at ">>"))
+ (>= (match-end 0) final-pos))
+ ;; ...., or search back for a < which isn't already marked as an
+ ;; opening template delimiter.
+ (save-restriction
+ (widen)
+ ;; Narrow to avoid `c-forward-<>-arglist' below searching past
+ ;; our position.
+ (narrow-to-region (point-min) final-pos)
+ (goto-char final-pos)
+ (while
+ (and
+ (progn
+ (c-syntactic-skip-backward "^<;}" nil t)
+ (eq (char-before) ?<))
+ (progn
+ (backward-char)
+ (looking-at "\\s\("))))
+ (and (eq (char-after) ?<)
+ (not (looking-at "\\s\("))
+ (progn (c-backward-syntactic-ws)
+ (c-simple-skip-symbol-backward))
+ (or (looking-at c-opt-<>-sexp-key)
+ (not (looking-at c-keywords-regexp)))))))))
- (progn
- (setq <-pos (point))
- (c-backward-syntactic-ws)
- (c-simple-skip-symbol-backward))
- (or (looking-at c-opt-<>-sexp-key)
- (not (looking-at c-keywords-regexp)))
-
- (let ((c-parse-and-markup-<>-arglists t)
- c-restricted-<>-arglists
- (containing-sexp
- (c-most-enclosing-brace (c-parse-state))))
- (when (and containing-sexp
- (progn (goto-char containing-sexp)
- (eq (char-after) ?\())
- (not (eq (get-text-property (point) 'c-type)
- 'c-decl-arg-start)))
- (setq c-restricted-<>-arglists t))
- (goto-char <-pos)
- (c-forward-<>-arglist nil))
-
- ;; Loop here if the "<" we found above belongs to a nested
- ;; angle bracket sexp. When we start over we'll find the
- ;; previous or surrounding sexp.
- (if (< (point) final-pos)
- t
- (setq close-paren-inserted t)
- nil)))))))
(goto-char final-pos)
-
- ;; Indent the line if appropriate.
- (when (and c-electric-flag c-syntactic-indentation)
- (backward-char)
- (when (prog1 (or (looking-at "\\s\(\\|\\s\)")
- (and (c-major-mode-is 'c++-mode)
- (progn
- (c-beginning-of-current-token)
- (looking-at "<<\\|>>"))
- (= (match-end 0) final-pos)))
- (goto-char final-pos))
- (indent-according-to-mode)))
-
- (when (and close-paren-inserted
- (not executing-kbd-macro)
- blink-paren-function)
- ;; Note: Most paren blink functions, such as the standard
- ;; `blink-matching-open', currently doesn't handle paren chars
- ;; marked with text properties very well. Maybe we should avoid
- ;; this call for the time being?
- (funcall blink-paren-function))))
+ (when found-delim
+ (indent-according-to-mode)
+ (when (and (eq (char-before) ?>)
+ (not executing-kbd-macro)
+ blink-paren-function)
+ ;; Note: Most paren blink functions, such as the standard
+ ;; `blink-matching-open', currently doesn't handle paren chars
+ ;; marked with text properties very well. Maybe we should avoid
+ ;; this call for the time being?
+ (funcall blink-paren-function)))))
(defun c-electric-paren (arg)
"Insert a parenthesis.
@@ -1529,6 +1503,11 @@ defun."
(interactive "p")
(or arg (setq arg 1))
+ (or (not (eq this-command 'c-beginning-of-defun))
+ (eq last-command 'c-beginning-of-defun)
+ (and transient-mark-mode mark-active)
+ (push-mark))
+
(c-save-buffer-state
(beginning-of-defun-function end-of-defun-function
(start (point))
@@ -1632,6 +1611,11 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
(interactive "p")
(or arg (setq arg 1))
+ (or (not (eq this-command 'c-end-of-defun))
+ (eq last-command 'c-end-of-defun)
+ (and transient-mark-mode mark-active)
+ (push-mark))
+
(c-save-buffer-state
(beginning-of-defun-function end-of-defun-function
(start (point))
@@ -3992,16 +3976,19 @@ command to conveniently insert and align the necessary backslashes."
;; "Invalid search bound (wrong side of point)"
;; error in the subsequent re-search. Maybe
;; another fix would be needed (2007-12-08).
- (and (> (- (cdr c-lit-limits) 2) (point))
- (search-forward-regexp
- (concat "\\=[ \t]*\\(" c-current-comment-prefix "\\)")
- (- (cdr c-lit-limits) 2) t)
- (not (search-forward-regexp
- "\\(\\s \\|\\sw\\)"
- (- (cdr c-lit-limits) 2) 'limit))
- ;; The comment ender IS on its own line. Exclude
- ;; this line from the filling.
- (set-marker end (c-point 'bol))))
+; (or (<= (- (cdr c-lit-limits) 2) (point))
+; 2010-10-17 Construct removed.
+; (or (< (- (cdr c-lit-limits) 2) (point))
+ (and
+ (search-forward-regexp
+ (concat "\\=[ \t]*\\(" c-current-comment-prefix "\\)")
+ (- (cdr c-lit-limits) 2) t)
+ (not (search-forward-regexp
+ "\\(\\s \\|\\sw\\)"
+ (- (cdr c-lit-limits) 2) 'limit))
+ ;; The comment ender IS on its own line. Exclude this
+ ;; line from the filling.
+ (set-marker end (c-point 'bol))));)
;; The comment ender is hanging. Replace all space between it
;; and the last word either by one or two 'x's (when
@@ -4018,6 +4005,14 @@ command to conveniently insert and align the necessary backslashes."
(goto-char ender-start)
(current-column)))
(point-rel (- ender-start here))
+ (sentence-ends-comment
+ (save-excursion
+ (goto-char ender-start)
+ (and (search-backward-regexp
+ (c-sentence-end) (c-point 'bol) t)
+ (goto-char (match-end 0))
+ (looking-at "[ \t]*")
+ (= (match-end 0) ender-start))))
spaces)
(save-excursion
@@ -4060,7 +4055,9 @@ command to conveniently insert and align the necessary backslashes."
(setq spaces
(max
(min spaces
- (if sentence-end-double-space 2 1))
+ (if (and sentence-ends-comment
+ sentence-end-double-space)
+ 2 1))
1)))
;; Insert the filler first to keep marks right.
(insert-char ?x spaces t)
@@ -4270,8 +4267,11 @@ Optional prefix ARG means justify paragraph as well."
(let ((fill-paragraph-function
;; Avoid infinite recursion.
(if (not (eq fill-paragraph-function 'c-fill-paragraph))
- fill-paragraph-function)))
- (c-mask-paragraph t nil 'fill-paragraph arg))
+ fill-paragraph-function))
+ (start-point (point-marker)))
+ (c-mask-paragraph
+ t nil (lambda () (fill-region-as-paragraph (point-min) (point-max) arg)))
+ (goto-char start-point))
;; Always return t. This has the effect that if filling isn't done
;; above, it isn't done at all, and it's therefore effectively
;; disabled in normal code.