;;; cc-cmds.el --- user level commands for CC Mode
-;; Copyright (C) 1985, 1987, 1992-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2015 Free Software Foundation, Inc.
;; Authors: 2003- Alan Mackenzie
;; 1998- Martin Stjernholm
(cc-require 'cc-engine)
;; Silence the compiler.
-(cc-bytecomp-defun delete-forward-p) ; XEmacs
(cc-bytecomp-defvar filladapt-mode) ; c-fill-paragraph contains a kludge
; which looks at this.
\f
"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
(interactive "P")
(setq c-electric-flag (c-calculate-state arg c-electric-flag))
(c-update-modeline)
+ (when (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later.
+ (electric-indent-local-mode (if c-electric-flag 1 0)))
(c-keep-region-active))
\f
(bolp (bolp)))
(beginning-of-line)
(delete-horizontal-space)
- (insert last-command-event)
+ (insert (c-last-command-char))
(and (not bolp)
(goto-char (- (point-max) pos)))
)))
;; `}': clean up empty defun braces
(when (c-save-buffer-state ()
(and (memq 'empty-defun-braces c-cleanup-list)
- (eq last-command-event ?\})
+ (eq (c-last-command-char) ?\})
(c-intersect-lists '(defun-close class-close inline-close)
syntax)
(progn
;; `}': compact to a one-liner defun?
(save-match-data
(when
- (and (eq last-command-event ?\})
+ (and (eq (c-last-command-char) ?\})
(memq 'one-liner-defun c-cleanup-list)
(c-intersect-lists '(defun-close) syntax)
(c-try-one-liner))
(setq here (- (point-max) pos))))
;; `{': clean up brace-else-brace and brace-elseif-brace
- (when (eq last-command-event ?\{)
+ (when (eq (c-last-command-char) ?\{)
(cond
((and (memq 'brace-else-brace c-cleanup-list)
(re-search-backward
))))
;; blink the paren
- (and (eq last-command-event ?\})
+ (and (eq (c-last-command-char) ?\})
(not executing-kbd-macro)
old-blink-paren
(save-excursion
(when (and (not arg)
(eq literal 'c)
(memq 'comment-close-slash c-cleanup-list)
- (eq last-command-event ?/)
+ (eq (c-last-command-char) ?/)
(looking-at (concat "[ \t]*\\("
(regexp-quote comment-end) "\\)?$"))
; (eq c-block-comment-ender "*/") ; C-style comments ALWAYS end in */
(setq indentp (and (not arg)
c-syntactic-indentation
c-electric-flag
- (eq last-command-event ?/)
+ (eq (c-last-command-char) ?/)
(eq (char-before) (if literal ?* ?/))))
(self-insert-command (prefix-numeric-value arg))
(if indentp
(let ((pos (- (point-max) (point))))
(if (c-save-buffer-state ()
(and (or (and
- (eq last-command-event ?,)
+ (eq (c-last-command-char) ?,)
(memq 'list-close-comma c-cleanup-list))
(and
- (eq last-command-event ?\;)
+ (eq (c-last-command-char) ?\;)
(memq 'defun-close-semi c-cleanup-list)))
(progn
(forward-char -1)
(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))
;; 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 (eq (c-last-command-char) ?<)
;; If a <, basically see if it's got "template" before it .....
(or (and (progn
(backward-char)
(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)))))
+ ;; Currently (2014-10-19), the syntax-table text properties on < and >
+ ;; are only applied in code called during Emacs redisplay. We thus
+ ;; explicitly cause a redisplay so that these properties have been
+ ;; applied when `blink-paren-function' gets called.
+ (sit-for 0)
+ (funcall blink-paren-function)))))
(defun c-electric-paren (arg)
"Insert a parenthesis.
;; clean up brace-elseif-brace
(when
(and (memq 'brace-elseif-brace c-cleanup-list)
- (eq last-command-event ?\()
+ (eq (c-last-command-char) ?\()
(re-search-backward
(concat "}"
"\\([ \t\n]\\|\\\\\n\\)*"
;; clean up brace-catch-brace
(when
(and (memq 'brace-catch-brace c-cleanup-list)
- (eq last-command-event ?\()
+ (eq (c-last-command-char) ?\()
(re-search-backward
(concat "}"
"\\([ \t\n]\\|\\\\\n\\)*"
;; space-before-funcall clean-up?
((and (memq 'space-before-funcall c-cleanup-list)
- (eq last-command-event ?\()
+ (eq (c-last-command-char) ?\()
(save-excursion
(backward-char)
(skip-chars-backward " \t")
;; compact-empty-funcall clean-up?
((c-save-buffer-state ()
(and (memq 'compact-empty-funcall c-cleanup-list)
- (eq last-command-event ?\))
+ (eq (c-last-command-char) ?\))
(save-excursion
(c-safe (backward-char 2))
(when (looking-at "()")
(when (c-save-buffer-state ()
(and c-electric-flag
c-syntactic-indentation
- (not (eq last-command-event ?_))
+ (not (eq (c-last-command-char) ?_))
(= (save-excursion
(skip-syntax-backward "w")
(point))
(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)))
+
;; "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.
(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
(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
(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)
(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
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)))
\f
(cc-provide 'cc-cmds)
+;;; Local Variables:
+;;; indent-tabs-mode: t
+;;; tab-width: 8
+;;; End:
;;; cc-cmds.el ends here