Emacs Lisp Blog Post:

Emacs Lisp code: Mouse-Clickable Search Results in Helm (with some glitches)
12/4/2015

Post Below
12/4/2015 - Emacs Lisp code: Mouse-Clickable Search Results in Helm (with some glitches) (Emacs Lisp)

    Hide/Show:


   ▲ Top  ▼ Bottom  △ TOC
Emacs Lisp code: Mouse-Clickable Search Results in Helm (with some glitches)
Friday, December 4th, 2015
14:24:50 GMT

Emacs Lisp

Helm is one of the most useful add-ons I've found for the GNU Emacs operating system - uh, I mean, text editor - so far.

Helm makes it tremendously easier to find all sorts of things such as files, buffers, function names, variable names, and text within files or buffers. In many Helm modes, you can just type a few letters, and Helm will narrow down your search and instantly display updated results.

Helm also gives you a way to browse and search your "imenu", which is where php-mode puts a list of functions defined in the PHP file (or multifile!) you're currently looking at.

And you can easily go to any of those functions by selecting its name in the Helm search results and pressing Return or Ctrl-j. Or, thanks to the below code, by double-clicking or right-clicking on any item in the Helm search results with your mouse.


By default, the Helm add-on has no mouse capabilities at all. So, I kept accidentally trying to click Helm results, resulting in nothing happening.

That seemed like the sort of thing someone probably already wrote an add-on to fix, so I searched the web, and soon found this post on Reddit:

Select helm candidate by using mouse (click)

To my delight, that code worked quite well out of the box. But, it globally overwrote my preferred mouse click settings, so, I had to figure out how to make some custom mouse click settings that would only be in effect while Helm was running.

Even though my final result wasn't very much code in the end, it still took me hours and lots of trial and error to figure out how to do it, and I wasn't sure I ever would figure it out. But somehow, I managed to cobble together the below code, which uses most of the code provided in the abovementioned Reddit post, plus some other code to create a custom minor mode which is supposed to only run when Helm is active.

Since I'm such an Emacs newbie, it would have taken quite a lot longer if I hadn't been able to stand on the shoulders of numerous giants, such as the author of the code in the abovementioned Reddit post, and all the authors of all the web pages and documentation I read that helped me figure out how to do this.

Thanks to everyone!


I still haven't figured out how to make the below code not get confused by mouse-wheel scrolling, and there could be other glitches too.

But, it still makes Emacs and Helm more cozy and intuitive to use.


I'm using GNU Emacs 24.5.1. And I'm not sure what version of the Helm add-on - all I know is I downloaded it on Nov. 13, 2015 at 6:22:26 AM EST from GitHub.

The below code only requires the Helm add-on, and can just be copied and pasted into your .emacs settings file, probably somewhere after the place in your settings code where you loaded Helm.

While trying to debug the above, I figured out that one glitch I had actually wasn't caused by the above.

I figured out that the Purpose add-on interferes with Helm by somehow making Helm open help text in the wrong window pane - usually Helm's own window pane - which accidentally kills Helm sessions. The only solution to that I found so far was to turn off the Purpose add-on.


Edit, 2:47/3:08 PM EST. Added some missing backslashes to the above code. And changed some wording.

By the way, I actually often make small, usually unmentioned edits to my blog posts after I publish them - but this edit seems important to point out because the lack of those backslashes probably could have stopped the code from working properly.

I guess the vanishing backslash problem is another thing I need to fix in my WordsPlatz blog software. WordsPlatz has served me well with scarcely any changes since 2009, but, I actually am still interested in updating it and improving it.

   ▲ Top  ▼ Bottom  △ TOC


    Hide/Show: