aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2007-10-20 01:46:38 +0000
committerStefan Monnier2007-10-20 01:46:38 +0000
commitcc34934141dbd44b4cbf7a110e2bd2e3f92cf422 (patch)
treeb24837344c125417c19a3337fc00cd032657b10c
parent54a2247d6e1c0b6abb8df6808130797f2a5eec50 (diff)
downloademacs-cc34934141dbd44b4cbf7a110e2bd2e3f92cf422.tar.gz
emacs-cc34934141dbd44b4cbf7a110e2bd2e3f92cf422.zip
(easy-mmode-define-navigation):
Add `body' arg. Cleanup the check-narrow-maybe/re-narrow-maybe mess.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/emacs-lisp/easy-mmode.el62
2 files changed, 35 insertions, 32 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e0d0e5dd07b..a9cf6c9078b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,8 @@
12007-10-20 Stefan Monnier <monnier@iro.umontreal.ca> 12007-10-20 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * emacs-lisp/easy-mmode.el (easy-mmode-define-navigation):
4 Add `body' arg. Cleanup the check-narrow-maybe/re-narrow-maybe mess.
5
3 * vc-bzr.el (vc-bzr-diff-tree): 6 * vc-bzr.el (vc-bzr-diff-tree):
4 * vc-git.el (vc-git-diff-tree): 7 * vc-git.el (vc-git-diff-tree):
5 * vc-hg.el (vc-hg-diff-tree): 8 * vc-hg.el (vc-hg-diff-tree):
@@ -7,8 +10,6 @@
7 * vc-mtn.el (vc-mtn-diff-tree): 10 * vc-mtn.el (vc-mtn-diff-tree):
8 * vc-svn.el (vc-svn-diff-tree): Remove. 11 * vc-svn.el (vc-svn-diff-tree): Remove.
9 12
102007-10-20 Stefan Monnier <monnier@iro.umontreal.ca>
11
12 * vc-mtn.el (vc-mtn-revision-completion-table): 13 * vc-mtn.el (vc-mtn-revision-completion-table):
13 * vc-cvs.el (vc-cvs-revision-completion-table): 14 * vc-cvs.el (vc-cvs-revision-completion-table):
14 * vc-arch.el (vc-arch-revision-completion-table): 15 * vc-arch.el (vc-arch-revision-completion-table):
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index da0b76808d5..d3d9e5fdca0 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -478,7 +478,8 @@ CSS contains a list of syntax specifications of the form (CHAR . SYNTAX)."
478;;; easy-mmode-define-navigation 478;;; easy-mmode-define-navigation
479;;; 479;;;
480 480
481(defmacro easy-mmode-define-navigation (base re &optional name endfun narrowfun) 481(defmacro easy-mmode-define-navigation (base re &optional name endfun narrowfun
482 &rest body)
482 "Define BASE-next and BASE-prev to navigate in the buffer. 483 "Define BASE-next and BASE-prev to navigate in the buffer.
483RE determines the places the commands should move point to. 484RE determines the places the commands should move point to.
484NAME should describe the entities matched by RE. It is used to build 485NAME should describe the entities matched by RE. It is used to build
@@ -488,17 +489,20 @@ BASE-next also tries to make sure that the whole entry is visible by
488 the next entry) and recentering if necessary. 489 the next entry) and recentering if necessary.
489ENDFUN should return the end position (with or without moving point). 490ENDFUN should return the end position (with or without moving point).
490NARROWFUN non-nil means to check for narrowing before moving, and if 491NARROWFUN non-nil means to check for narrowing before moving, and if
491found, do `widen' first and then call NARROWFUN with no args after moving." 492found, do `widen' first and then call NARROWFUN with no args after moving.
493BODY is executed after moving to the destination location."
494 (declare (indent 5) (debug (exp exp exp def-form def-form &rest def-body)))
492 (let* ((base-name (symbol-name base)) 495 (let* ((base-name (symbol-name base))
493 (prev-sym (intern (concat base-name "-prev"))) 496 (prev-sym (intern (concat base-name "-prev")))
494 (next-sym (intern (concat base-name "-next"))) 497 (next-sym (intern (concat base-name "-next")))
495 (check-narrow-maybe 498 (when-narrowed
496 (when narrowfun 499 (lambda (body)
497 '(setq was-narrowed 500 (if (null narrowfun) body
498 (prog1 (or (< (- (point-max) (point-min)) (buffer-size))) 501 `(let ((was-narrowed
499 (widen))))) 502 (prog1 (or (< (- (point-max) (point-min)) (buffer-size)))
500 (re-narrow-maybe (when narrowfun 503 (widen))))
501 `(when was-narrowed (,narrowfun))))) 504 ,body
505 (when was-narrowed (,narrowfun)))))))
502 (unless name (setq name base-name)) 506 (unless name (setq name base-name))
503 `(progn 507 `(progn
504 (add-to-list 'debug-ignored-errors 508 (add-to-list 'debug-ignored-errors
@@ -509,33 +513,31 @@ found, do `widen' first and then call NARROWFUN with no args after moving."
509 (unless count (setq count 1)) 513 (unless count (setq count 1))
510 (if (< count 0) (,prev-sym (- count)) 514 (if (< count 0) (,prev-sym (- count))
511 (if (looking-at ,re) (setq count (1+ count))) 515 (if (looking-at ,re) (setq count (1+ count)))
512 (let (was-narrowed) 516 ,(funcall when-narrowed
513 ,check-narrow-maybe 517 `(if (not (re-search-forward ,re nil t count))
514 (if (not (re-search-forward ,re nil t count)) 518 (if (looking-at ,re)
515 (if (looking-at ,re) 519 (goto-char (or ,(if endfun `(,endfun)) (point-max)))
516 (goto-char (or ,(if endfun `(,endfun)) (point-max))) 520 (error "No next %s" ,name))
517 (error "No next %s" ,name)) 521 (goto-char (match-beginning 0))
518 (goto-char (match-beginning 0)) 522 (when (and (eq (current-buffer) (window-buffer (selected-window)))
519 (when (and (eq (current-buffer) (window-buffer (selected-window))) 523 (interactive-p))
520 (interactive-p)) 524 (let ((endpt (or (save-excursion
521 (let ((endpt (or (save-excursion 525 ,(if endfun `(,endfun)
522 ,(if endfun `(,endfun) 526 `(re-search-forward ,re nil t 2)))
523 `(re-search-forward ,re nil t 2))) 527 (point-max))))
524 (point-max)))) 528 (unless (pos-visible-in-window-p endpt nil t)
525 (unless (pos-visible-in-window-p endpt nil t) 529 (recenter '(0)))))))
526 (recenter '(0)))))) 530 ,@body))
527 ,re-narrow-maybe)))
528 (put ',next-sym 'definition-name ',base) 531 (put ',next-sym 'definition-name ',base)
529 (defun ,prev-sym (&optional count) 532 (defun ,prev-sym (&optional count)
530 ,(format "Go to the previous COUNT'th %s" (or name base-name)) 533 ,(format "Go to the previous COUNT'th %s" (or name base-name))
531 (interactive "p") 534 (interactive "p")
532 (unless count (setq count 1)) 535 (unless count (setq count 1))
533 (if (< count 0) (,next-sym (- count)) 536 (if (< count 0) (,next-sym (- count))
534 (let (was-narrowed) 537 ,(funcall when-narrowed
535 ,check-narrow-maybe 538 `(unless (re-search-backward ,re nil t count)
536 (unless (re-search-backward ,re nil t count) 539 (error "No previous %s" ,name)))
537 (error "No previous %s" ,name)) 540 ,@body))
538 ,re-narrow-maybe)))
539 (put ',prev-sym 'definition-name ',base)))) 541 (put ',prev-sym 'definition-name ',base))))
540 542
541 543