Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Proposal: add swiper option to go to the start of the match, instead of its end #942
Hi, and thanks for this package.
Would you accept a PR which adds an option to swiper which will make swiper to go the beginning of the match, not its end?
Something like this:
diff --git a/swiper.el b/swiper.el index 7aa2875..754b9bf 100644 --- a/swiper.el +++ b/swiper.el @@ -683,36 +683,38 @@ WND, when specified is the window." (defun swiper--action (x) "Goto line X." (let ((ln (1- (read (or (get-text-property 0 'swiper-line-number x) (and (string-match ":\\([0-9]+\\):.*\\'" x) (match-string-no-properties 1 x)))))) (re (ivy--regex ivy-text))) (if (null x) (user-error "No candidates") (with-ivy-window (unless (equal (current-buffer) (ivy-state-buffer ivy-last)) (switch-to-buffer (ivy-state-buffer ivy-last))) (goto-char swiper--point-min) (funcall (if swiper-use-visual-line #'line-move #'forward-line) ln) (re-search-forward re (line-end-position) t) + (when (goto-char swiper--point-min) ;; and some other var is true, maybe `swiper-action-land-on-match-start` + (goto-char (match-beginning 0))) (swiper--ensure-visible) (cond (swiper-action-recenter (recenter)) (swiper--current-window-start (set-window-start (selected-window) swiper--current-window-start))) (when (/= (point) swiper--opoint) (unless (and transient-mark-mode mark-active) (when (eq ivy-exit 'done) (push-mark swiper--opoint t) (message "Mark saved where search started")))) (add-to-history 'regexp-search-ring re regexp-search-ring-max) (when (and (bound-and-true-p evil-mode) (eq evil-search-module 'evil-search)) (add-to-history 'evil-ex-search-history re) (setq evil-ex-search-pattern (list re t t))
After using vim, and now evil, I'm used to this behaviour - vim's and evil's default search (both evil's own search and evil's isearch wrapper) go to the start.
I common use case I have is:
Another use case I have (again vim habit):
It's all personal preference based on muscle memory I guess.
Look at this code already in
(when (and (bound-and-true-p evil-mode) (eq evil-search-module 'evil-search)) (add-to-history 'evil-ex-search-history re) (setq evil-ex-search-pattern (list re t t)) (when evil-ex-search-persistent-highlight (evil-ex-search-activate-highlight evil-ex-search-pattern)))
Maybe there's a way to make cgn to work with that.
Otherwise, please PR with a new user option, off by default.
I think adding the user option as proposed here (thus moving to beginning of match) is probably the way to go, if