|
30 | 30 | (require 'xdg) |
31 | 31 | (fset 'rustic-doc--xdg-data-home 'xdg-data-home))) |
32 | 32 |
|
| 33 | +(defun rustic-doc--make-semver (&rest version-kv) |
| 34 | + "Return a new semver-like version from VERSION-KV. |
| 35 | +VERSION-KV is a plist which must have :major key, and optionaly |
| 36 | +:minor and :patch. Default values for :minor and :patch are 0. |
| 37 | +Returned value is a list of the form (major minor patch)." |
| 38 | + (let ((major (plist-get version-kv :major)) |
| 39 | + (minor (or (plist-get version-kv :minor) 0)) |
| 40 | + (patch (or (plist-get version-kv :patch) 0))) |
| 41 | + (list major minor patch))) |
| 42 | + |
| 43 | +(defun rustic-doc--semver-from-string (version-str) |
| 44 | + "Return a semver-like version from VERSION-STR." |
| 45 | + (let* ((splitted-str (split-string version-str "\\.")) |
| 46 | + (str-length (length splitted-str))) |
| 47 | + (mapcar #'string-to-number |
| 48 | + ;; take only first 3 elements or less |
| 49 | + (seq-subseq splitted-str 0 (min 3 str-length))))) |
| 50 | + |
| 51 | +(defun rustic-doc--semver-greater (v1 v2) |
| 52 | + "Return greater for two semver-like versions V1 and V2." |
| 53 | + (defun -semver-major (v) (nth 0 v)) |
| 54 | + (defun -semver-minor (v) (nth 1 v)) |
| 55 | + (defun -semver-patch (v) (nth 2 v)) |
| 56 | + |
| 57 | + (cond |
| 58 | + ((> (-semver-major v1) (-semver-major v2)) t) |
| 59 | + ((< (-semver-major v1) (-semver-major v2)) nil) |
| 60 | + ((> (-semver-minor v1) (-semver-minor v2)) t) |
| 61 | + ((< (-semver-minor v1) (-semver-minor v2)) nil) |
| 62 | + ((> (-semver-patch v1) (-semver-patch v2)) t) |
| 63 | + ((< (-semver-patch v1) (-semver-patch v2)) nil) |
| 64 | + (t nil))) |
| 65 | + |
| 66 | +(defconst rustic-doc-pandoc-min-version |
| 67 | + (rustic-doc--make-semver :major 2 :minor 1)) |
| 68 | + |
| 69 | +(defconst rustic-doc-fd-find-min-version |
| 70 | + (rustic-doc--make-semver :major 2)) |
| 71 | + |
33 | 72 | (defvar rustic-doc-lua-filter (concat (file-name-as-directory (getenv "HOME")) |
34 | 73 | ".local/bin/rustic-doc-filter.lua") |
35 | 74 | "Save location for the rustic-doc lua filter.") |
@@ -274,16 +313,28 @@ See buffer *cargo-makedocs* for more info") |
274 | 313 | (rustic-doc--project-doc-dest))))) |
275 | 314 | (message "Activate rustic-doc-mode to run `rustic-doc-convert-current-package"))) |
276 | 315 |
|
| 316 | +(defun rustic-doc--extract-version (str) |
| 317 | + "Extract semver-like version from `STR' and conver it to list. |
| 318 | +
|
| 319 | +Both `fd-find' and `pandoc' output their versions in the form: |
| 320 | +`<program> <semver>\n', that's why this function parses the |
| 321 | +version from first whitespace to the end of the line." |
| 322 | + (let ((start (string-match-p " " str)) |
| 323 | + (end (string-match-p "\n" str))) |
| 324 | + (rustic-doc--semver-from-string (substring str start end)))) |
| 325 | + |
277 | 326 | (defun rustic-doc--confirm-dep-versions (missing-fd) |
278 | 327 | "Verify that dependencies are not too old. |
279 | | -Do not check `fd' when MISSING-FD is non-nil." |
| 328 | + Do not check `fd' when MISSING-FD is non-nil." |
280 | 329 | (when (not missing-fd) |
281 | | - (when (> 8 (string-to-number |
282 | | - (substring (shell-command-to-string "fd --version") 3 4))) |
| 330 | + (when (rustic-doc--semver-greater |
| 331 | + rustic-doc-fd-find-min-version |
| 332 | + (rustic-doc--extract-version (shell-command-to-string "fd --version"))) |
283 | 333 | (message "Your version of fd is too old, please install a recent version, maybe through cargo."))) |
284 | 334 |
|
285 | | - (when (>= 11 (string-to-number |
286 | | - (substring (shell-command-to-string "pandoc --version") 9 11))) |
| 335 | + (when (rustic-doc--semver-greater |
| 336 | + rustic-doc-pandoc-min-version |
| 337 | + (rustic-doc--extract-version (shell-command-to-string "pandoc --version"))) |
287 | 338 | (message "Your version of pandoc is too old, please install a more recent version. See their github for more info."))) |
288 | 339 |
|
289 | 340 |
|
|
0 commit comments