;;; cc-cmds.el --- user level commands for CC Mode
;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
;; Free Software Foundation, Inc.
;; Authors: 2003- Alan Mackenzie
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with this program; see the file COPYING. If not, write to
-;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This is the list of brace syntactic symbols that can hang.
;; If any new ones are added to c-offsets-alist, they should be
;; added here as well.
- '(class-open class-close defun-open defun-close
+ ;;
+ ;; The order of this list is important; if SYNTAX has several
+ ;; elements, the element that "wins" is the earliest in SYMS.
+ '(arglist-cont-nonempty ; e.g. an array literal.
+ class-open class-close defun-open defun-close
inline-open inline-close
brace-list-open brace-list-close
brace-list-intro brace-entry-open
(narrow-to-region (point-min) (point))
(back-to-indentation)
(looking-at (concat c-current-comment-prefix "[ \t]*$")))))
- (kill-region (progn (forward-line 0) (point))
- (progn (end-of-line) (point)))
+ (delete-region (progn (forward-line 0) (point))
+ (progn (end-of-line) (point)))
(insert-char ?* 1)) ; the / comes later. ; Do I need a t (retain sticky properties) here?
(setq indentp (and (not arg)
(and c-opt-block-decls-with-vars-key
(save-excursion
(c-syntactic-skip-backward "^;}" lim)
- (and (eq (char-before) ?\})
- (eq (car (c-beginning-of-decl-1 lim)) 'previous)
- (looking-at c-opt-block-decls-with-vars-key)
- (point)))))
+ (let ((eo-block (point))
+ bod)
+ (and (eq (char-before) ?\})
+ (eq (car (c-beginning-of-decl-1 lim)) 'previous)
+ (setq bod (point))
+ ;; Look for struct or union or ... If we find one, it might
+ ;; be the return type of a function, or the like. Exclude
+ ;; this case.
+ (c-syntactic-re-search-forward
+ (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)
+ (eq (char-before) ?\{)
+ bod)))))
(defun c-where-wrt-brace-construct ()
;; Determine where we are with respect to functions (or other brace
(or arg (setq arg 1))
(c-save-buffer-state
- ((start (point))
+ (beginning-of-defun-function end-of-defun-function
+ (start (point))
where paren-state pos)
;; Move back out of any macro/comment/string we happen to be in.
(setq arg (c-forward-to-nth-EOF-} (- arg) where)))
;; Move forward to the next opening brace....
(when (and (= arg 0)
- (c-syntactic-re-search-forward "{" nil t))
+ (c-syntactic-re-search-forward "{" nil 'eob))
(backward-char)
;; ... and backward to the function header.
(c-beginning-of-decl-1)
(or arg (setq arg 1))
(c-save-buffer-state
- ((start (point))
+ (beginning-of-defun-function end-of-defun-function
+ (start (point))
where paren-state pos)
;; Move back out of any macro/comment/string we happen to be in.
(c-keep-region-active)
(= arg 0)))
+(defun c-defun-name ()
+ "Return the name of the current defun, or NIL if there isn't one.
+\"Defun\" here means a function, or other top level construct
+with a brace block."
+ (interactive)
+ (c-save-buffer-state
+ (beginning-of-defun-function end-of-defun-function
+ where pos name-end)
+
+ (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 where (c-where-wrt-brace-construct))
+
+ ;; Move to the beginning of the current defun, if any, if we're not
+ ;; already there.
+ (if (eq where 'outwith-function)
+ nil
+ (unless (eq where 'at-header)
+ (c-backward-to-nth-BOF-{ 1 where)
+ (c-beginning-of-decl-1))
+
+ ;; Pick out the defun name, according to the type of defun.
+ (cond
+ ((and (looking-at c-type-prefix-key)
+ (progn (c-forward-token-2 2) ; over "struct foo "
+ (eq (char-after) ?\{)))
+ ;; struct, union, enum, or similar:
+ (c-backward-syntactic-ws)
+ (setq name-end (point))
+ (buffer-substring-no-properties
+ (progn
+ (c-backward-token-2 2)
+ (point))
+ name-end))
+
+ ((looking-at "DEFUN\\_>")
+ ;; 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)
+ (c-forward-syntactic-ws)
+ (when (eq (char-after) ?\")
+ (forward-sexp 1)
+ (c-forward-token-2)) ; over the comma and following WS.
+ (buffer-substring-no-properties
+ (point)
+ (progn
+ (c-forward-token-2)
+ (c-backward-syntactic-ws)
+ (point))))
+
+ (t
+ ;; Normal function or initializer.
+ (when (c-syntactic-re-search-forward "[{(]" nil t)
+ (backward-char)
+ (c-backward-syntactic-ws)
+ (when (eq (char-before) ?\=) ; struct foo bar = {0, 0} ;
+ (c-backward-token-2)
+ (c-backward-syntactic-ws))
+ (setq name-end (point))
+ (c-backward-token-2)
+ (buffer-substring-no-properties (point) name-end))))))))
+
(defun c-declaration-limits (near)
;; Return a cons of the beginning and end positions of the current
;; top level declaration or macro. If point is not inside any then
(goto-char (car decl-limits))
(push-mark (cdr decl-limits) nil t))))
+(defun c-cpp-define-name ()
+ "Return the name of the current CPP macro, or NIL if we're not in one."
+ (interactive)
+ (save-excursion
+ (and c-opt-cpp-macro-define-start
+ (c-beginning-of-macro)
+ (looking-at c-opt-cpp-macro-define-start)
+ (match-string-no-properties 1))))
+
\f
;; Movement by statements.
(defun c-in-comment-line-prefix-p ()
;; 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.
-(mapcar
+(mapc
(function
(lambda (sym)
(put sym 'delete-selection t) ; for delsel (Emacs)
;; compiled, e.g. in the menus.
(c-region-is-active-p))
-(defun c-indent-line-or-region ()
- "When the region is active, indent it syntactically. Otherwise
-indent the current line syntactically."
- ;; Emacs has a variable called mark-active, XEmacs uses region-active-p
- (interactive)
- (if (c-region-is-active-p)
+(defun c-indent-line-or-region (&optional arg region)
+ "Indent active region, current line, or block starting on this line.
+In Transient Mark mode, when the region is active, reindent the region.
+Othewise, 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)))
+ (if region
(c-indent-region (region-beginning) (region-end))
- (c-indent-line)))
-
+ (c-indent-command arg)))
\f
;; for progress reporting
(defvar c-progress-info nil)
(save-excursion
(goto-char (cdr c-lit-limits))
(beginning-of-line)
- (and (search-forward-regexp
+ ;; The following conjunct was added to avoid an
+ ;; "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
\f
(cc-provide 'cc-cmds)
-;;; arch-tag: bf0611dc-d1f4-449e-9e45-4ec7c6936677
+;; arch-tag: bf0611dc-d1f4-449e-9e45-4ec7c6936677
;;; cc-cmds.el ends here