Experimenting with a custom matcher, sorter, and highlighter

43 views
Skip to first unread message

Le Wang

unread,
Apr 13, 2013, 11:50:26 AM4/13/13
to emacs...@googlegroups.com, Thierry Volpiatto
Hi Thierry,

I'd like to play around with a custom matching function, and a custom sorting function and a custom highlighter.  Is there a good example of this?

This is for an implementation of flex that I'm playing around with.


--
Le

Thierry Volpiatto

unread,
Apr 14, 2013, 1:21:08 AM4/14/13
to Le Wang, emacs...@googlegroups.com
Hi Le,

Le Wang <l26...@gmail.com> writes:

> I'd like to play around with a custom matching function, and a custom
> sorting function and a custom highlighter. Is there a good example of this?

Normally, `matching` functions are for use with `candidates`
implementation of a source, and 'searching' for `candidates-in-buffer`,
this have limitations for `candidates-in-buffer` actually.
But in this case the both can be used,
see how I recently did in helm-bookmark.el, you will find the both
methods.

For a matching function, see in helm-buffers.el
`helm-buffer-match-major-mode`.

For highligthting, you will find filter functions in many places,
including the ones cited above.

For sorting see in helm-sys.el how top is sorted by CPU, MEM etc..

> This is for an implementation of flex that I'm playing around with.

I suggest you implement this with an attribute by source, adding this
attribute e.g (flexmatching) to a source would enable this matching
method in this source only.


--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997

Le Wang

unread,
Apr 14, 2013, 8:46:59 AM4/14/13
to Thierry Volpiatto, emacs...@googlegroups.com
I may be missing something, but the flow is not clear to me.

I have a match function that's quite complicated, it returns information on how to sort and highlight the match.  As it stands it looks like the "match" function gets a candidate as a string and returns non-nil when it's matched.  

I don't want to recalculate the match information when I do the sorting and highlighting in the "filtered-candidate-transformer"?
--
Le

Thierry Volpiatto

unread,
Apr 14, 2013, 2:17:47 PM4/14/13
to Le Wang, emacs...@googlegroups.com
Le Wang <l26...@gmail.com> writes:

> I may be missing something, but the flow is not clear to me.
>
> I have a match function that's quite complicated, it returns information on
> how to sort and highlight the match.

The match function should only match against candidates, sorting and
highlighting should happen in filtered-candidate-transformer or
candidate-transformer.


> As it stands it looks like the "match" function gets a candidate as a
> string and returns non-nil when it's matched.

Yes.

> I don't want to recalculate the match information when I do the sorting and
> highlighting in the "filtered-candidate-transformer"?

Just sort and highlight in filtered-candidate-transformer, see above.

Le Wang

unread,
Apr 15, 2013, 10:08:35 AM4/15/13
to Thierry Volpiatto, emacs...@googlegroups.com
On Mon, Apr 15, 2013 at 2:17 AM, Thierry Volpiatto <thierry....@gmail.com> wrote:
Just sort and highlight in filtered-candidate-transformer, see above.

Actually I must sort in the candidate-transformer, correct?  I only want to apply helm-candidate-number-limit to the sorted list, otherwise the best matches may already be gone by the time filtered-candidate-transformer runs?

It looks like the easiest way to do this is to make a new match method in helm-match-plugin.  The idea is that I want the first word of the pattern to be "flex" matched, but the following words should work the same as "multi3p".  What do you think about that?

 

--
Le

Thierry Volpiatto

unread,
Apr 15, 2013, 11:24:02 AM4/15/13
to Le Wang, emacs...@googlegroups.com
Le Wang <l26...@gmail.com> writes:

> On Mon, Apr 15, 2013 at 2:17 AM, Thierry Volpiatto <
> thierry....@gmail.com> wrote:
>
>> Just sort and highlight in filtered-candidate-transformer, see above.
>>
>
> Actually I must sort in the candidate-transformer, correct? I only want to
> apply helm-candidate-number-limit to the sorted list, otherwise the best
> matches may already be gone by the time filtered-candidate-transformer runs?

Sorry but I have not enough informations to figure out what you are
trying to do exactly.

> It looks like the easiest way to do this is to make a new match method in
> helm-match-plugin. The idea is that I want the first word of the pattern
> to be "flex" matched, but the following words should work the same as
> "multi3p". What do you think about that?

If you add a new function (flex) to a match attribute:

(defvar helm-source-test
'((name . "test")
(....)
(match . flex)))

this flex function will run and then all the other match-plugin
functions unless you use `match-strict` instead of match.

Le Wang

unread,
Apr 15, 2013, 12:30:13 PM4/15/13
to Thierry Volpiatto, emacs...@googlegroups.com
On Mon, Apr 15, 2013 at 11:24 PM, Thierry Volpiatto <thierry....@gmail.com> wrote:
Le Wang <l26...@gmail.com> writes:
Sorry but I have not enough informations to figure out what you are
trying to do exactly.

It's easier to discuss once I have some working code.  The key problem I'm trying to solve with the flex stuff is that sorting the results is important.  So I need to sort the items in order of importance before the list gets truncated by helm-candidate-number-limit.




--
Le

Thierry Volpiatto

unread,
Apr 15, 2013, 1:12:57 PM4/15/13
to Le Wang, emacs...@googlegroups.com
Ok, when I will know exactly what is needed, we could allow enabling
such sorting at the helm core level instead of running extra loop ect...
Reply all
Reply to author
Forward
0 new messages