Emacs kaizen: ace-isearch combines ace-jump-mode and helm-swoop

This entry is part 3 of 4 in the series Emacs Kaizen

I’m a fan of clever little things that change their behaviour depending on what you’re doing while letting you mentally think of it as just one function.

ace-isearch looks like it’ll be useful for collapsing three different functions into one mental thing in my head:

  • jumping to a specific character that I can see (ace-jump-mode)
  • searching through a buffer for a few characters (isearch)
  • doing helm-swoop to quickly preview and navigate through matching lines in a buffer

If you install the ace-isearch package and turn on global-ace-isearch-mode, then searching for a single character triggers ace-jump-mode, searching for less than 5 characters triggers isearch, and anything longer triggers helm-swoop-from-isearch. You can customize those thresholds, of course.


Series Navigation« Emacs kaizen: helm-swoop and editing
  • Just found this, brilliant! Simple, to make it even more efficient I’ve added defadvice to check if a region is marked in which case it searches for that:

    (defadvice isearch-forward (around search-standard-or-selection-forward activate)
    (if (use-region-p)
    (search-selection (region-beginning) (region-end))
    ad-do-it)) ;; do the same with isearch-backward

    • Hmm, you’re right, maybe I should get ace-isearch to do something similar… Usually, if I want to search within a region, I’ll just narrow to it anyway. =)

    • Jaehyun Yeom

      Not sure if I’m understanding correctly, but the downside may be when we want to jump to change the region range. The pattern I use often is C-Spc to set mark (transient-mark) and page down a bit and C-s to jump to the end of the region that I want to set when I see it.

      • Hmmm… I know there are all sorts of keyboard shortcuts in isearch and helm-swoop that I haven’t explored yet. There’s probably already a quick way to pull in the current word or region. C-w copies in the next character or word, apparently. Let me think about what an interesting behaviour might be like… Maybe one could hit different keys depending on whether you want to search only within the region, or copy the region into the string, or use that as the beginning of the region and then search for what will be the end of the region? I’m not sure if I’m going to remember or use all that, though… =) With Emacs, the toughest part is usually figuring out what you want Emacs to behave like!

  • Jaehyun Yeom

    Cool! I was just wondering how I could combine isearch-* and helm-swoop. Thank you very much!