emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs/lisp/progmodes cc-cmds.el


From: Alan Mackenzie
Subject: [Emacs-diffs] emacs/lisp/progmodes cc-cmds.el
Date: Thu, 24 Sep 2009 20:19:58 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Alan Mackenzie <acmacm> 09/09/24 20:19:58

Modified files:
        lisp/progmodes : cc-cmds.el 

Log message:
        (c-scan-conditionals): A new function like c-forward-conditionals, but 
it
        doesn't move point and doesn't set the mark.
        (c-up-conditional, c-up-conditional-with-else, c-down-conditional)
        (c-down-conditional-with-else, c-backward-conditional)
        (c-forward-conditional): Refactor to use c-scan-conditionals.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/progmodes/cc-cmds.el?cvsroot=emacs&r1=1.84&r2=1.85

Patches:
Index: cc-cmds.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-cmds.el,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -b -r1.84 -r1.85
--- cc-cmds.el  29 Aug 2009 02:07:45 -0000      1.84
+++ cc-cmds.el  24 Sep 2009 20:19:58 -0000      1.85
@@ -2808,7 +2808,9 @@
 function stops at them when going backward, but not when going
 forward."
   (interactive "p")
-  (c-forward-conditional (- count) -1)
+  (let ((new-point (c-scan-conditionals (- count) -1)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-up-conditional-with-else (count)
@@ -2816,7 +2818,9 @@
 Just like `c-up-conditional', except it also stops at \"#else\"
 directives."
   (interactive "p")
-  (c-forward-conditional (- count) -1 t)
+  (let ((new-point (c-scan-conditionals (- count) -1 t)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-down-conditional (count)
@@ -2828,7 +2832,9 @@
 function stops at them when going forward, but not when going
 backward."
   (interactive "p")
-  (c-forward-conditional count 1)
+  (let ((new-point (c-scan-conditionals count 1)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-down-conditional-with-else (count)
@@ -2836,15 +2842,24 @@
 Just like `c-down-conditional', except it also stops at \"#else\"
 directives."
   (interactive "p")
-  (c-forward-conditional count 1 t)
+  (let ((new-point (c-scan-conditionals count 1 t)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-backward-conditional (count &optional target-depth with-else)
   "Move back across a preprocessor conditional, leaving mark behind.
 A prefix argument acts as a repeat count.  With a negative argument,
-move forward across a preprocessor conditional."
+move forward across a preprocessor conditional.
+
+The optional arguments TARGET-DEPTH and WITH-ELSE are historical,
+and have the same meanings as in `c-scan-conditionals'.  If you
+are calling c-forward-conditional from a program, you might want
+to call `c-scan-conditionals' directly instead."
   (interactive "p")
-  (c-forward-conditional (- count) target-depth with-else)
+  (let ((new-point (c-scan-conditionals (- count) target-depth with-else)))
+    (push-mark)
+    (goto-char new-point))
   (c-keep-region-active))
 
 (defun c-forward-conditional (count &optional target-depth with-else)
@@ -2852,21 +2867,42 @@
 A prefix argument acts as a repeat count.  With a negative argument,
 move backward across a preprocessor conditional.
 
+If there aren't enough conditionals after \(or before) point, an
+error is signalled.
+
+\"#elif\" is treated like \"#else\" followed by \"#if\", except that
+the nesting level isn't changed when tracking subconditionals.
+
+The optional arguments TARGET-DEPTH and WITH-ELSE are historical,
+and have the same meanings as in `c-scan-conditionals'.  If you
+are calling c-forward-conditional from a program, you might want
+to call `c-scan-conditionals' directly instead."
+  (interactive "p")
+  (let ((new-point (c-scan-conditionals count target-depth with-else)))
+    (push-mark)
+    (goto-char new-point)))
+
+(defun c-scan-conditionals (count &optional target-depth with-else)
+  "Scan forward across COUNT preprocessor conditionals.
+With a negative argument, scan backward across preprocessor
+conditionals.  Return the end position.  Point is not moved.
+
+If there aren't enough preprocessor conditionals, throw an error.
+
 \"#elif\" is treated like \"#else\" followed by \"#if\", except that
 the nesting level isn't changed when tracking subconditionals.
 
 The optional argument TARGET-DEPTH specifies the wanted nesting depth
-after each scan.  I.e. if TARGET-DEPTH is -1, the function will move
-out of the enclosing conditional.  A non-integer non-nil TARGET-DEPTH
+after each scan.  E.g. if TARGET-DEPTH is -1, the end position will be
+outside the enclosing conditional.  A non-integer non-nil TARGET-DEPTH
 counts as -1.
 
 If the optional argument WITH-ELSE is non-nil, \"#else\" directives
 are treated as conditional clause limits.  Normally they are ignored."
-  (interactive "p")
   (let* ((forward (> count 0))
         (increment (if forward -1 1))
         (search-function (if forward 're-search-forward 're-search-backward))
-        (new))
+        new)
     (unless (integerp target-depth)
       (setq target-depth (if target-depth -1 0)))
     (save-excursion
@@ -2935,9 +2971,8 @@
              (error "No containing preprocessor conditional"))
          (goto-char (setq new found)))
        (setq count (+ count increment))))
-    (push-mark)
-    (goto-char new))
-  (c-keep-region-active))
+    (c-keep-region-active)
+    new))
 
 
 ;; commands to indent lines, regions, defuns, and expressions




reply via email to

[Prev in Thread] Current Thread [Next in Thread]