-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathflx-rs.el
97 lines (77 loc) · 2.71 KB
/
flx-rs.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
;;; flx-rs.el --- flx in Rust using dynamic module -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2025 Shen, Jen-Chieh
;; Created date 2021-10-28 00:53:46
;; Author: Shen, Jen-Chieh <[email protected]>
;; URL: https://github.com/jcs-elpa/flx-rs
;; Version: 0.1.2
;; Package-Requires: ((emacs "25.1"))
;; Keywords: matching fuzzy
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; flx in Rust using dynamic module
;;
;;; Code:
(require 'pcase)
(require 'subr-x)
(defgroup flx-rs nil
"flx in Rust using dynamic module."
:prefix "flx-rs-"
:group 'flx)
(defcustom flx-rs-bin-dir
(concat (file-name-directory load-file-name) "bin/")
"Pre-built binaries directory path."
:type 'directory
:group 'flx-rs)
(defcustom flx-rs-dyn-name "flx-rs"
"Dynamic module name."
:type 'string
:group 'flx-rs)
;;
;; (@* "Externals" )
;;
(declare-function flx-rs-core-score "flx-rs-core")
;;
;; (@* "Utils" )
;;
(defun flx-rs-score (str query &rest _)
"Return best score matching QUERY against STR."
(unless (or (zerop (length query))
(zerop (length str)))
(when-let ((vec (ignore-errors (flx-rs-core-score str query))))
(append vec nil)))) ; Convert vector to list
;;
;; (@* "Bootstrap" )
;;
(defun flx-rs--system-specific-file ()
"Return the dynamic module filename, which is system-dependent."
(let* ((x86 (string-prefix-p "x86_64" system-configuration))
(name (if x86 "x86_64" "aarch64")))
(pcase system-type
('windows-nt
(concat flx-rs-dyn-name "." name "-pc-windows-msvc.dll"))
('darwin
(concat flx-rs-dyn-name "." name "-apple-darwin.dylib"))
((or 'gnu 'gnu/linux 'gnu/kfreebsd)
(concat flx-rs-dyn-name "." name "-unknown-linux-gnu.so")))))
;;;###autoload
(defun flx-rs-load-dyn ()
"Load dynamic module."
(interactive)
(unless (featurep 'flx-rs-core)
(let* ((dyn-name (flx-rs--system-specific-file))
(dyn-path (concat flx-rs-bin-dir dyn-name)))
(module-load dyn-path)
(message "[INFO] Successfully load dynamic module, `%s`" dyn-name))))
(provide 'flx-rs)
;;; flx-rs.el ends here