diff options
author | Kyle Meyer <kyle@kyleam.com> | 2017-03-25 01:20:17 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2017-03-25 01:20:17 -0400 |
commit | 585b59c4839896e9d513604b7f1ef315e40ebfec (patch) | |
tree | 4cb2c0a09dffdf3870d677afc1ca9efafc3d0ff1 /lisp | |
parent | 8891202e6eb80c1162fd35cebcfa621ea586742e (diff) | |
download | emacs.d-585b59c4839896e9d513604b7f1ef315e40ebfec.tar.gz |
magit-log-select-guess-fixup-commit: Decouple from log format
When magit-log-show-refname-after-summary was non-nil, the previous
logic failed. Use magit-rev-format instead of regular expressions to
extract the subjects. As a result, we don't make any assumptions
about where the subject is positioned in a magit-log-select-mode line.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/km-magit.el | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/lisp/km-magit.el b/lisp/km-magit.el index 5f118af..56c1e67 100644 --- a/lisp/km-magit.el +++ b/lisp/km-magit.el @@ -247,22 +247,33 @@ and 'squash!' titles." (interactive (list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg)) 5))) - (let (ntop-end msgs commit-pts) + (let ((msg-fn (lambda () + (magit-rev-format + "%s" (magit-section-value (magit-current-section))))) + msgs commit-pts) (save-excursion - ;; Get limit for fixup/squash search. (goto-char (point-min)) - (setq ntop-end (line-end-position (1+ ntop))) ;; Get fixup and squash messages. - (while (re-search-forward "[a-z0-9]+ \\(fixup!\\|squash!\\) \\(.+\\)" - ntop-end t) - (push (match-string-no-properties 2) msgs)) + (while (re-search-forward (rx " " (or "fixup" "squash") "! ") + (line-end-position (1+ ntop)) + t) + (let ((msg (funcall msg-fn))) + (and msg + (string-match (rx string-start (or "fixup" "squash") "! " + (group (one-or-more not-newline))) + msg) + (push (cons (match-string-no-properties 1 msg) (line-end-position)) + msgs)))) (when (not msgs) (user-error "No fixup or squash commits found")) ;; Find earliest commit. - (dolist (msg msgs) - (goto-char (point-min)) - (when (re-search-forward (concat "[a-z0-9]+ " msg "\n") nil t) - (push (match-beginning 0) commit-pts)))) + (pcase-dolist (`(,msg . ,search-beg) msgs) + (goto-char search-beg) + (catch 'found + (while (search-forward msg nil t) + (when (string= msg (funcall msg-fn)) + (push (line-beginning-position) commit-pts) + (throw 'found t)))))) (if commit-pts (goto-char (apply #'max commit-pts)) (message "No matching commits found")))) |