]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/easy-mmode.el
Add a provide statement.
[gnu-emacs] / lisp / emacs-lisp / easy-mmode.el
index 6b9c593915ff82b373493e0980a1fa1ddca1a650..b6b91710ed426cd5187d5936bb633c52c35e9318 100644 (file)
@@ -1,6 +1,6 @@
 ;;; easy-mmode.el --- easy definition for major and minor modes
 
-;; Copyright (C) 1997, 2000, 2001, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 1997,2000,01,02,03,2004  Free Software Foundation, Inc.
 
 ;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr>
 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
@@ -209,7 +209,7 @@ With zero or negative ARG turn mode off.
         ,@body
         ;; The on/off hooks are here for backward compatibility only.
         (run-hooks ',hook (if ,mode ',hook-on ',hook-off))
-        (if (interactive-p)
+        (if (called-interactively-p)
             (progn
               ,(if globalp `(customize-mark-as-set ',mode))
               (unless (current-message)
@@ -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,11 +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"))))
-    (unless name (setq name (symbol-name base-name)))
+        (next-sym (intern (concat base-name "-next")))
+         (check-narrow-maybe
+         (when narrowfun
+           '(setq was-narrowed
+                  (prog1 (or (< (- (point-max) (point-min)) (buffer-size)))
+                    (widen)))))
+         (re-narrow-maybe (when narrowfun
+                            `(when was-narrowed (,narrowfun)))))
+    (unless name (setq name base-name))
     `(progn
        (add-to-list 'debug-ignored-errors
                    ,(concat "^No \\(previous\\|next\\) " (regexp-quote name)))
@@ -440,28 +449,36 @@ ENDFUN should return the end position (with or without moving point)."
         (interactive)
         (unless count (setq count 1))
         (if (< count 0) (,prev-sym (- count))
-          (if (looking-at ,re) (incf count))
-          (if (not (re-search-forward ,re nil t count))
-              (if (looking-at ,re)
-                  (goto-char (or ,(if endfun `(,endfun)) (point-max)))
-                (error ,(format "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))))))))
+          (if (looking-at ,re) (setq count (1+ count)))
+           (let (was-narrowed)
+             ,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 ,(format "No previous %s" name))))))))
+           (let (was-narrowed)
+             ,check-narrow-maybe
+             (unless (re-search-backward ,re nil t count)
+               (error "No previous %s" ,name))
+             ,re-narrow-maybe))))))
+
 
 (provide 'easy-mmode)
 
+;;; arch-tag: d48a5250-6961-4528-9cb0-3c9ea042a66a
 ;;; easy-mmode.el ends here