branch: scratch/rfc-mode commit 355f25ee2a83b9c8adf4e30fac8dbc58a59946d2 Author: Daniel Martín <mardan...@yahoo.es> Commit: Daniel Martín <mardan...@yahoo.es>
Add commands to move to the previous/next RFC section * rfc-mode.el (rfc-mode-map): Bind "n" and "p" to `rfc-mode-next-section' and `rfc-mode-previous-section', respectively. (rfc-mode-next-section): Add `rfc-mode-next-section' and `rfc-mode-previous-section', which move point to the next and previous RFC section, respectively. --- rfc-mode.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/rfc-mode.el b/rfc-mode.el index cb64693b3f..91443b4dac 100644 --- a/rfc-mode.el +++ b/rfc-mode.el @@ -102,6 +102,8 @@ Assume RFC documents are named as e.g. rfc21.txt, rfc-index.txt." (define-key map (kbd "q") 'rfc-mode-quit) (define-key map (kbd "<prior>") 'rfc-mode-backward-page) (define-key map (kbd "<next>") 'rfc-mode-forward-page) + (define-key map (kbd "n") 'rfc-mode-next-section) + (define-key map (kbd "p") 'rfc-mode-previous-section) map) "The keymap for `rfc-mode'.") @@ -133,6 +135,31 @@ Assume RFC documents are named as e.g. rfc21.txt, rfc-index.txt." (rfc-mode-previous-header) (recenter 0)) +(defun rfc-mode-next-section (n) + "Move point to Nth next section (default 1)." + (interactive "p") + (let ((case-fold-search nil) + (start (point))) + (if (looking-at rfc-mode-title-regexp) + (forward-line 1)) + (if (re-search-forward rfc-mode-title-regexp (point-max) t n) + (beginning-of-line) + (goto-char (point-max)) + ;; The last line doesn't belong to any section. + (forward-line -1)) + ;; Ensure we never move back from the starting point. + (if (< (point) start) (goto-char start)))) + +(defun rfc-mode-previous-section (n) + "Move point to Nth previous section (default 1)." + (interactive "p") + (let ((case-fold-search nil)) + (if (looking-at rfc-mode-title-regexp) + (forward-line -1)) + (if (re-search-backward rfc-mode-title-regexp (point-min) t n) + (beginning-of-line) + (goto-char (point-min))))) + ;;;###autoload (defun rfc-mode-read (number) "Read the RFC document NUMBER."