Commit 51f606de authored by Gerd Moellmann's avatar Gerd Moellmann
Browse files

Installed version 5.26

parent 3fc55897
This diff is collapsed.
This diff is collapsed.
;;; cc-compat.el --- cc-mode compatibility with c-mode.el confusion
;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
;; Copyright (C) 1985,1987,1992-1999 Free Software Foundation, Inc.
;; Author: 1994-1997 Barry A. Warsaw
;; Maintainer: bug-cc-mode@gnu.org
;; Maintainer: Unmaintained
;; Created: August 1994, split from cc-mode.el
;; Version: See cc-mode.el
;; Keywords: c languages oop
......@@ -40,9 +40,15 @@
;;; Code:
(eval-when-compile
(require 'cc-defs)
(require 'cc-styles)
(require 'cc-engine))
(let ((load-path
(if (and (boundp 'byte-compile-current-file)
(stringp byte-compile-current-file))
(cons (file-name-directory byte-compile-current-file)
load-path)
load-path)))
(load "cc-defs" nil t)))
(require 'cc-styles)
(require 'cc-engine)
;; In case c-mode.el isn't loaded
......
;;; cc-defs.el --- compile time definitions for CC Mode
;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
;; Copyright (C) 1985,1987,1992-1999 Free Software Foundation, Inc.
;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
;; Authors: 1998-1999 Barry A. Warsaw and Martin Stjernholm
;; 1992-1997 Barry A. Warsaw
;; 1987 Dave Detlefs and Stewart Clamen
;; 1985 Richard M. Stallman
......@@ -28,10 +28,8 @@
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;; Get all the necessary compile time definitions.
(require 'custom)
(require 'cc-menus)
(require 'derived) ;only necessary in Emacs 20
;; cc-mode-19.el contains compatibility macros that should be compiled
......@@ -48,7 +46,7 @@
(require 'cc-mode-19))
(defsubst c-point (position)
(defmacro c-point (position)
;; Returns the value of point at certain commonly referenced POSITIONs.
;; POSITION can be one of the following symbols:
;;
......@@ -63,76 +61,105 @@
;; bopl -- beginning of previous line
;;
;; This function does not modify point or mark.
(let ((here (point)))
(cond
((eq position 'bol) (beginning-of-line))
((eq position 'eol) (end-of-line))
((eq position 'boi) (back-to-indentation))
((eq position 'bonl) (forward-line 1))
((eq position 'bopl) (forward-line -1))
((eq position 'iopl)
(forward-line -1)
(back-to-indentation))
((eq position 'ionl)
(forward-line 1)
(back-to-indentation))
((eq position 'eod) (c-end-of-defun))
((eq position 'bod)
(if (and (fboundp 'buffer-syntactic-context-depth)
c-enable-xemacs-performance-kludge-p)
;; XEmacs only. This can improve the performance of
;; c-parse-state to between 3 and 60 times faster when
;; braces are hung. It can also degrade performance by
;; about as much when braces are not hung.
(let (pos)
(while (not pos)
(save-restriction
(widen)
(setq pos (scan-lists (point) -1
(buffer-syntactic-context-depth)
nil t)))
(cond
((bobp) (setq pos (point-min)))
((not pos)
(let ((distance (skip-chars-backward "^{")))
;; unbalanced parenthesis, while illegal C code,
;; shouldn't cause an infloop! See unbal.c
(when (zerop distance)
;; Punt!
(beginning-of-defun)
(setq pos (point)))))
((= pos 0))
((not (eq (char-after pos) ?{))
(goto-char pos)
(setq pos nil))
))
(goto-char pos))
;; Emacs, which doesn't have buffer-syntactic-context-depth
;;
;; NOTE: This should be the only explicit use of
;; beginning-of-defun in CC Mode. Eventually something better
;; than b-o-d will be available and this should be the only
;; place the code needs to change. Everything else should use
;; (goto-char (c-point 'bod))
(beginning-of-defun)
;; if defun-prompt-regexp is non-nil, b-o-d won't leave us at
;; the open brace.
(and defun-prompt-regexp
(looking-at defun-prompt-regexp)
(goto-char (match-end 0)))
))
(t (error "unknown buffer position requested: %s" position))
)
(prog1
(point)
(goto-char here))))
`(save-excursion
,(if (and (eq (car-safe position) 'quote)
(symbolp (eval position)))
(let ((position (eval position)))
(cond
((eq position 'bol) `(beginning-of-line))
((eq position 'eol) `(end-of-line))
((eq position 'boi) `(back-to-indentation))
((eq position 'bonl) `(forward-line 1))
((eq position 'bopl) `(forward-line -1))
((eq position 'bod) `(c-beginning-of-defun-1))
((eq position 'eod) `(c-end-of-defun-1))
((eq position 'iopl) `(progn
(forward-line -1)
(back-to-indentation)))
((eq position 'ionl) `(progn
(forward-line 1)
(back-to-indentation)))
(t (error "unknown buffer position requested: %s" position))))
;;(message "c-point long expansion")
`(let ((position ,position))
(cond
((eq position 'bol) (beginning-of-line))
((eq position 'eol) (end-of-line))
((eq position 'boi) (back-to-indentation))
((eq position 'bonl) (forward-line 1))
((eq position 'bopl) (forward-line -1))
((eq position 'bod) (c-beginning-of-defun-1))
((eq position 'eod) (c-end-of-defun-1))
((eq position 'iopl) (progn
(forward-line -1)
(back-to-indentation)))
((eq position 'ionl) (progn
(forward-line 1)
(back-to-indentation)))
(t (error "unknown buffer position requested: %s" position)))))
(point)))
(defmacro c-safe (&rest body)
;; safely execute BODY, return nil if an error occurred
(` (condition-case nil
(progn (,@ body))
(error nil))))
`(condition-case nil
(progn ,@body)
(error nil)))
(defsubst c-beginning-of-defun-1 ()
;; Wrapper around beginning-of-defun.
;;
;; NOTE: This function should contain the only explicit use of
;; beginning-of-defun in CC Mode. Eventually something better than
;; b-o-d will be available and this should be the only place the
;; code needs to change. Everything else should use
;; (c-beginning-of-defun-1)
(if (and (fboundp 'buffer-syntactic-context-depth)
c-enable-xemacs-performance-kludge-p)
;; XEmacs only. This can improve the performance of
;; c-parse-state to between 3 and 60 times faster when
;; braces are hung. It can also degrade performance by
;; about as much when braces are not hung.
(let (pos)
(while (not pos)
(save-restriction
(widen)
(setq pos (scan-lists (point) -1
(buffer-syntactic-context-depth)
nil t)))
(cond
((bobp) (setq pos (point-min)))
((not pos)
(let ((distance (skip-chars-backward "^{")))
;; unbalanced parenthesis, while illegal C code,
;; shouldn't cause an infloop! See unbal.c
(when (zerop distance)
;; Punt!
(beginning-of-defun)
(setq pos (point)))))
((= pos 0))
((not (eq (char-after pos) ?{))
(goto-char pos)
(setq pos nil))
))
(goto-char pos))
;; Emacs, which doesn't have buffer-syntactic-context-depth
(beginning-of-defun))
;; if defun-prompt-regexp is non-nil, b-o-d won't leave us at the
;; open brace.
(and defun-prompt-regexp
(looking-at defun-prompt-regexp)
(goto-char (match-end 0))))
(defsubst c-end-of-defun-1 ()
;; Replacement for end-of-defun that use c-beginning-of-defun-1.
(while (and (c-safe (down-list 1) t)
(not (eq (char-before) ?{)))
;; skip down into the next defun-block
(forward-char -1)
(c-forward-sexp))
(c-beginning-of-defun-1)
(c-forward-sexp))
(defmacro c-forward-sexp (&optional arg)
;; like forward-sexp except
......@@ -152,17 +179,78 @@
(or arg (setq arg 1))
`(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg))))
(defsubst c-beginning-of-macro (&optional lim)
;; Go to the beginning of a cpp macro definition. Leaves point at
;; the beginning of the macro and returns t if in a cpp macro
;; definition, otherwise returns nil and leaves point unchanged.
;; `lim' is currently ignored, but the interface requires it.
(let ((here (point)))
(beginning-of-line)
(while (eq (char-before (1- (point))) ?\\)
(forward-line -1))
(back-to-indentation)
(if (and (<= (point) here)
(eq (char-after) ?#))
t
(goto-char here)
nil)))
(defsubst c-forward-comment (count)
;; Insulation from various idiosyncrasies in implementations of
;; `forward-comment'. Note: Some emacsen considers incorrectly that
;; any line comment ending with a backslash continues to the next
;; line. I can't think of any way to work around that in a reliable
;; way without changing the buffer though. Suggestions welcome. ;)
(let ((here (point)))
(if (>= count 0)
(when (forward-comment count)
;; Emacs includes the ending newline in a b-style
;; (c++) comment, but XEmacs don't. We depend on the
;; Emacs behavior (which also is symmetric).
(if (and (eolp) (nth 7 (parse-partial-sexp here (point))))
(condition-case nil (forward-char 1)))
t)
;; When we got newline terminated comments,
;; forward-comment in all supported emacsen so far will
;; stop at eol of each line not ending with a comment when
;; moving backwards. The following corrects for it when
;; count is -1. The other common case, when count is
;; large and negative, works regardless. It's too much
;; work to correct for the rest of the cases.
(skip-chars-backward " \t\n\r\f")
(if (bobp)
;; Some emacsen return t when moving backwards at bob.
nil
(re-search-forward "[\n\r]" here t)
(if (forward-comment count)
(if (eolp) (forward-comment -1) t))))))
(defmacro c-add-syntax (symbol &optional relpos)
;; a simple macro to append the syntax in symbol to the syntax list.
;; try to increase performance by using this macro
(` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
`(setq syntax (cons (cons ,symbol ,relpos) syntax)))
(defsubst c-auto-newline ()
(defmacro c-add-class-syntax (symbol classkey)
;; The inclass and class-close syntactic symbols are added in
;; several places and some work is needed to fix everything.
;; Therefore it's collected here.
`(save-restriction
(widen)
(let ((symbol ,symbol)
(classkey ,classkey))
(goto-char (aref classkey 1))
(if (and (eq symbol 'inclass) (= (point) (c-point 'boi)))
(c-add-syntax symbol (point))
(c-add-syntax symbol (aref classkey 0))
(if (and c-inexpr-class-key (c-looking-at-inexpr-block))
(c-add-syntax 'inexpr-class))))))
(defmacro c-auto-newline ()
;; if auto-newline feature is turned on, insert a newline character
;; and return t, otherwise return nil.
(and c-auto-newline
(not (c-in-literal))
(not (newline))))
`(and c-auto-newline
(not (c-in-literal))
(not (newline))))
(defsubst c-intersect-lists (list alist)
;; return the element of ALIST that matches the first element found
......@@ -188,13 +276,14 @@
(goto-char here))
)))
(defsubst c-update-modeline ()
(defmacro c-update-modeline ()
;; set the c-auto-hungry-string for the correct designation on the modeline
(setq c-auto-hungry-string
(if c-auto-newline
(if c-hungry-delete-key "/ah" "/a")
(if c-hungry-delete-key "/h" nil)))
(force-mode-line-update))
`(progn
(setq c-auto-hungry-string
(if c-auto-newline
(if c-hungry-delete-key "/ah" "/a")
(if c-hungry-delete-key "/h" nil)))
(force-mode-line-update)))
(defsubst c-keep-region-active ()
;; Do whatever is necessary to keep the region active in XEmacs.
......@@ -209,6 +298,7 @@
(cond
;; XEmacs
((and (fboundp 'region-active-p)
(boundp 'zmacs-regions)
zmacs-regions)
(region-active-p))
;; Emacs
......@@ -219,6 +309,17 @@
(defsubst c-major-mode-is (mode)
(eq (derived-mode-class major-mode) mode))
(defmacro c-with-syntax-table (table &rest code)
;; Temporarily switches to the specified syntax table in a failsafe
;; way to execute code.
`(let ((c-with-syntax-table-orig-table (syntax-table)))
(unwind-protect
(progn
(set-syntax-table ,table)
,@code)
(set-syntax-table c-with-syntax-table-orig-table))))
(put 'c-with-syntax-table 'lisp-indent-function 1)
(provide 'cc-defs)
;;; cc-defs.el ends here
This diff is collapsed.
;;; cc-langs.el --- specific language support for CC Mode
;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
;; Copyright (C) 1985,1987,1992-1999 Free Software Foundation, Inc.
;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
;; Authors: 1998-1999 Barry A. Warsaw and Martin Stjernholm
;; 1992-1997 Barry A. Warsaw
;; 1987 Dave Detlefs and Stewart Clamen
;; 1985 Richard M. Stallman
......@@ -28,11 +28,38 @@
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
(eval-when-compile
(let ((load-path
(if (and (boundp 'byte-compile-current-file)
(stringp byte-compile-current-file))
(cons (file-name-directory byte-compile-current-file)
load-path)
load-path)))
(load "cc-defs" nil t)))
(require 'cc-styles)
;; Pull in some other packages.
(eval-when-compile
(condition-case nil
;; Not required and only needed during compilation to shut up
;; the compiler.
(require 'outline)
(error nil)))
;; menu support for both XEmacs and Emacs. If you don't have easymenu
;; with your version of Emacs, you are incompatible!
(require 'easymenu)
(eval-when-compile
(require 'cc-defs))
(defvar c-buffer-is-cc-mode nil
"Non-nil for all buffers with a `major-mode' derived from CC Mode.
Otherwise, this variable is nil. I.e. this variable is non-nil for
`c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode',
`pike-mode', and any other non-CC Mode mode that calls
`c-initialize-cc-mode' (e.g. `awk-mode').")
(make-variable-buffer-local 'c-buffer-is-cc-mode)
(put 'c-buffer-is-cc-mode 'permanent-local t)
;; Regular expressions and other values which must be parameterized on
;; a per-language basis.
......@@ -56,7 +83,7 @@
;; keywords introducing class definitions. language specific
(defconst c-C-class-key "\\(struct\\|union\\)")
(defconst c-C++-class-key "\\(class\\|struct\\|union\\)")
(defconst c-IDL-class-key "\\(class\\|struct\\|union\\|interface\\)")
(defconst c-IDL-class-key "\\(interface\\|struct\\|union\\|valuetype\\)")
(defconst c-C-extra-toplevel-key "\\(extern\\)")
(defconst c-C++-extra-toplevel-key "\\(extern\\|namespace\\)")
(defconst c-IDL-extra-toplevel-key "\\(module\\)")
......@@ -86,11 +113,18 @@
(defvar c-extra-toplevel-key c-C-extra-toplevel-key)
(make-variable-buffer-local 'c-extra-toplevel-key)
;; Keywords that can introduce bitfields in the languages that supports that.
(defconst c-C-bitfield-key "\\(char\\|int\\|long\\|signed\\|unsigned\\)")
(defvar c-bitfield-key nil)
(make-variable-buffer-local 'c-bitfield-key)
;; regexp describing access protection clauses. language specific
(defvar c-access-key nil)
(make-variable-buffer-local 'c-access-key)
(defconst c-C++-access-key (concat c-protection-key "[ \t]*:"))
(defconst c-IDL-access-key nil)
(defconst c-ObjC-access-key (concat "@" c-protection-key))
(defconst c-Java-access-key nil)
(defconst c-Pike-access-key nil)
......@@ -99,6 +133,8 @@
;; keywords introducing conditional blocks
(defconst c-C-conditional-key nil)
(defconst c-C++-conditional-key nil)
(defconst c-IDL-conditional-key nil)
(defconst c-ObjC-conditional-key nil)
(defconst c-Java-conditional-key nil)
(defconst c-Pike-conditional-key nil)
......@@ -109,6 +145,8 @@
(back "\\)\\b[^_]"))
(setq c-C-conditional-key (concat front all-kws back)
c-C++-conditional-key (concat front all-kws exc-kws back)
;; c-IDL-conditional-key is nil.
c-ObjC-conditional-key c-C-conditional-key
c-Java-conditional-key (concat front all-kws exc-kws thr-kws back)
c-Pike-conditional-key (concat front all-kws "\\|foreach" back)))
......@@ -132,6 +170,10 @@
;; comment starter definitions for various languages. language specific
(defconst c-C++-comment-start-regexp "/[/*]")
(defconst c-C-comment-start-regexp c-C++-comment-start-regexp)
(defconst c-IDL-comment-start-regexp c-C++-comment-start-regexp)
(defconst c-ObjC-comment-start-regexp c-C++-comment-start-regexp)
(defconst c-Pike-comment-start-regexp c-C++-comment-start-regexp)
;; We need to match all 3 Java style comments
;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
(defconst c-Java-comment-start-regexp "/\\(/\\|[*][*]?\\)")
......@@ -173,7 +215,7 @@
;; Regexp describing Javadoc markup that always starts paragraphs.
(defconst c-Java-javadoc-paragraph-start
"@\\(author\\|exception\\|param\\|return\\|see\\|version\\)")
"@\\(author\\|exception\\|param\\|return\\|see\\|throws\\|version\\)")
;; Regexp that starts lambda constructs.
(defvar c-lambda-key nil)
......@@ -225,47 +267,86 @@
;; Common initializations for all modes.
;; these variables should always be buffer local; they do not affect
;; indentation style.
(make-local-variable 'paragraph-start)
(make-local-variable 'paragraph-separate)
(make-local-variable 'paragraph-ignore-fill-prefix)
(make-local-variable 'require-final-newline)
(make-local-variable 'parse-sexp-ignore-comments)
(make-local-variable 'indent-line-function)
(make-local-variable 'indent-region-function)
(make-local-variable 'outline-regexp)
(make-local-variable 'outline-level)
(make-local-variable 'normal-auto-fill-function)
(make-local-variable 'comment-start)
(make-local-variable 'comment-end)
(make-local-variable 'comment-column)
(make-local-variable 'comment-start-skip)
(make-local-variable 'comment-multi-line)
(make-local-variable 'outline-regexp)
(make-local-variable 'outline-level)
(make-local-variable 'adaptive-fill-regexp)
(make-local-variable 'paragraph-start)
(make-local-variable 'paragraph-separate)
(make-local-variable 'paragraph-ignore-fill-prefix)
(make-local-variable 'adaptive-fill-mode)
(make-local-variable 'adaptive-fill-regexp)
(make-local-variable 'imenu-generic-expression) ;set in the mode functions
;; X/Emacs 20 only
(and (boundp 'comment-line-break-function)
(make-local-variable 'comment-line-break-function))
;; Emacs 19.30 and beyond only, AFAIK
(if (boundp 'fill-paragraph-function)
(progn
(make-local-variable 'fill-paragraph-function)
(setq fill-paragraph-function 'c-fill-paragraph)))
(progn
(make-local-variable 'comment-line-break-function)
(setq comment-line-break-function
'c-indent-new-comment-line)))
;; now set their values
(setq paragraph-start (concat page-delimiter "\\|$")
paragraph-separate paragraph-start
paragraph-ignore-fill-prefix t
require-final-newline t
(setq require-final-newline t
parse-sexp-ignore-comments t
indent-line-function 'c-indent-line
indent-region-function 'c-indent-region
outline-regexp "[^#\n\^M]"
outline-level 'c-outline-level
normal-auto-fill-function 'c-do-auto-fill
comment-column 32
comment-start-skip "/\\*+ *\\|// *"
comment-multi-line nil
comment-line-break-function 'c-comment-line-break-function
adaptive-fill-regexp nil
adaptive-fill-mode nil)
comment-start-skip "/\\*+ *\\|//+ *"
comment-multi-line t)
;; now set the mode style based on c-default-style
(let ((style (if (stringp c-default-style)
(if (c-major-mode-is 'java-mode)
"java"
c-default-style)
(or (cdr (assq major-mode c-default-style))
(cdr (assq 'other c-default-style))
"gnu"))))
;; Override style variables if `c-old-style-variable-behavior' is
;; set. Also override if we are using global style variables,
;; have already initialized a style once, and are switching to a
;; different style. (It's doubtful whether this is desirable, but
;; the whole situation with nonlocal style variables is a bit
;; awkward. It's at least the most compatible way with the old
;; style init procedure.)
(c-set-style style (not (or c-old-style-variable-behavior
(and (not c-style-variables-are-local-p)
c-indentation-style
(not (string-equal c-indentation-style
style)))))))
;; Fix things up for paragraph recognition and filling inside
;; comments by using c-comment-prefix-regexp in the relevant places.
;; We use adaptive filling for this to make it possible to use
;; filladapt or some other fancy package.
(let ((comment-line-prefix
(concat "[ \t]*\\(" c-comment-prefix-regexp "\\)?[ \t]*")))
(setq paragraph-start (concat comment-line-prefix "$\\|"
page-delimiter)
paragraph-separate paragraph-start
paragraph-ignore-fill-prefix t
adaptive-fill-mode t
adaptive-fill-regexp
(concat comment-line-prefix
(if adaptive-fill-regexp
(concat "\\(" adaptive-fill-regexp "\\)")
"")))
(when (boundp 'adaptive-fill-first-line-regexp)
;; XEmacs (20.x) adaptive fill mode doesn't have this.
(make-local-variable 'adaptive-fill-first-line-regexp)
(setq adaptive-fill-first-line-regexp
(concat "\\`" comment-line-prefix
;; Maybe we should incorporate the old value here,
;; but then we have to do all sorts of kludges to
;; deal with the \` and \' it probably contains.
"\\'"))))
;; we have to do something special for c-offsets-alist so that the
;; buffer local value has its own alist structure.
(setq c-offsets-alist (copy-alist c-offsets-alist))
......@@ -280,14 +361,6 @@
(setq minor-mode-alist
(cons '(c-auto-hungry-string c-auto-hungry-string)
minor-mode-alist)))
;; now set the mode style based on c-default-style
(c-set-style (if (stringp c-default-style)
(if (c-major-mode-is 'java-mode)
"java"
c-default-style)
(or (cdr (assq major-mode c-default-style))
(cdr (assq 'other c-default-style))
"gnu")))
)
......@@ -386,31 +459,49 @@ Note that the style variables are always made local to the buffer."
;; backward-kill-word.
(define-key c-mode-base-map [(control meta h)] 'c-mark-function)
(define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
(define-key c-mode-base-map "\ea" 'c-beginning-of-statement)
(define-key c-mode-base-map "\ee" 'c-end-of-statement)
(substitute-key-definition 'backward-sentence
'c-beginning-of-statement
c-mode-base-map global-map)
(substitute-key-definition 'forward-sentence
'c-end-of-statement
c-mode-base-map global-map)
(substitute-key-definition 'indent-new-comment-line
'c-indent-new-comment-line
c-mode-base-map global-map)
;; RMS says don't make these the default.
;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
(define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
(define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
(define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)