6

Is there a way in Helm to first match substrings from the beginning and only after that in the middle of candidates?

For instance, I have the following directory structure:

~/
    .emacs.d/
    .gem/
    .microemulator/

And I want to open a file in the directory .emacs.d. I start to type .em and Helm matches .gem first.

How to make Helm match .emacs.d first, without prepending the beginning of line symbol (^)?

Imgur

5

It's possible with a pattern-transformer. Here's a sample code:

(helm :sources
          `((name . "Headings")
            (candidates . ,candidates)
            (action . (lambda (x) (goto-char x)
                         (call-interactively 'show-branches)
                         (worf-more)))
            (pattern-transformer . worf--pattern-transformer)))

(defun worf--pattern-transformer (x)
  "Transform X to make 1-9 select the heading level in `worf-goto'."
  (if (string-match "^[1-9]" x)
      (setq x (format "^%s" x))
    x))
2

The reason the character is not included because potentially a filename can contain that character. Btw, you are using the Helm version of find-file, not the actual helm-find-files. The helm-find-files command can fuzzy match, so you can just type "emd" to get to ~/.emacs.d, and even if you type "em", the command should give you ~/.emacs.d first. Check the helm-find-files section in my guide.

  • I tried typing em and it did match .emacs.d first in both helm-find-files and helm-mode-based find-file (didn't know they were different!). Why is it not matching .em the same way as em? – katspaugh Oct 30 '14 at 10:52
  • 1
    @katspaugh The same goes for helm-M-x is different from helm-based M-x. You can tell by execute persistent action (by default bound to TAB) and see the action menu. helm-find-files give you much more, and to know each action does what, read in details in my Helm Projectile guide, File Management section – Tu Do Oct 30 '14 at 10:57

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.