branch: elpa/flx commit 4cd6d9c9e4524b66a6b4ee76d2b7679c5c7d2376 Author: Ramkumar Ramachandra <artag...@gmail.com> Commit: Ramkumar Ramachandra <artag...@gmail.com>
flx: require cl-lib; avoid ugly eval-when-compile Also prefix various functions with "cl-", and add a Package-Requires header. Signed-off-by: Ramkumar Ramachandra <artag...@gmail.com> --- flx.el | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/flx.el b/flx.el index 301e4a2bb4..b3a2f5cc3f 100644 --- a/flx.el +++ b/flx.el @@ -7,6 +7,7 @@ ;; Description: fuzzy matching with good sorting ;; Created: Wed Apr 17 01:01:41 2013 (+0800) ;; Version: 0.1 +;; Package-Requires: ((cl-lib "0.3")) ;; URL: https://github.com/lewang/flx ;; This file is NOT part of GNU Emacs. @@ -49,7 +50,7 @@ ;;; Code: -(eval-when-compile (require 'cl)) +(require 'cl-lib) (defface flx-highlight-face '((t (:inherit font-lock-variable-name-face :bold t :underline t))) "Face used by flx for highlighting flx match characters." @@ -62,7 +63,7 @@ (let* ((res (make-hash-table :test 'eq :size 32)) (str-len (length str)) char) - (loop for index from (1- str-len) downto 0 + (cl-loop for index from (1- str-len) downto 0 do (progn (setq char (downcase (aref str index))) (push index (gethash char res)))) @@ -102,8 +103,8 @@ from BEG (inclusive) to end (not inclusive). (or end (setq end (length vec))) (while (< beg end) - (incf (aref vec beg) inc) - (incf beg)) + (cl-incf (aref vec beg) inc) + (cl-incf beg)) vec) ;; So we store one fixnum per character. Is this too memory inefficient? @@ -118,9 +119,9 @@ See documentation for logic." (penalty-lead ?.) (groups-alist (list (list -1 0)))) ;; ++++ final char bonus - (incf (aref scores str-last-index) 1) + (cl-incf (aref scores str-last-index) 1) ;; Establish baseline mapping - (loop for char across str + (cl-loop for char across str for index from 0 with last-char = nil with group-word-count = 0 @@ -131,13 +132,13 @@ See documentation for logic." ;; gets penalized compared to "foo/ab". (if (zerop group-word-count) nil last-char))) (when (flx-boundary-p effective-last-char char) - (setcdr (cdar groups-alist) (cons index (cddar groups-alist)))) + (setcdr (cdar groups-alist) (cons index (cl-cddar groups-alist)))) (when (and (not (flx-word-p last-char)) (flx-word-p char)) - (incf group-word-count))) + (cl-incf group-word-count))) ;; ++++ -45 penalize extension (when (eq last-char penalty-lead) - (incf (aref scores index) -45)) + (cl-incf (aref scores index) -45)) (when (eq group-separator char ) (setcar (cdar groups-alist) group-word-count) (setq group-word-count 0) @@ -151,7 +152,7 @@ See documentation for logic." (unless (zerop separator-count) (flx-inc-vec scores (* -2 group-count))) ;; score each group further - (loop for group in groups-alist + (cl-loop for group in groups-alist for index from separator-count downto 0 with last-group-limit = nil with basepath-found = nil @@ -179,17 +180,17 @@ See documentation for logic." -3 (+ -5 (1- index))))) (flx-inc-vec scores num (1+ group-start) last-group-limit)) - (loop for word in (cddr group) + (cl-loop for word in (cddr group) for word-index from (1- words-length) downto 0 with last-word = (or last-group-limit str-len) do (progn - (incf (aref scores word) + (cl-incf (aref scores word) ;; ++++ beg word bonus AND 85) - (loop for index from word below last-word + (cl-loop for index from word below last-word for char-i from 0 - do (incf (aref scores index) + do (cl-incf (aref scores index) (- ;; ++++ word order penalty (* -3 word-index) @@ -209,9 +210,9 @@ See documentation for logic." if VAL is nil, return entire list." (if val - (loop for sub on sorted-list + (cl-loop for sub on sorted-list do (when (> (car sub) val) - (return sub))) + (cl-return sub))) sorted-list)) (defun flx-get-matches (hash query &optional greater-than q-index) @@ -289,15 +290,15 @@ e.g. (\"aab\" \"ab\") returns 0)) (contiguous-count 0) last-match) - (loop for index in match-positions + (cl-loop for index in match-positions do (progn (if (and last-match (= (1+ last-match) index)) - (incf contiguous-count) + (cl-incf contiguous-count) (setq contiguous-count 0)) - (incf score (aref heatmap index)) + (cl-incf score (aref heatmap index)) (when (> contiguous-count 0) - (incf score (+ 45 (* 15 (min contiguous-count 4))))) + (cl-incf score (+ 45 (* 15 (min contiguous-count 4))))) (setq last-match index))) (if (or (null best-score) (> score (car best-score))) @@ -317,7 +318,7 @@ SCORE of nil means to clear the properties." (substring-no-properties obj)))) (unless (null score) - (loop for char in (cdr score) + (cl-loop for char in (cdr score) do (progn (when (and last-char (not (= (1+ last-char) char)))