comparison lisp/progmodes/c-mode.el @ 909:4c6cdb66c74c

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Mon, 03 Aug 1992 02:02:37 +0000
parents 34b6b37092c7
children f6f13367d93c
comparison
equal deleted inserted replaced
908:94eb4344341b 909:4c6cdb66c74c
1 ;;; c-mode.el --- C code editing commands for Emacs 1 ;;; c-mode.el --- C code editing commands for Emacs
2 2
3 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
4 4
5 ;; Maintainer: FSF 5 ;; Maintainer: FSF
6 ;; Keywords: c 6 ;; Keywords: c
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
1120 (end-of-line) 1120 (end-of-line)
1121 (forward-char -1) 1121 (forward-char -1)
1122 (if (looking-at "\\\\") 1122 (if (looking-at "\\\\")
1123 (delete-region (1+ (point)) 1123 (delete-region (1+ (point))
1124 (progn (skip-chars-backward " \t") (point))))) 1124 (progn (skip-chars-backward " \t") (point)))))
1125
1126 (defun c-up-conditional (count)
1127 "Move back to the containing preprocessor conditional, leaving mark behind.
1128 A prefix argument acts as a repeat count. With a negative argument,
1129 move forward to the end of the containing preprocessor conditional.
1130 When going backwards, `#elif' is treated like `#else' followed by `#if'.
1131 When going forwards, `#elif' is ignored."
1132 (interactive "p")
1133 (let* ((forward (< count 0))
1134 (increment (if forward -1 1))
1135 (search-function (if forward 're-search-forward 're-search-backward))
1136 (opoint (point))
1137 (new))
1138 (save-excursion
1139 (while (/= count 0)
1140 (if forward (end-of-line))
1141 (let ((depth 0) found)
1142 (save-excursion
1143 ;; Find the "next" significant line in the proper direction.
1144 (while (and (not found)
1145 ;; Rather than searching for a # sign that comes
1146 ;; at the beginning of a line aside from whitespace,
1147 ;; search first for a string starting with # sign.
1148 ;; Then verify what precedes it.
1149 ;; This is faster on account of the fastmap feature of
1150 ;; the regexp matcher.
1151 (funcall search-function
1152 "#[ \t]*\\(if\\|elif\\|endif\\)"
1153 nil t)
1154 (progn
1155 (beginning-of-line)
1156 (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)")))
1157 ;; Update depth according to what we found.
1158 (beginning-of-line)
1159 (cond ((looking-at "[ \t]*#[ \t]*endif")
1160 (setq depth (+ depth increment)))
1161 ((looking-at "[ \t]*#[ \t]*elif")
1162 (if (and forward (= depth 0))
1163 (setq found (point))))
1164 (t (setq depth (- depth increment))))
1165 ;; If this line exits a level of conditional, exit inner loop.
1166 (if (< depth 0)
1167 (setq found (point)))
1168 ;; When searching forward, start from end of line
1169 ;; so that we don't find the same line again.
1170 (if forward (end-of-line))))
1171 (or found
1172 (error "No containing preprocessor conditional"))
1173 (goto-char (setq new found)))
1174 (setq count (- count increment))))
1175 (push-mark)
1176 (goto-char new)))
1125 1177
1126 ;;; c-mode.el ends here 1178 ;;; c-mode.el ends here