;;; cc-cmds.el --- user level commands for CC Mode
-;; Copyright (C) 1985, 1987, 1992-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2016 Free Software Foundation, Inc.
;; Authors: 2003- Alan Mackenzie
;; 1998- Martin Stjernholm
"a" "")
(if c-hungry-delete-key "h" "")
(if (and
- ;; subword might not be loaded.
- (boundp 'subword-mode)
- (symbol-value 'subword-mode))
+ ;; (cc-)subword might not be loaded.
+ (boundp 'c-subword-mode)
+ (symbol-value 'c-subword-mode))
+ ;; FIXME: subword-mode already comes with its
+ ;; own lighter!
"w"
"")))
;; FIXME: Derived modes might want to use something else
deletes forward. Otherwise it deletes backward.
Note: This is the way in XEmacs to choose the correct action for the
-\[delete] key, whichever key that means. Other flavors don't use this
+[delete] key, whichever key that means. Other flavors don't use this
function to control that."
(interactive "*P")
(if (and (fboundp 'delete-forward-p)
backward using `c-hungry-backspace'.
Note: This is the way in XEmacs to choose the correct action for the
-\[delete] key, whichever key that means. Other flavors don't use this
+[delete] key, whichever key that means. Other flavors don't use this
function to control that."
(interactive)
(if (and (fboundp 'delete-forward-p)
(interactive "*P")
(let ((c-echo-syntactic-information-p nil)
- final-pos close-paren-inserted found-delim case-fold-search)
+ final-pos found-delim case-fold-search)
(self-insert-command (prefix-numeric-value arg))
(setq final-pos (point))
(looking-at "<<"))
(>= (match-end 0) final-pos)))
- ;; It's a >. Either a C++ >> operator. ......
- (or (and (c-major-mode-is 'c++-mode)
+ ;; It's a >. Either a template/generic terminator ...
+ (or (c-get-char-property (1- final-pos) 'syntax-table)
+ ;; or 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))
- ;; ...., 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)))))))))
+ (>= (match-end 0) final-pos))))))
(goto-char final-pos)
(when found-delim
(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)))))
+ ;; From now (2016-01-01), the syntax-table text properties on < and >
+ ;; are applied in an after-change function, not during redisplay. Hence
+ ;; we no longer need to call (sit-for 0) for blink paren to work.
+ (funcall blink-paren-function)))))
(defun c-electric-paren (arg)
"Insert a parenthesis.
(declare-function subword-forward "subword" (&optional arg))
(declare-function subword-backward "subword" (&optional arg))
+(cond
+ ((and (fboundp 'subword-mode) (not (fboundp 'c-subword-mode)))
+ ;; Recent Emacsen come with their own subword support. Use that.
+ (define-obsolete-function-alias 'c-subword-mode 'subword-mode "24.3")
+ (define-obsolete-variable-alias 'c-subword-mode 'subword-mode "24.3"))
+ (t
+ ;; Autoload directive for emacsen that doesn't have an older CC Mode
+ ;; version in the dist.
+ (autoload 'c-subword-mode "cc-subword"
+ "Mode enabling subword movement and editing keys." t)))
+
+(declare-function c-forward-subword "ext:cc-subword" (&optional arg))
+(declare-function c-backward-subword "ext:cc-subword" (&optional arg))
+
;; "nomenclature" functions + c-scope-operator.
(defun c-forward-into-nomenclature (&optional arg)
"Compatibility alias for `c-forward-subword'."
(interactive "p")
- (require 'subword)
- (subword-forward arg))
-(make-obsolete 'c-forward-into-nomenclature 'subword-forward "23.2")
+ (if (fboundp 'subword-mode)
+ (progn
+ (require 'subword)
+ (subword-forward arg))
+ (require 'cc-subword)
+ (c-forward-subword arg)))
+(make-obsolete 'c-forward-into-nomenclature
+ (if (fboundp 'subword-mode) 'subword-forward 'c-forward-subword)
+ "23.2")
(defun c-backward-into-nomenclature (&optional arg)
"Compatibility alias for `c-backward-subword'."
(interactive "p")
- (require 'subword)
- (subword-backward arg))
-(make-obsolete 'c-backward-into-nomenclature 'subword-backward "23.2")
+ (if (fboundp 'subword-mode)
+ (progn
+ (require 'subword)
+ (subword-backward arg))
+ (require 'cc-subword)
+ (c-backward-subword arg)))
+(make-obsolete
+ 'c-backward-into-nomenclature
+ (if (fboundp 'subword-mode) 'subword-backward 'c-backward-subword) "23.2")
(defun c-scope-operator ()
"Insert a double colon scope operator at point.
;; be the return type of a function, or the like. Exclude
;; this case.
(c-syntactic-re-search-forward
- (concat "[;=\(\[{]\\|\\("
+ (concat "[;=([{]\\|\\("
c-opt-block-decls-with-vars-key
"\\)")
eo-block t t t)
(match-beginning 1) ; Is there a "struct" etc., somewhere?
(not (eq (char-before) ?_))
- (c-syntactic-re-search-forward "[;=\(\[{]" eo-block t t t)
+ (c-syntactic-re-search-forward "[;=([{]" eo-block t t t)
(eq (char-before) ?\{)
bod)))))
(car (c-beginning-of-decl-1
;; NOTE: If we're in a K&R region, this might be the start
;; of a parameter declaration, not the actual function.
+ ;; It might also leave us at a label or "label" like
+ ;; "private:".
(and least-enclosing ; LIMIT for c-b-of-decl-1
(c-safe-position least-enclosing paren-state)))))
;; Has the declaration we've gone back to got braces?
- (setq brace-decl-p
- (save-excursion
+ (or (eq decl-result 'label)
+ (setq brace-decl-p
+ (save-excursion
(and (c-syntactic-re-search-forward "[;{]" nil t t)
(or (eq (char-before) ?\{)
(and c-recognize-knr-p
;; ';' in a K&R argdecl. In
;; that case the declaration
;; should contain a block.
- (c-in-knr-argdecl))))))
+ (c-in-knr-argdecl)))))))
(cond
- ((= (point) kluge-start) ; might be BOB or unbalanced parens.
+ ((or (eq decl-result 'label) ; e.g. "private:" or invalid syntax.
+ (= (point) kluge-start)) ; might be BOB or unbalanced parens.
'outwith-function)
((eq decl-result 'same)
(if brace-decl-p
(or (not (eq this-command 'c-beginning-of-defun))
(eq last-command 'c-beginning-of-defun)
- (and transient-mark-mode mark-active)
+ (c-region-is-active-p)
(push-mark))
(c-save-buffer-state
- (beginning-of-defun-function end-of-defun-function
+ (beginning-of-defun-function
+ end-of-defun-function
(start (point))
- (paren-state (copy-tree (c-parse-state))) ; This must not share list
- ; structure with other users of c-state-cache.
+ (paren-state (c-parse-state))
(orig-point-min (point-min)) (orig-point-max (point-max))
- lim ; Position of { which has been widened to.
+ lim ; Position of { which has been widened to.
where pos case-fold-search)
(save-restriction
;; Move back out of any macro/comment/string we happen to be in.
(c-beginning-of-macro)
- (setq pos (c-literal-limits))
- (if pos (goto-char (car pos)))
+ (setq pos (c-literal-start))
+ (if pos (goto-char pos))
(setq where (c-where-wrt-brace-construct))
(or (not (eq this-command 'c-end-of-defun))
(eq last-command 'c-end-of-defun)
- (and transient-mark-mode mark-active)
+ (c-region-is-active-p)
(push-mark))
(c-save-buffer-state
- (beginning-of-defun-function end-of-defun-function
+ (beginning-of-defun-function
+ end-of-defun-function
(start (point))
- (paren-state (copy-tree (c-parse-state))) ; This must not share list
- ; structure with other users of c-state-cache.
+ (paren-state (c-parse-state))
(orig-point-min (point-min)) (orig-point-max (point-max))
lim
where pos case-fold-search)
;; Move back out of any macro/comment/string we happen to be in.
(c-beginning-of-macro)
- (setq pos (c-literal-limits))
- (if pos (goto-char (car pos)))
+ (setq pos (c-literal-start))
+ (if pos (goto-char pos))
(setq where (c-where-wrt-brace-construct))
;; Do we need to move forward from the brace to the semicolon?
(when (eq arg 0)
- (if (c-in-function-trailer-p) ; after "}" of struct/enum, etc.
+ (if (c-in-function-trailer-p) ; after "}" of struct/enum, etc.
(c-syntactic-re-search-forward ";"))
(setq pos (point))
(c-save-buffer-state
(beginning-of-defun-function end-of-defun-function
where pos name-end case-fold-search)
-
+
(save-restriction
(widen)
(save-excursion
;; Move back out of any macro/comment/string we happen to be in.
(c-beginning-of-macro)
- (setq pos (c-literal-limits))
- (if pos (goto-char (car pos)))
+ (setq pos (c-literal-start))
+ (if pos (goto-char pos))
(setq where (c-where-wrt-brace-construct))
(looking-at c-symbol-key))
(match-string-no-properties 0))
- ((looking-at "DEFUN\\_>")
+ ((looking-at "DEFUN\\s-*(") ;"DEFUN\\_>") think of XEmacs!
;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory
;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK
(down-list 1)
(or (save-restriction
(c-narrow-to-most-enclosing-decl-block nil)
- ;; Note: Some code duplication in `c-beginning-of-defun' and
- ;; `c-end-of-defun'.
- (catch 'exit
- (let ((start (point))
- (paren-state (c-parse-state))
- lim pos end-pos)
- (unless (c-safe
- (goto-char (c-least-enclosing-brace paren-state))
+ ;; Note: Some code duplication in `c-beginning-of-defun' and
+ ;; `c-end-of-defun'.
+ (catch 'exit
+ (let ((start (point))
+ (paren-state (c-parse-state))
+ lim pos end-pos)
+ (unless (c-safe
+ (goto-char (c-least-enclosing-brace paren-state))
;; If we moved to the outermost enclosing paren
;; then we can use c-safe-position to set the
;; limit. Can't do that otherwise since the
;; earlier paren pair on paren-state might very
;; well be part of the declaration we should go
;; to.
- (setq lim (c-safe-position (point) paren-state))
- t)
- ;; At top level. Make sure we aren't inside a literal.
- (setq pos (c-literal-limits
- (c-safe-position (point) paren-state)))
- (if pos (goto-char (car pos))))
-
- (when (c-beginning-of-macro)
- (throw 'exit
- (cons (point)
- (save-excursion
- (c-end-of-macro)
- (forward-line 1)
- (point)))))
-
- (setq pos (point))
- (when (or (eq (car (c-beginning-of-decl-1 lim)) 'previous)
- (= pos (point)))
- ;; We moved back over the previous defun. Skip to the next
- ;; one. Not using c-forward-syntactic-ws here since we
- ;; should not skip a macro. We can also be directly after
- ;; the block in a `c-opt-block-decls-with-vars-key'
- ;; declaration, but then we won't move significantly far
- ;; here.
- (goto-char pos)
- (c-forward-comments)
-
- (when (and near (c-beginning-of-macro))
- (throw 'exit
- (cons (point)
- (save-excursion
- (c-end-of-macro)
- (forward-line 1)
- (point))))))
-
- (if (eobp) (throw 'exit nil))
-
- ;; Check if `c-beginning-of-decl-1' put us after the block in a
- ;; declaration that doesn't end there. We're searching back and
- ;; forth over the block here, which can be expensive.
- (setq pos (point))
- (if (and c-opt-block-decls-with-vars-key
- (progn
- (c-backward-syntactic-ws)
- (eq (char-before) ?}))
- (eq (car (c-beginning-of-decl-1))
- 'previous)
- (save-excursion
- (c-end-of-decl-1)
- (and (> (point) pos)
- (setq end-pos (point)))))
- nil
- (goto-char pos))
-
- (if (and (not near) (> (point) start))
- nil
+ (setq lim (c-safe-position (point) paren-state))
+ t)
+ ;; At top level. Make sure we aren't inside a literal.
+ (setq pos (c-literal-start
+ (c-safe-position (point) paren-state)))
+ (if pos (goto-char pos)))
+
+ (when (c-beginning-of-macro)
+ (throw 'exit
+ (cons (point)
+ (save-excursion
+ (c-end-of-macro)
+ (forward-line 1)
+ (point)))))
- ;; Try to be line oriented; position the limits at the
- ;; closest preceding boi, and after the next newline, that
- ;; isn't inside a comment, but if we hit a neighboring
- ;; declaration then we instead use the exact declaration
- ;; limit in that direction.
- (cons (progn
(setq pos (point))
- (while (and (/= (point) (c-point 'boi))
- (c-backward-single-comment)))
- (if (/= (point) (c-point 'boi))
- pos
- (point)))
- (progn
- (if end-pos
- (goto-char end-pos)
- (c-end-of-decl-1))
+ (when (or (eq (car (c-beginning-of-decl-1 lim)) 'previous)
+ (= pos (point)))
+ ;; We moved back over the previous defun. Skip to the next
+ ;; one. Not using c-forward-syntactic-ws here since we
+ ;; should not skip a macro. We can also be directly after
+ ;; the block in a `c-opt-block-decls-with-vars-key'
+ ;; declaration, but then we won't move significantly far
+ ;; here.
+ (goto-char pos)
+ (c-forward-comments)
+
+ (when (and near (c-beginning-of-macro))
+ (throw 'exit
+ (cons (point)
+ (save-excursion
+ (c-end-of-macro)
+ (forward-line 1)
+ (point))))))
+
+ (if (eobp) (throw 'exit nil))
+
+ ;; Check if `c-beginning-of-decl-1' put us after the block in a
+ ;; declaration that doesn't end there. We're searching back and
+ ;; forth over the block here, which can be expensive.
(setq pos (point))
- (while (and (not (bolp))
- (not (looking-at "\\s *$"))
- (c-forward-single-comment)))
- (cond ((bolp)
- (point))
- ((looking-at "\\s *$")
- (forward-line 1)
- (point))
- (t
+ (if (and c-opt-block-decls-with-vars-key
+ (progn
+ (c-backward-syntactic-ws)
+ (eq (char-before) ?}))
+ (eq (car (c-beginning-of-decl-1))
+ 'previous)
+ (save-excursion
+ (c-end-of-decl-1)
+ (and (> (point) pos)
+ (setq end-pos (point)))))
+ nil
+ (goto-char pos))
+
+ (if (and (not near) (> (point) start))
+ nil
+
+ ;; Try to be line oriented; position the limits at the
+ ;; closest preceding boi, and after the next newline, that
+ ;; isn't inside a comment, but if we hit a neighboring
+ ;; declaration then we instead use the exact declaration
+ ;; limit in that direction.
+ (cons (progn
+ (setq pos (point))
+ (while (and (/= (point) (c-point 'boi))
+ (c-backward-single-comment)))
+ (if (/= (point) (c-point 'boi))
+ pos
+ (point)))
+ (progn
+ (if end-pos
+ (goto-char end-pos)
+ (c-end-of-decl-1))
+ (setq pos (point))
+ (while (and (not (bolp))
+ (not (looking-at "\\s *$"))
+ (c-forward-single-comment)))
+ (cond ((bolp)
+ (point))
+ ((looking-at "\\s *$")
+ (forward-line 1)
+ (point))
+ (t
pos))))))))
(and (not near)
(goto-char (point-min))
(eq last-command 'c-mark-function)))
(push-mark-p (and (eq this-command 'c-mark-function)
(not extend-region-p)
- (not (and transient-mark-mode mark-active)))))
+ (not (c-region-is-active-p)))))
(if push-mark-p (push-mark (point)))
(if extend-region-p
(progn
\f
;; set up electric character functions to work with pending-del,
;; (a.k.a. delsel) mode. All symbols get the t value except
-;; the functions which delete, which gets 'supersede.
+;; the functions which delete, which gets 'supersede, and (from Emacs
+;; 25) `c-electric-brace' and `c-electric-paren' get special handling
+;; so as to work gracefully with `electric-pair-mode'.
(mapc
(function
(lambda (sym)
(put sym 'delete-selection t) ; for delsel (Emacs)
(put sym 'pending-delete t))) ; for pending-del (XEmacs)
'(c-electric-pound
- c-electric-brace
c-electric-slash
c-electric-star
c-electric-semi&comma
c-electric-lt-gt
- c-electric-colon
+ c-electric-colon))
+(mapc
+ (function
+ (lambda (sym)
+ (put sym 'delete-selection (if (fboundp 'delete-selection-uses-region-p)
+ 'delete-selection-uses-region-p
+ t))
+ (put sym 'pending-delete t)))
+ '(c-electric-brace
c-electric-paren))
(put 'c-electric-delete 'delete-selection 'supersede) ; delsel
(put 'c-electric-delete 'pending-delete 'supersede) ; pending-del
starting on the current line.
Otherwise reindent just the current line."
(interactive
- (list current-prefix-arg (use-region-p)))
+ (list current-prefix-arg (c-region-is-active-p)))
(if region
(c-indent-region (region-beginning) (region-end))
(c-indent-command arg)))
(if (< c-progress-interval (- now lastsecs))
(progn
(message "Indenting region... (%d%% complete)"
- (/ (* 100 (- (point) start)) (- end start)))
+ (floor (* 100.0 (- (point) start)) (- end start)))
(aset c-progress-info 2 now)))
)))
char description[] = \"\\
A very long description of something that you want to fill to make
-nicely formatted output.\"\;
+nicely formatted output.\";
If point is in any other situation, i.e. in normal code, do nothing.
\f
(cc-provide 'cc-cmds)
+;; Local Variables:
+;; indent-tabs-mode: t
+;; tab-width: 8
+;; End:
;;; cc-cmds.el ends here