이멕스에서 vim commandT plugin을 구현하고 싶습니다. 이 코드는 대부분 matcher의 번역입니다.이맥스에서 문자열 일치 속도를 높입니다.
여기에 내 netbook에서 사용하기에는 너무 느린 이유가 있습니다. 어떻게 속도를 높일 수 있습니까?
(eval-when-compile (require 'cl))
(defun commandT-fuzzy-match (choices search-string)
(sort (loop for choice in choices
for score = (commandT-fuzzy-score choice search-string (commandT-max-score-per-char choice search-string))
if (> score 0.0) collect (list score choice))
#'(lambda (a b) (> (first a) (first b)))
))
(defun* commandT-fuzzy-score (choice search-string &optional (score-per-char (commandT-max-score-per-char choice search-string)) (choice-pointer 0) (last-found nil))
(condition-case error
(loop for search-char across search-string
sum (loop until (char-equal search-char (elt choice choice-pointer))
do (incf choice-pointer)
finally return (let ((factor (cond (last-found (* 0.75 (/ 1.0 (- choice-pointer last-found))))
(t 1.0))))
(setq last-found choice-pointer)
(max (commandT-fuzzy-score choice search-string score-per-char (1+ choice-pointer) last-found)
(* factor score-per-char)))))
(args-out-of-range 0.0) ; end of string hit without match found.
))
(defun commandT-max-score-per-char (choice search-string)
(/ (+ (/ 1.0 (length choice)) (/ 1.0 (length search-string))) 2))
이미 많은 도움이되었으므로 해당 부분을 컴파일해야합니다. 그리고 벤치 마크 : 여기
(let ((choices (split-string (shell-command-to-string "curl http://sprunge.us/FcEL") "\n")))
(benchmark-run-compiled 10
(commandT-fuzzy-match choices "az")))
일부 설명을 코드가해야하거나 일부 의견이 도움이 될 것입니다. – Thomas
'iswitchb'및/또는'ido' 제안과 비슷한 소리입니다. Textmate가 Emacs에서 가져온 것이라면 너무 놀랄 것입니다 ... http://emacswiki.org/emacs/IswitchBuffers – tripleee
[여기] (http://www.emacswiki.org/emacs/Icicles_-_Fuzzy_Completion)는 설명입니다. Emacs Lisp에서 퍼지 매칭 (fuzzy matching)의 다양한 종류의 구현 코드에 대한 언급. – Drew