XahTV 2021-04-20 Emacs Lisp. Explore Helm Fuzzy Match Source Code. Part 3

XahTV 2021-04-20 Emacs Lisp. Explore Helm Fuzzy Match Source Code. Part 3

Highlights:

Topics:

We are going to explore the elisp source code of helm mode, to see how it implement fuzzy matching.

(defun select-choices ()
  "Select from a list of predefine choices, then insert them into buffer.
version 2021-04-18 "
  (interactive)
  (let (
        (phrases
         '(
           "This heart follows the brain of __"
           "This field closely follows the paradigm of __"
           "Widely considered to be a good way to __"
           "This has been widely adopted in the field of __"
           "This is more widely used at the time of __"
           "This phenomenon has been widely observed"
           "A common technique is to __"
           "This is a technique common in __"
           "There are several common kinds of __"
           ))
        userChoice
        )
    (setq userChoice (ido-completing-read "Make a choice:" phrases ))
    (insert userChoice)
    ;;
    ))

;; ido fuzzy matching is a character based fuzzy matching, and order matters

;; now let's explore  helm's helm-M-x. It is a word based fuzzy matching, and order does not matter.

;; now, let's look at helm's implementation of M-x: helm-M-x

;; helm-M-x call stack

(helm-M-x)

(helm-M-x-read-extended-command obarray)

(helm :sources sources
                :prompt prompt
                :buffer "*helm M-x*"
                :history 'helm-M-x-input-history)

(t #'helm-internal)
(apply fn plist)

(helm-internal &optional
SOURCES INPUT PROMPT RESUME PRESELECT BUFFER
KEYMAP DEFAULT HISTORY)

(helm-read-from-minibuffer
prompt input preselect resume keymap default
history)

;; btw, emacs 27 has string-distance


;; so, in helm, they use the word fuzzy-matching to mean some sort of fuzzy matching. but, the helm-M-x is actualy not using helm's fuzzy match, but let's call it orderless word based matching.

;; where is the doc for helm API

xah_talk_show_2021-04-20_transcript.txt

xah_talk_show_2021-04-20.txt

Xah Talk Show, Emacs Lisp. Fuzzy Matching. Explore Ido and Helm Source Code