Mercurial > emacs
comparison lisp/emacs-lisp/easy-mmode.el @ 33358:a86c95343fa5
(easy-mmode-define-navigation):
Allow `next' to jump to after the end of the last match.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 09 Nov 2000 23:51:59 +0000 |
parents | 8b3f1e99c11a |
children | e8794ae4f856 |
comparison
equal
deleted
inserted
replaced
33357:482cbaef2af5 | 33358:a86c95343fa5 |
---|---|
517 ;;; | 517 ;;; |
518 | 518 |
519 (defmacro easy-mmode-define-navigation (base re &optional name endfun) | 519 (defmacro easy-mmode-define-navigation (base re &optional name endfun) |
520 "Define BASE-next and BASE-prev to navigate in the buffer. | 520 "Define BASE-next and BASE-prev to navigate in the buffer. |
521 RE determines the places the commands should move point to. | 521 RE determines the places the commands should move point to. |
522 NAME should describe the entities matched by RE and is used to build | 522 NAME should describe the entities matched by RE. It is used to build |
523 the docstrings of the two functions. | 523 the docstrings of the two functions. |
524 BASE-next also tries to make sure that the whole entry is visible by | 524 BASE-next also tries to make sure that the whole entry is visible by |
525 searching for its end (by calling ENDFUN if provided or by looking for | 525 searching for its end (by calling ENDFUN if provided or by looking for |
526 the next entry) and recentering if necessary. | 526 the next entry) and recentering if necessary. |
527 ENDFUN should return the end position (with or without moving point)." | 527 ENDFUN should return the end position (with or without moving point)." |
536 ,(format "Go to the next COUNT'th %s." name) | 536 ,(format "Go to the next COUNT'th %s." name) |
537 (interactive) | 537 (interactive) |
538 (unless count (setq count 1)) | 538 (unless count (setq count 1)) |
539 (if (< count 0) (,prev-sym (- count)) | 539 (if (< count 0) (,prev-sym (- count)) |
540 (if (looking-at ,re) (incf count)) | 540 (if (looking-at ,re) (incf count)) |
541 (unless (re-search-forward ,re nil t count) | 541 (if (not (re-search-forward ,re nil t count)) |
542 (error ,(format "No next %s" name))) | 542 (if (looking-at ,re) |
543 (goto-char (match-beginning 0)) | 543 (goto-char (or ,(if endfun `(,endfun)) (point-max))) |
544 (when (eq (current-buffer) (window-buffer (selected-window))) | 544 (error ,(format "No next %s" name))) |
545 (let ((endpt (or (save-excursion | 545 (goto-char (match-beginning 0)) |
546 ,(if endfun `(,endfun) | 546 (when (eq (current-buffer) (window-buffer (selected-window))) |
547 `(re-search-forward ,re nil t 2))) | 547 (let ((endpt (or (save-excursion |
548 (point-max)))) | 548 ,(if endfun `(,endfun) |
549 (unless (<= endpt (window-end)) | 549 `(re-search-forward ,re nil t 2))) |
550 (recenter '(0))))))) | 550 (point-max)))) |
551 (unless (pos-visible-in-window-p endpt nil t) | |
552 (recenter '(0)))))))) | |
551 (defun ,prev-sym (&optional count) | 553 (defun ,prev-sym (&optional count) |
552 ,(format "Go to the previous COUNT'th %s" (or name base-name)) | 554 ,(format "Go to the previous COUNT'th %s" (or name base-name)) |
553 (interactive) | 555 (interactive) |
554 (unless count (setq count 1)) | 556 (unless count (setq count 1)) |
555 (if (< count 0) (,next-sym (- count)) | 557 (if (< count 0) (,next-sym (- count)) |