aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1993-06-28 04:48:51 +0000
committerRichard M. Stallman1993-06-28 04:48:51 +0000
commit3c8aaef219be24c9a24552da0be7a9053a82251d (patch)
treef064d43ab79755caea2edd0f190845e126343f88
parent41dfb835db8a0c12fb7a03d484b8c7a9a7335f24 (diff)
downloademacs-3c8aaef219be24c9a24552da0be7a9053a82251d.tar.gz
emacs-3c8aaef219be24c9a24552da0be7a9053a82251d.zip
(c-forward-conditional): New function.
(c-up-conditional): Use c-forward-conditional. (c-backward-conditional): New function. (c-mode-map): Make bindings for them.
-rw-r--r--lisp/progmodes/c-mode.el40
1 files changed, 31 insertions, 9 deletions
diff --git a/lisp/progmodes/c-mode.el b/lisp/progmodes/c-mode.el
index 198e430f60a..b52f9fa68de 100644
--- a/lisp/progmodes/c-mode.el
+++ b/lisp/progmodes/c-mode.el
@@ -48,6 +48,9 @@
48 (define-key c-mode-map "\ea" 'c-beginning-of-statement) 48 (define-key c-mode-map "\ea" 'c-beginning-of-statement)
49 (define-key c-mode-map "\ee" 'c-end-of-statement) 49 (define-key c-mode-map "\ee" 'c-end-of-statement)
50 (define-key c-mode-map "\eq" 'c-fill-paragraph) 50 (define-key c-mode-map "\eq" 'c-fill-paragraph)
51 (define-key c-mode-map "\C-c\C-n" 'c-forward-conditional)
52 (define-key c-mode-map "\C-c\C-p" 'c-backward-conditional)
53 (define-key c-mode-map "\C-c\C-u" 'c-up-conditional)
51 (define-key c-mode-map "\177" 'backward-delete-char-untabify) 54 (define-key c-mode-map "\177" 'backward-delete-char-untabify)
52 (define-key c-mode-map "\t" 'c-indent-command)) 55 (define-key c-mode-map "\t" 'c-indent-command))
53 56
@@ -1252,15 +1255,28 @@ move forward to the end of the containing preprocessor conditional.
1252When going backwards, `#elif' is treated like `#else' followed by `#if'. 1255When going backwards, `#elif' is treated like `#else' followed by `#if'.
1253When going forwards, `#elif' is ignored." 1256When going forwards, `#elif' is ignored."
1254 (interactive "p") 1257 (interactive "p")
1255 (let* ((forward (< count 0)) 1258 (c-forward-conditional (- count) t))
1259
1260(defun c-backward-conditional (count &optional up-flag)
1261 "Move back across a preprocessor conditional, leaving mark behind.
1262A prefix argument acts as a repeat count. With a negative argument,
1263move forward across a preprocessor conditional."
1264 (interactive "p")
1265 (c-forward-conditional (- count) up-flag))
1266
1267(defun c-forward-conditional (count &optional up-flag)
1268 "Move forward across a preprocessor conditional, leaving mark behind.
1269A prefix argument acts as a repeat count. With a negative argument,
1270move backward across a preprocessor conditional."
1271 (interactive "p")
1272 (let* ((forward (> count 0))
1256 (increment (if forward -1 1)) 1273 (increment (if forward -1 1))
1257 (search-function (if forward 're-search-forward 're-search-backward)) 1274 (search-function (if forward 're-search-forward 're-search-backward))
1258 (opoint (point)) 1275 (opoint (point))
1259 (new)) 1276 (new))
1260 (save-excursion 1277 (save-excursion
1261 (while (/= count 0) 1278 (while (/= count 0)
1262 (if forward (end-of-line)) 1279 (let ((depth (if up-flag 0 -1)) found)
1263 (let ((depth 0) found)
1264 (save-excursion 1280 (save-excursion
1265 ;; Find the "next" significant line in the proper direction. 1281 ;; Find the "next" significant line in the proper direction.
1266 (while (and (not found) 1282 (while (and (not found)
@@ -1276,7 +1292,7 @@ When going forwards, `#elif' is ignored."
1276 (beginning-of-line) 1292 (beginning-of-line)
1277 ;; Now verify it is really a preproc line. 1293 ;; Now verify it is really a preproc line.
1278 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)") 1294 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)")
1279 (progn 1295 (let ((prev depth))
1280 ;; Update depth according to what we found. 1296 ;; Update depth according to what we found.
1281 (beginning-of-line) 1297 (beginning-of-line)
1282 (cond ((looking-at "[ \t]*#[ \t]*endif") 1298 (cond ((looking-at "[ \t]*#[ \t]*endif")
@@ -1285,16 +1301,22 @@ When going forwards, `#elif' is ignored."
1285 (if (and forward (= depth 0)) 1301 (if (and forward (= depth 0))
1286 (setq found (point)))) 1302 (setq found (point))))
1287 (t (setq depth (- depth increment)))) 1303 (t (setq depth (- depth increment))))
1304 ;; If we are trying to move across, and we find
1305 ;; an end before we find a beginning, get an error.
1306 (if (and (< prev 0) (< depth prev))
1307 (error (if forward
1308 "No following conditional at this level"
1309 "No previous conditional at this level")))
1310 ;; When searching forward, start from next line
1311 ;; so that we don't find the same line again.
1312 (if forward (forward-line 1))
1288 ;; If this line exits a level of conditional, exit inner loop. 1313 ;; If this line exits a level of conditional, exit inner loop.
1289 (if (< depth 0) 1314 (if (< depth 0)
1290 (setq found (point))) 1315 (setq found (point)))))))
1291 ;; When searching forward, start from end of line
1292 ;; so that we don't find the same line again.
1293 (if forward (end-of-line))))))
1294 (or found 1316 (or found
1295 (error "No containing preprocessor conditional")) 1317 (error "No containing preprocessor conditional"))
1296 (goto-char (setq new found))) 1318 (goto-char (setq new found)))
1297 (setq count (- count increment)))) 1319 (setq count (+ count increment))))
1298 (push-mark) 1320 (push-mark)
1299 (goto-char new))) 1321 (goto-char new)))
1300 1322