summaryrefslogtreecommitdiff
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:47:10 -0400
commit09d8064c176c889742cf825168c941173cbe491d (patch)
tree75498867b006b1a050feebf7e8b852b7a16908e3
parent483ca890a21b033ba63e1849f96a4beeddb93668 (diff)
downloademacs.d-09d8064c176c889742cf825168c941173cbe491d.tar.gz
diff-review: Extract bounds logic into separate function
The same calculation will be useful in the next commit, which adds commands for moving to the next/previous comment.
-rw-r--r--lisp/km-diff.el41
1 files changed, 23 insertions, 18 deletions
diff --git a/lisp/km-diff.el b/lisp/km-diff.el
index b768820..a862b80 100644
--- a/lisp/km-diff.el
+++ b/lisp/km-diff.el
@@ -119,33 +119,38 @@ When this mode is turned on
(when font-lock-mode
(font-lock-flush)))
+(defun km/diff-review--comment-bounds ()
+ (and (eq ?: (char-after (point-at-bol)))
+ (cons
+ (save-excursion (goto-char (point-at-bol))
+ (if (bobp)
+ (point)
+ (while (and (eq ?: (char-after))
+ (not (bobp)))
+ (forward-line -1))
+ (forward-line)
+ (point)))
+ (save-excursion (goto-char (point-at-bol))
+ (while (and (eq ?: (char-after))
+ (not (eobp)))
+ (forward-line 1))
+ (forward-line -1)
+ (point-at-eol)))))
+
(defun km/diff-review-copy-comment ()
"Copy the comment at point, stripping the leading ': '.
When there is no comment at point or when the region is active,
fall back to `kill-region'."
(interactive)
- (if (or (use-region-p)
- (not (eq ?: (char-after (point-at-bol)))))
- (call-interactively #'kill-region)
- (let ((beg (save-excursion (goto-char (point-at-bol))
- (if (bobp)
- (point)
- (while (and (eq ?: (char-after))
- (not (bobp)))
- (forward-line -1))
- (forward-line)
- (point))))
- (end (save-excursion (goto-char (point-at-bol))
- (while (and (eq ?: (char-after))
- (not (eobp)))
- (forward-line 1))
- (forward-line -1)
- (point-at-eol))))
+ (let (bounds)
+ (if (or (use-region-p)
+ (not (setq bounds (km/diff-review--comment-bounds))))
+ (call-interactively #'kill-region)
(message
"%s"
(kill-new
(thread-last
- (buffer-substring-no-properties beg end)
+ (buffer-substring-no-properties (car bounds) (cdr bounds))
(replace-regexp-in-string "^: ?" "")
(replace-regexp-in-string "\\`\\s-+" "")
(replace-regexp-in-string "\\s-+\\'" "")))))))