(in-is13194-devanagari-pre-write-conversion): Use with-temp-buffer.
[bpt/emacs.git] / lisp / progmodes / cc-defs.el
CommitLineData
3c3d11e7 1;;; cc-defs.el --- compile time definitions for CC Mode
785eecbb 2
d5436a29 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
785eecbb
RS
4
5;; Authors: 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org
9;; Created: 22-Apr-1997 (split from cc-mode.el)
81eb2ff9 10;; Version: See cc-mode.el
785eecbb
RS
11;; Keywords: c languages oop
12
13;; This file is part of GNU Emacs.
14
15;; GNU Emacs is free software; you can redistribute it and/or modify
16;; it under the terms of the GNU General Public License as published by
17;; the Free Software Foundation; either version 2, or (at your option)
18;; any later version.
19
20;; GNU Emacs is distributed in the hope that it will be useful,
21;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23;; GNU General Public License for more details.
24
25;; You should have received a copy of the GNU General Public License
26;; along with GNU Emacs; see the file COPYING. If not, write to the
27;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28;; Boston, MA 02111-1307, USA.
29
30\f
785eecbb
RS
31(defsubst c-point (position)
32 ;; Returns the value of point at certain commonly referenced POSITIONs.
33 ;; POSITION can be one of the following symbols:
34 ;;
35 ;; bol -- beginning of line
36 ;; eol -- end of line
37 ;; bod -- beginning of defun
38 ;; boi -- back to indentation
39 ;; ionl -- indentation of next line
40 ;; iopl -- indentation of previous line
41 ;; bonl -- beginning of next line
42 ;; bopl -- beginning of previous line
43 ;;
44 ;; This function does not modify point or mark.
45 (let ((here (point)))
46 (cond
47 ((eq position 'bol) (beginning-of-line))
48 ((eq position 'eol) (end-of-line))
785eecbb
RS
49 ((eq position 'boi) (back-to-indentation))
50 ((eq position 'bonl) (forward-line 1))
51 ((eq position 'bopl) (forward-line -1))
52 ((eq position 'iopl)
53 (forward-line -1)
54 (back-to-indentation))
55 ((eq position 'ionl)
56 (forward-line 1)
57 (back-to-indentation))
d5436a29
RS
58 ((eq position 'bod)
59 (if (and (fboundp 'buffer-syntactic-context-depth)
60 c-enable-xemacs-performance-kludge-p)
61 ;; XEmacs only. This can improve the performance of
62 ;; c-parse-state to between 3 and 60 times faster when
63 ;; braces are hung. It can cause c-parse-state to be
64 ;; slightly slower when braces are not hung, but general
65 ;; editing appears to be still about as fast.
66 (let (pos)
67 (while (not pos)
68 (save-restriction
69 (widen)
70 (setq pos (scan-lists (point) -1
71 (buffer-syntactic-context-depth)
72 nil t)))
73 (cond
74 ((bobp) (setq pos (point-min)))
75 ((not pos)
76 (let ((distance (skip-chars-backward "^{")))
77 ;; unbalanced parenthesis, while illegal C code,
78 ;; shouldn't cause an infloop! See unbal.c
79 (when (zerop distance)
80 ;; Punt!
81 (beginning-of-defun)
82 (setq pos (point)))))
83 ((= pos 0))
84 ((not (eq (char-after pos) ?{))
85 (goto-char pos)
86 (setq pos nil))
87 ))
88 (goto-char pos))
89 ;; Emacs, which doesn't have buffer-syntactic-context-depth
90 ;;
91 ;; NOTE: This should be the only explicit use of
92 ;; beginning-of-defun in CC Mode. Eventually something better
93 ;; than b-o-d will be available and this should be the only
94 ;; place the code needs to change. Everything else should use
95 ;; (goto-char (c-point 'bod))
96 (beginning-of-defun)
97 ;; if defun-prompt-regexp is non-nil, b-o-d won't leave us at
98 ;; the open brace.
99 (and defun-prompt-regexp
100 (looking-at defun-prompt-regexp)
101 (goto-char (match-end 0)))
102 ))
785eecbb
RS
103 (t (error "unknown buffer position requested: %s" position))
104 )
105 (prog1
106 (point)
107 (goto-char here))))
108
109(defmacro c-safe (&rest body)
110 ;; safely execute BODY, return nil if an error occurred
111 (` (condition-case nil
112 (progn (,@ body))
113 (error nil))))
114
115(defmacro c-add-syntax (symbol &optional relpos)
116 ;; a simple macro to append the syntax in symbol to the syntax list.
117 ;; try to increase performance by using this macro
118 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
119
120(defsubst c-auto-newline ()
121 ;; if auto-newline feature is turned on, insert a newline character
122 ;; and return t, otherwise return nil.
123 (and c-auto-newline
124 (not (c-in-literal))
125 (not (newline))))
126
127(defsubst c-intersect-lists (list alist)
128 ;; return the element of ALIST that matches the first element found
129 ;; in LIST. Uses assq.
130 (let (match)
131 (while (and list
132 (not (setq match (assq (car list) alist))))
133 (setq list (cdr list)))
134 match))
135
136(defsubst c-lookup-lists (list alist1 alist2)
137 ;; first, find the first entry from LIST that is present in ALIST1,
138 ;; then find the entry in ALIST2 for that entry.
139 (assq (car (c-intersect-lists list alist1)) alist2))
140
141(defsubst c-langelem-col (langelem &optional preserve-point)
142 ;; convenience routine to return the column of langelem's relpos.
143 ;; Leaves point at the relpos unless preserve-point is non-nil.
144 (let ((here (point)))
145 (goto-char (cdr langelem))
146 (prog1 (current-column)
147 (if preserve-point
148 (goto-char here))
149 )))
150
151(defsubst c-update-modeline ()
152 ;; set the c-auto-hungry-string for the correct designation on the modeline
153 (setq c-auto-hungry-string
154 (if c-auto-newline
155 (if c-hungry-delete-key "/ah" "/a")
156 (if c-hungry-delete-key "/h" nil)))
157 (force-mode-line-update))
158
159(defsubst c-keep-region-active ()
160 ;; Do whatever is necessary to keep the region active in XEmacs.
161 ;; Ignore byte-compiler warnings you might see. This is not needed
162 ;; for Emacs.
163 (and (boundp 'zmacs-region-stays)
164 (setq zmacs-region-stays t)))
165
785eecbb
RS
166\f
167(provide 'cc-defs)
168;;; cc-defs.el ends here