Emacsist RSS --- If never, make it ever: C-h C-h

Leave the cursor at start of match after isearch

7346

这里 查看更多 Emacs 相关推荐文章最新 Emacs 圈的动态. 欢迎关注微信公众账号: Emacsist

Have you ever stopped to think about why isearch leaves point at the end of the match? It does make some intuitive sense to leave you after the characters you have just typed, but that doesn’t make it the most practical behaviour.

This is something I’d never even given half a thought in the past, but it’s one of the first things a friend questioned me as he was diving into Emacs (yes, the same one as last week). Why not leave the cursor at the start of the match, instead of the end?

It’s great when someone’s fresh perspective shakes new ideas into my gradually-calcifying init file, so I immediately started looking for a way to do this. Fortunately, Google was quick to find me an answer, in the dotfiles of one Sylvain Rousseau. I should go through the entire file later to look for more snippets, but for the current purpose, the following is all we need.

(add-hook 'isearch-mode-end-hook
          #'endless/goto-match-beginning)
(defun endless/goto-match-beginning ()
  "Go to the start of current isearch match.
Use in `isearch-mode-end-hook'."
  (when (and isearch-forward
             (number-or-marker-p isearch-other-end)
             (not mark-active)
             (not isearch-mode-end-hook-quit))
    (goto-char isearch-other-end)))

After using this for a few days, I’ve already ran into a couple of cases where I would have preferred the original behaviour. Still, the net balance has been positive so far so it’s probably going to stay.

原文出处: EndlessParenthese
原文地址: http://endlessparentheses.com/leave-the-cursor-at-start-of-match-after-isearch.html?source=rss
原文时间: 2016-03-21 08:00
本文地址: http://emacsist.com/10812
整理时间: 2016-03-22 23:06

本文由 Hick 整理,转载请保留以上信息;
COPYLEFTThe articles on this site come from Internet, thanks to all the original authors.
      If anything about COPYRIGHT, or LEFT, please contact Emacsist at gmail dot com .