Skip to content

Instantly share code, notes, and snippets.

@narendraj9
Last active February 7, 2019 18:41
Show Gist options
  • Select an option

  • Save narendraj9/d49bbbc51a83aaa9b8fb07d5d82a0025 to your computer and use it in GitHub Desktop.

Select an option

Save narendraj9/d49bbbc51a83aaa9b8fb07d5d82a0025 to your computer and use it in GitHub Desktop.

Revisions

  1. narendraj9 revised this gist Feb 7, 2019. 1 changed file with 71 additions and 9 deletions.
    80 changes: 71 additions & 9 deletions magit-blame--search.el
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,84 @@
    ;;; -- Magit blame swiper results
    (require 'magit-blame)
    ;;; -- Magit blame swiper results
    (require 'dash)
    (defun magit-blame--current-committer ()
    (->> (overlays-at (point))
    (-keep (lambda (ov)
    (when (and (= (point) (overlay-start ov)))
    (assoc-default "committer"
    (overlay-get ov 'magit-blame-revinfo)))))
    (car)))
    (when (and (boundp 'magit-blame-read-only-mode)
    magit-blame-read-only-mode)
    (->> (overlays-at (point))
    (-keep (lambda (ov)
    (when (and (= (line-beginning-position) (overlay-start ov)))
    (assoc-default "committer"
    (overlay-get ov 'magit-blame-revinfo)))))
    (apply #'concat)
    ((lambda (s) (when (not (string-empty-p s)) s))))))

    (defun magit-blame--swiper-line (orig-line)
    (if-let ((c (and magit-blame-read-only-mode
    (magit-blame--current-committer))))
    (if-let ((c (magit-blame--current-committer)))
    (format (format "%%s %%%ds"
    (max 0 (- (window-width) (length orig-line) 15)))
    orig-line c)
    orig-line))

    (defun magit-blame--swiper-update-input-ivy ()
    "Called when `ivy' input is updated."
    (with-ivy-window
    (swiper--cleanup)
    (when (> (length (ivy-state-current ivy-last)) 0)
    (let* ((regexp-or-regexps (funcall ivy--regex-function ivy-text))
    (regexps
    (if (listp regexp-or-regexps)
    (mapcar #'car (cl-remove-if-not #'cdr regexp-or-regexps))
    (list regexp-or-regexps))))
    (dolist (re regexps)
    (let* ((re (replace-regexp-in-string
    " " "\t"
    re))
    (str (get-text-property 0 'swiper-line-number (ivy-state-current ivy-last)))
    (num (if (string-match "^[0-9]+" str)
    (string-to-number (match-string 0 str))
    0)))
    (unless (memq this-command '(ivy-yank-word
    ivy-yank-symbol
    ivy-yank-char
    scroll-other-window))
    (when (cl-plusp num)
    (unless (if swiper--current-line
    (eq swiper--current-line num)
    (eq (line-number-at-pos) num))
    (goto-char swiper--point-min)
    (if swiper-use-visual-line
    (line-move (1- num))
    (forward-line (1- num))))
    (if (and (equal ivy-text "")
    (>= swiper--opoint (line-beginning-position))
    (<= swiper--opoint (line-end-position)))
    (goto-char swiper--opoint)
    (if (eq swiper--current-line num)
    (when swiper--current-match-start
    (goto-char swiper--current-match-start))
    (setq swiper--current-line num))
    (when (re-search-forward re (line-end-position) t)
    (setq swiper--current-match-start (match-beginning 0)))
    ;; If committer's name matches override
    ;; `swiper--current-match-start'.
    (when (and (magit-blame--current-committer)
    (string-match re (magit-blame--current-committer)))
    (setq swiper--current-match-start (line-beginning-position))))
    (isearch-range-invisible (line-beginning-position)
    (line-end-position))
    (unless (and (>= (point) (window-start))
    (<= (point) (window-end (ivy-state-window ivy-last) t)))
    (recenter))
    (setq swiper--current-window-start (window-start))))
    (swiper--add-overlays
    re
    (max (window-start) swiper--point-min)
    (min (window-end (selected-window) t) swiper--point-max))))))))

    (add-function :filter-return
    (symbol-function #'swiper--line)
    #'magit-blame--swiper-line)
    #'magit-blame--swiper-line)
    (add-function :override
    (symbol-function #'swiper--update-input-ivy)
    #'magit-blame--swiper-update-input-ivy)
  2. narendraj9 revised this gist Feb 7, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions magit-blame--search.el
    Original file line number Diff line number Diff line change
    @@ -12,11 +12,11 @@
    (defun magit-blame--swiper-line (orig-line)
    (if-let ((c (and magit-blame-read-only-mode
    (magit-blame--current-committer))))
    (format (format "%%s %%%ds" (- (window-width) (length orig-line)))
    (format (format "%%s %%%ds"
    (max 0 (- (window-width) (length orig-line) 15)))
    orig-line c)
    orig-line))

    (add-function :filter-return
    (symbol-function #'swiper--line)
    #'magit-blame--swiper-line)

    #'magit-blame--swiper-line)
  3. narendraj9 created this gist Feb 7, 2019.
    22 changes: 22 additions & 0 deletions magit-blame--search.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    ;;; -- Magit blame swiper results
    (require 'magit-blame)
    (require 'dash)
    (defun magit-blame--current-committer ()
    (->> (overlays-at (point))
    (-keep (lambda (ov)
    (when (and (= (point) (overlay-start ov)))
    (assoc-default "committer"
    (overlay-get ov 'magit-blame-revinfo)))))
    (car)))

    (defun magit-blame--swiper-line (orig-line)
    (if-let ((c (and magit-blame-read-only-mode
    (magit-blame--current-committer))))
    (format (format "%%s %%%ds" (- (window-width) (length orig-line)))
    orig-line c)
    orig-line))

    (add-function :filter-return
    (symbol-function #'swiper--line)
    #'magit-blame--swiper-line)