0

I'm trying to create a Helm source which matches the basename of files. I created a source which splits the basename of files in recentf list and puts the path behind it in parens (it uses the (DISPLAY . REAL) candidate format, so the real item is still available for opening the file.

I then added a :match attribute function which should match only the basename of the file when searching, but for some reason it still matches the path part.

Can someone tell me why?

(helm
 :sources
 (list
  (helm-build-sync-source
      "Recent Files Basenames"
    :candidates
    (lambda ()
      (mapcar (lambda (f)
                (cons (format
                       "%s (%s)"
                       (file-name-nondirectory f) f) f))
              recentf-list))

    :match (lambda (candidate)
             (string-match
              helm-pattern
              (substring candidate 0
                         (string-match "(" candidate))))

    :action '(("Find File" . find-file)))))
1

You're missing :multimatch nil. You can also replace the match slot with:

:match-strict (lambda (candidate)
                (string-match helm-pattern
                              (helm-basename candidate)))

or

:match-part (lambda (candidate)
              (helm-basename candidate))
  • Thanks, I tried the match-part version and it worked. What I don't understand is why :match didn't work. It is supposed to override the default matching, isn't it? – Tom Aug 13 at 4:53
  • I don't think so. The multimatch option was probably adding additional matching functions, so you need to deactivate multimatch explicitly if you want only your match function to be used. – jagrg Aug 13 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.