diff options
Diffstat (limited to 'lisp/progmodes/cc-defs.el')
-rw-r--r-- | lisp/progmodes/cc-defs.el | 237 |
1 files changed, 131 insertions, 106 deletions
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el index d7213d03469..b17cbdd5900 100644 --- a/lisp/progmodes/cc-defs.el +++ b/lisp/progmodes/cc-defs.el @@ -1,6 +1,6 @@ ;;; cc-defs.el --- compile time definitions for CC Mode -;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. +;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc. ;; Authors: 2000- Martin Stjernholm ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm @@ -25,31 +25,55 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; along with this program; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. -;; Get all the necessary compile time definitions. -(require 'custom) -(require 'derived) ;only necessary in Emacs 20 +(eval-when-compile + (let ((load-path + (if (and (boundp 'byte-compile-dest-file) + (stringp byte-compile-dest-file)) + (cons (file-name-directory byte-compile-dest-file) load-path) + load-path))) + (require 'cc-bytecomp))) -;; cc-mode-19.el contains compatibility macros that should be compiled -;; in if needed. -(if (or (not (fboundp 'functionp)) - (not (condition-case nil - (progn (char-before) t) - (error nil))) - (not (condition-case nil - (progn (char-after) t) - (error nil))) - (not (fboundp 'when)) - (not (fboundp 'unless))) - (require 'cc-mode-19)) +;; cc-mode-19.el contains compatibility macros that should be used if +;; needed. +(eval-and-compile + (if (or (not (fboundp 'functionp)) + (not (condition-case nil + (progn (eval '(char-before)) t) + (error nil))) + (not (condition-case nil + (progn (eval '(char-after)) t) + (error nil))) + (not (fboundp 'when)) + (not (fboundp 'unless))) + (cc-load "cc-mode-19"))) + +;; Silence the compiler. +(cc-bytecomp-defvar c-enable-xemacs-performance-kludge-p) ; In cc-vars.el +(cc-bytecomp-defun buffer-syntactic-context-depth) ; XEmacs +(cc-bytecomp-defun region-active-p) ; XEmacs +(cc-bytecomp-defvar zmacs-region-stays) ; XEmacs +(cc-bytecomp-defvar zmacs-regions) ; XEmacs +(cc-bytecomp-defvar mark-active) ; Emacs +(cc-bytecomp-defun scan-lists) ; 5 args in XEmacs, 3 in Emacs +(require 'derived) ; Only necessary in Emacs -(defmacro c-point (position) - ;; Returns the value of point at certain commonly referenced POSITIONs. - ;; POSITION can be one of the following symbols: +;;; Macros. + +;;; Helpers for building regexps. +(defmacro c-paren-re (re) + `(concat "\\(" ,re "\\)")) +(defmacro c-identifier-re (re) + `(concat "\\<\\(" ,re "\\)\\>[^_]")) + +(defmacro c-point (position &optional point) + ;; Returns the value of certain commonly referenced POSITIONs + ;; relative to POINT. The current point is used if POINT isn't + ;; specified. POSITION can be one of the following symbols: ;; ;; bol -- beginning of line ;; eol -- end of line @@ -63,6 +87,7 @@ ;; ;; This function does not modify point or mark. `(save-excursion + ,(if point `(goto-char ,point)) ,(if (and (eq (car-safe position) 'quote) (symbolp (eval position))) (let ((position (eval position))) @@ -100,13 +125,81 @@ (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))) +(defmacro c-forward-sexp (&optional arg) + ;; like forward-sexp except + ;; 1. this is much stripped down from the XEmacs version + ;; 2. this cannot be used as a command, so we're insulated from + ;; XEmacs' losing efforts to make forward-sexp more user + ;; friendly + ;; 3. Preserves the semantics most of CC Mode is based on + (or arg (setq arg 1)) + `(goto-char (or (scan-sexps (point) ,arg) + ,(if (numberp arg) + (if (> arg 0) `(point-max) `(point-min)) + `(if (> ,arg 0) (point-max) (point-min)))))) + +(defmacro c-backward-sexp (&optional arg) + ;; See c-forward-sexp and reverse directions + (or arg (setq arg 1)) + `(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg)))) + +(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))) + +(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. This is a macro mostly because + ;; c-add-syntax doesn't work otherwise. + `(save-restriction + (widen) + (let ((symbol ,symbol) + (classkey ,classkey) + inexpr) + (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 + (setq inexpr (c-looking-at-inexpr-block)) + (/= (cdr inexpr) (c-point 'boi (cdr inexpr)))) + (c-add-syntax 'inexpr-class)))))) + +(defmacro c-update-modeline () + ;; set the c-auto-hungry-string for the correct designation on the modeline + `(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))) + +(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) + +;;; Inline functions. + +;; Note: All these after the macros, to be on safe side in avoiding +;; bugs where macros are defined too late. These bugs often only show +;; when the files are compiled in a certain order within the same +;; session. + (defsubst c-beginning-of-defun-1 () ;; Wrapper around beginning-of-defun. ;; @@ -165,52 +258,25 @@ (if (< (point) start) (goto-char (point-max))))) -(defmacro c-forward-sexp (&optional arg) - ;; like forward-sexp except - ;; 1. this is much stripped down from the XEmacs version - ;; 2. this cannot be used as a command, so we're insulated from - ;; XEmacs' losing efforts to make forward-sexp more user - ;; friendly - ;; 3. Preserves the semantics most of CC Mode is based on - (or arg (setq arg 1)) - `(goto-char (or (scan-sexps (point) ,arg) - ,(if (numberp arg) - (if (> arg 0) `(point-max) `(point-min)) - `(if (> ,arg 0) (point-max) (point-min)))))) - -(defmacro c-backward-sexp (&optional arg) - ;; See c-forward-sexp and reverse directions - (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. ;) + ;; `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. ;) + ;; + ;; Another note: When moving backwards over a block comment, there's + ;; a bug in forward-comment that can make it stop at "/*" inside a + ;; line comment. Haven't yet found a reasonably cheap way to kludge + ;; around that one either. :\ (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). + ;; Emacs includes the ending newline in a b-style (c++) + ;; comment, but XEmacs doesn'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) @@ -229,26 +295,6 @@ (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))) - -(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)))))) - (defsubst c-intersect-lists (list alist) ;; return the element of ALIST that matches the first element found ;; in LIST. Uses assq. @@ -275,19 +321,9 @@ )) 0)) -(defmacro c-update-modeline () - ;; set the c-auto-hungry-string for the correct designation on the modeline - `(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. - ;; Ignore byte-compiler warnings you might see. This is not needed - ;; for Emacs. + ;; This is not needed for Emacs. (and (boundp 'zmacs-region-stays) (setq zmacs-region-stays t))) @@ -308,17 +344,6 @@ (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-provide 'cc-defs) ;;; cc-defs.el ends here |