XahTV 2021-04-19 Emacs Lisp. Explore Ido and Helm Fuzzy Match Source Code. Part 2

XahTV 2021-04-19 Emacs Lisp. Explore Ido and Helm Fuzzy Match Source Code. Part 2

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

First, we write a emacs command, that lets user choose from potentially thousands of academic phrases. Using ido mode's character based fuzzy matching. 10 minutes. Helm uses a word based fuzzy matching, and order of words does not matter. If our elisp exploration of helm source code is successful, we are going to modify our code to use helm's fuzzy matching.

(defun select-phrases ()
  "prompt to let user select a academic phrase and insert it.
Version 2021-04-19"
  (interactive)
  (let (
        (phrases
         '(
           "a certain study, … indicated that…"
           "little attention has been devoted to the impact…"
           "given the lack of critical attention paid to…"
           "there is a divergence between …… and what they actually do. This divergence"
           "several schools of thought have emerged…"
           "prior research has suggested…"
           "the central issue addressed here is the relationship between…"
           "the topic of …… warrants research attention for …… reasons."
           "to answer these questions…"
           "the present study attempts to crystallize …… factors which influence …… by…."
           ))
        userChoice
        )
    (setq userChoice (ido-completing-read "Pick one:" phrases))
    (insert userChoice)
    ;;
    ))

(defun select-phrases-helm ()
  "prompt to let user select a academic phrase and insert it.
Version 2021-04-19"
  (interactive)
  (let (
        (phrases
         '(
           "a certain study, … indicated that…"
           "little attention has been devoted to the impact…"
           "given the lack of critical attention paid to…"
           "there is a divergence between …… and what they actually do. This divergence"
           "several schools of thought have emerged…"
           "prior research has suggested…"
           "the central issue addressed here is the relationship between…"
           "the topic of …… warrants research attention for …… reasons."
           "to answer these questions…"
           "the present study attempts to crystallize …… factors which influence …… by…."
           ))
        userChoice
        )
    (helm :sources 'phrases
          :prompt "Pick a phrase:"
          :buffer "*academic phrases buffer*"
          :history nil)
    ;;
    ))

;; helm 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)

in emacs 27
string-distance

xah_talk_show_2021-04-19_transcript.txt

xah_talk_show_2021-04-19.txt

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