]> git.eshelyaron.com Git - emacs.git/commitdiff
Add emacs-news-previous-untagged-entry command
authorLars Ingebrigtsen <larsi@gnus.org>
Sat, 16 Apr 2022 16:35:11 +0000 (18:35 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 16 Apr 2022 16:35:20 +0000 (18:35 +0200)
* lisp/textmodes/emacs-news-mode.el
(emacs-news-next-untagged-entry): Allow searching backward.
(emacs-news-previous-untagged-entry): New command and keystroke.

lisp/textmodes/emacs-news-mode.el

index 340187e5fd4c472a77a1de7d7e0c0e805acc5910..85cbb1847bbc9fb7012018a0ae01f4cd3e84f5f2 100644 (file)
@@ -41,6 +41,7 @@
 
 (defvar-keymap emacs-news-mode-map
   "C-c C-s" #'emacs-news-next-untagged-entry
+  "C-c C-r" #'emacs-news-previous-untagged-entry
   "C-c C-n" #'emacs-news-count-untagged-entries)
 
 (defvar emacs-news-mode-font-lock-keywords
    (t
     (fill-paragraph justify))))
 
-(defun emacs-news-next-untagged-entry ()
-  "Go to the next untagged NEWS entry."
-  (interactive nil emacs-news-mode)
+(defun emacs-news-next-untagged-entry (&optional reverse)
+  "Go to the next untagged NEWS entry.
+If REVERSE (interactively, the prefix), go to the previous
+untagged NEWS entry."
+  (interactive "P" emacs-news-mode)
   (let ((start (point))
         (found nil))
     ;; Don't consider the current line, because that would stop
     ;; progress if calling this command repeatedly.
-    (forward-line 1)
+    (unless reverse
+      (forward-line 1))
     (while (and (not found)
-                (re-search-forward "\\(\\*+\\) " nil t))
+                (funcall (if reverse #'re-search-backward
+                           #'re-search-forward)
+                         "^\\(\\*+\\) " nil t))
       (unless (save-excursion
                 (forward-line -1)
                 (looking-at "---$\\|\\+\\+\\+$"))
         ;; more asterisks).
         (let ((level (length (match-string 1))))
           (when (save-excursion
+                  (goto-char (match-end 0))
                   (re-search-forward "^\\(\\*+\\) " nil t))
             (when (<= (length (match-string 1)) level)
               ;; It wasn't a sub-heading, so we've found one.
       (goto-char start)
       nil)))
 
+(defun emacs-news-previous-untagged-entry ()
+  "Go to the previous untagged NEWS entry."
+  (interactive nil emacs-news-mode)
+  (emacs-news-next-untagged-entry t))
+
 (defun emacs-news-count-untagged-entries ()
   "Say how many untagged entries there are in the current NEWS buffer."
   (interactive nil emacs-news-mode)