Group Emacs Search Functions using Hydra17 Apr 2015
I am a search-guy: when I want to know something, I use the search functionality to locate to where has the keyword, and I didn't use my eyes to scan the page, it's too slow and harmful.
Emacs provides powerful functionality to do searching. For example, I use these commands very often (with the key-binds),
isearch(C-s), search for a string and move the cursor to there,
helm-swoop(C-F1), find all the occurrences of a string, pull out the lines containing the string to another buffer where I can edit and save,
helm-swoopto multiple buffers, very handy if I want to know where a function is called in different buffers.
helm-projectile-grepC p s g, find which files in current project contains a specific string, similar to
helm-multi-swooplimits the search to files in project directory.
I love doing searching in Emacs, but the problem is to have to remember all the key-binds for different tasks. Also, sometimes, I forgot about what alternatives I have and usually go with the one that I most familiar with, which usually means not the right one. I sometimes realise I use
isearch multiple times to do what
ace-jump-word-mode can achieve by just once.
Org-mode Hydras incoming! gives me some idea to group all these functions together, and press a single key to perform different tasks, so this can free my mind from remembering all the key-binds. Also, I can write the few lines of text to reminds myself when to do what, and this potentially can solve problem two.
Here is the hydra implementation for searching:
(defhydra hydra-search (:color blue :hint nil) " Current Buffer : _i_search helm-_s_woop _a_ce-jump-word Multiple Buffers : helm-multi-_S_woop Project Directory: projectile-_g_rep helm-projectile-_G_rep " ("i" isearch-forward) ("s" helm-swoop) ("a" ace-jump-word-mode) ("S" helm-multi-swoop) ("g" projectile-grep) ("G" helm-projectile-grep)) (global-set-key [f4] 'hydra-search/body)
So next time, when I want to search something, I just press F4, and then it brings up all the choices I have, and I don't need to worry about the key-binds or which to use! That's cool!
I am looking forward simplifying my Emacs workflow using
hydra package, the key challenge is to identify the logical similarities among the tasks and then group them together accordingly. For
hydra-search(), it is "search something on somewhere".