]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-cmds.el
Update copyright year to 2015
[gnu-emacs] / lisp / progmodes / cc-cmds.el
index eec6873dc190580b2f80457208542e75aadfcbf4..68075f356ab8a6c17de8433c5254b21152362ecc 100644 (file)
@@ -1,6 +1,6 @@
 ;;; cc-cmds.el --- user level commands for CC Mode
 
-;; Copyright (C) 1985, 1987, 1992-201 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2015 Free Software Foundation, Inc.
 
 ;; Authors:    2003- Alan Mackenzie
 ;;             1998- Martin Stjernholm
@@ -45,7 +45,6 @@
 (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
@@ -259,9 +258,11 @@ With universal argument, inserts the analysis as a comment on that line."
                         "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
@@ -357,6 +358,8 @@ left out."
   (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
@@ -475,7 +478,7 @@ inside a literal or a macro, nothing special happens."
          (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)))
       )))
@@ -737,7 +740,7 @@ settings of `c-cleanup-list' are done."
              ;; `}': 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
@@ -753,14 +756,14 @@ settings of `c-cleanup-list' are done."
              ;; `}': 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
@@ -814,7 +817,7 @@ settings of `c-cleanup-list' are done."
            ))))
 
     ;; blink the paren
-    (and (eq last-command-event ?\})
+    (and (eq (c-last-command-char) ?\})
         (not executing-kbd-macro)
         old-blink-paren
         (save-excursion
@@ -851,7 +854,7 @@ is inhibited."
     (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 */
@@ -867,7 +870,7 @@ is inhibited."
     (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
@@ -941,10 +944,10 @@ settings of `c-cleanup-list'."
          (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)
@@ -1089,7 +1092,7 @@ 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 found-delim case-fold-search)
+       final-pos found-delim case-fold-search)
 
     (self-insert-command (prefix-numeric-value arg))
     (setq final-pos (point))
@@ -1101,7 +1104,7 @@ numeric argument is supplied, or the point is inside a literal."
     ;; 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)
@@ -1154,11 +1157,12 @@ numeric argument is supplied, or the point is inside a literal."
       (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.
@@ -1195,7 +1199,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
            ;; 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\\)*"
@@ -1213,7 +1217,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
            ;; 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\\)*"
@@ -1234,7 +1238,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
 
             ;; 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")
@@ -1252,7 +1256,7 @@ newline cleanups are done if appropriate; see the variable `c-cleanup-list'."
             ;; 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 "()")
@@ -1281,7 +1285,7 @@ keyword on the line, the keyword is not inserted inside a literal, and
     (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))
@@ -1302,20 +1306,43 @@ keyword on the line, the keyword is not inserted inside a literal, and
 (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.
@@ -1415,12 +1442,15 @@ No indentation or other \"electric\" behavior is performed."
              (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
@@ -1428,10 +1458,11 @@ No indentation or other \"electric\" behavior is performed."
                                  ;; ';' 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
@@ -1579,7 +1610,7 @@ defun."
 
   (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
@@ -1703,7 +1734,7 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
 
   (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
@@ -1807,7 +1838,7 @@ with a brace block."
              (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)
@@ -2000,7 +2031,7 @@ function does not require the declaration to contain a brace block."
                   (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
@@ -3337,7 +3368,7 @@ Otherwise, with a prefix argument, rigidly reindent the expression
 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)))
@@ -4726,4 +4757,8 @@ normally bound to C-o.  See `c-context-line-break' for the details."
 \f
 (cc-provide 'cc-cmds)
 
+;;; Local Variables:
+;;; indent-tabs-mode: t
+;;; tab-width: 8
+;;; End:
 ;;; cc-cmds.el ends here