summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2017-07-01 00:23:11 -0400
committerKyle Meyer <kyle@kyleam.com>2017-07-01 00:48:08 -0400
commit17d7a40875861a198e4eb75bd509be8ea270f0b2 (patch)
tree8010370e28a44423a5e1207a5e6adcd885543aed /lisp
parent09d8064c176c889742cf825168c941173cbe491d (diff)
downloademacs.d-17d7a40875861a198e4eb75bd509be8ea270f0b2.tar.gz
diff-review: Add commands to move to the previous/next comment
Diffstat (limited to 'lisp')
-rw-r--r--lisp/km-diff.el31
1 files changed, 30 insertions, 1 deletions
diff --git a/lisp/km-diff.el b/lisp/km-diff.el
index a862b80..f1801e9 100644
--- a/lisp/km-diff.el
+++ b/lisp/km-diff.el
@@ -1,4 +1,4 @@
-;;; km-diff.el --- Diff-related extensions
+;;; km-diff.el --- Diff-related extensions -*- lexical-binding: t; -*-
;; Copyright (C) 2012-2016 Kyle Meyer <kyle@kyleam.com>
@@ -81,6 +81,8 @@
(defvar km/diff-review-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-w") #'km/diff-review-copy-comment)
+ (define-key map (kbd "C-c C-n") #'km/diff-review-next-comment)
+ (define-key map (kbd "C-c C-p") #'km/diff-review-previous-comment)
map)
"Keymap for Diff Review mode.")
@@ -173,5 +175,32 @@ fall back to `kill-region'."
(set-buffer-modified-p nil)
(pop-to-buffer (current-buffer)))))
+(defun km/diff-review-next-comment (&optional n)
+ "Move to the Nth next comment.
+If N is negative, move backward instead."
+ (interactive "p")
+ (when (/= n 0)
+ (pcase-let ((`(,search-fn ,bound-fn ,incr-func)
+ (if (< n 0)
+ (list #'re-search-backward #'car #'1+)
+ (list #'re-search-forward #'cdr #'1-))))
+ (letrec ((move
+ (lambda (n)
+ (let ((bounds (km/diff-review--comment-bounds)))
+ (when bounds
+ (goto-char (funcall bound-fn bounds)))
+ (funcall search-fn "^:" nil t)
+ (if (= n 0)
+ (goto-char (car bounds))
+ (funcall move
+ (funcall incr-func n)))))))
+ (funcall move n)))))
+
+(defun km/diff-review-previous-comment (&optional n)
+ "Move to the Nth previous comment.
+If N is negative, move to forward instead."
+ (interactive "p")
+ (km/diff-review-next-comment (- n)))
+
(provide 'km-diff)
;;; km-diff.el ends here