]> git.eshelyaron.com Git - emacs.git/commitdiff
(easy-mmode-define-navigation): Take additional
authorThien-Thi Nguyen <ttn@gnuvola.org>
Fri, 14 Nov 2003 16:18:01 +0000 (16:18 +0000)
committerThien-Thi Nguyen <ttn@gnuvola.org>
Fri, 14 Nov 2003 16:18:01 +0000 (16:18 +0000)
optional arg NARROWFUN.  For the generated functions: Add local var
`was-narrowed-p'.  Also, if NARROWFUN is specified, include frags that
arrange to check for and save narrowing state before the move and then
conditionally call NARROWFUN after the move.

lisp/ChangeLog
lisp/emacs-lisp/easy-mmode.el

index 652fbb5813b76a613b3912dae3f3dba7fe1432d0..caefea001cb9c0f693f790b542fc140dc9d16104 100644 (file)
@@ -1,3 +1,11 @@
+2003-11-14  Thien-Thi Nguyen  <ttn@gnu.org>
+
+       * emacs-lisp/easy-mmode.el (easy-mmode-define-navigation): Take
+       additional optional arg NARROWFUN.  For the generated functions: Add
+       local var `was-narrowed-p'.  Also, if NARROWFUN is specified, include
+       frags that arrange to check for and save narrowing state before the
+       move and then conditionally call NARROWFUN after the move.
+
 2003-11-14  John Wiegley  <johnw@newartisans.com>
 
        * eshell/esh-var.el (eshell-parse-variable-ref): Added a backslash
@@ -31,7 +39,7 @@
 2003-11-08  Kailash C. Chowksey <klchxbec@m-net.arbornet.org>
 
        These changes are to support Kannada language/script.
-       
+
        * Makefile.in (DONTCOMPILE): Add kannada.el.
 
        * makefile.w32-in (DONTCOMPILE): Add kannada.el.
index cdc4bc3aca0870ca047c12726955e1f6d0280f0a..01e3e0af5ac91613aa6d5e23231c674238f00963 100644 (file)
@@ -419,7 +419,7 @@ CSS contains a list of syntax specifications of the form (CHAR . SYNTAX)."
 ;;; easy-mmode-define-navigation
 ;;;
 
-(defmacro easy-mmode-define-navigation (base re &optional name endfun)
+(defmacro easy-mmode-define-navigation (base re &optional name endfun narrowfun)
   "Define BASE-next and BASE-prev to navigate in the buffer.
 RE determines the places the commands should move point to.
 NAME should describe the entities matched by RE.  It is used to build
@@ -427,10 +427,20 @@ NAME should describe the entities matched by RE.  It is used to build
 BASE-next also tries to make sure that the whole entry is visible by
   searching for its end (by calling ENDFUN if provided or by looking for
   the next entry) and recentering if necessary.
-ENDFUN should return the end position (with or without moving point)."
+ENDFUN should return the end position (with or without moving point).
+NARROWFUN non-nil means to check for narrowing before moving, and if
+found, do widen first and then call NARROWFUN with no args after moving."
   (let* ((base-name (symbol-name base))
         (prev-sym (intern (concat base-name "-prev")))
-        (next-sym (intern (concat base-name "-next"))))
+        (next-sym (intern (concat base-name "-next")))
+         (check-narrow-maybe (when narrowfun
+                               '(setq was-narrowed-p
+                                      (prog1 (or (/= (point-min) 1)
+                                                 (/= (point-max)
+                                                     (1+ (buffer-size))))
+                                        (widen)))))
+         (re-narrow-maybe (when narrowfun
+                            `(when was-narrowed-p (,narrowfun)))))
     (unless name (setq name base-name))
     `(progn
        (add-to-list 'debug-ignored-errors
@@ -441,26 +451,33 @@ ENDFUN should return the end position (with or without moving point)."
         (unless count (setq count 1))
         (if (< count 0) (,prev-sym (- count))
           (if (looking-at ,re) (setq count (1+ count)))
-          (if (not (re-search-forward ,re nil t count))
-              (if (looking-at ,re)
-                  (goto-char (or ,(if endfun `(,endfun)) (point-max)))
-                (error "No next %s" ,name))
-            (goto-char (match-beginning 0))
-            (when (and (eq (current-buffer) (window-buffer (selected-window)))
-                       (interactive-p))
-              (let ((endpt (or (save-excursion
-                                 ,(if endfun `(,endfun)
-                                    `(re-search-forward ,re nil t 2)))
-                               (point-max))))
-                (unless (pos-visible-in-window-p endpt nil t)
-                  (recenter '(0))))))))
+           (let (was-narrowed-p)
+             ,check-narrow-maybe
+             (if (not (re-search-forward ,re nil t count))
+                 (if (looking-at ,re)
+                     (goto-char (or ,(if endfun `(,endfun)) (point-max)))
+                   (error "No next %s" ,name))
+               (goto-char (match-beginning 0))
+               (when (and (eq (current-buffer) (window-buffer (selected-window)))
+                          (interactive-p))
+                 (let ((endpt (or (save-excursion
+                                    ,(if endfun `(,endfun)
+                                       `(re-search-forward ,re nil t 2)))
+                                  (point-max))))
+                   (unless (pos-visible-in-window-p endpt nil t)
+                     (recenter '(0))))))
+             ,re-narrow-maybe)))
        (defun ,prev-sym (&optional count)
         ,(format "Go to the previous COUNT'th %s" (or name base-name))
         (interactive)
         (unless count (setq count 1))
         (if (< count 0) (,next-sym (- count))
-          (unless (re-search-backward ,re nil t count)
-            (error "No previous %s" ,name)))))))
+           (let (was-narrowed-p)
+             ,check-narrow-maybe
+             (unless (re-search-backward ,re nil t count)
+               (error "No previous %s" ,name))
+             ,re-narrow-maybe))))))
+
 
 (provide 'easy-mmode)