From 17d7a40875861a198e4eb75bd509be8ea270f0b2 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sat, 1 Jul 2017 00:23:11 -0400 Subject: diff-review: Add commands to move to the previous/next comment --- lisp/km-diff.el | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'lisp') 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 @@ -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 -- cgit v1.2.3