branch: externals/kiwix commit 33cfe42da29adda656bee3230e59b0aa7645b0db Author: stardiviner <numbch...@gmail.com> Commit: stardiviner <numbch...@gmail.com>
Use cond structure is better --- kiwix.el | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/kiwix.el b/kiwix.el index 29ddd29..8f04dbf 100644 --- a/kiwix.el +++ b/kiwix.el @@ -156,23 +156,25 @@ Set it to ‘t’ will use Emacs built-in ‘completing-read’." :type "GET" :sync t :parser (lambda () - (if (libxml-available-p) ; (and (not (featurep 'elquery)) (libxml-available-p)) - (let ((document (libxml-parse-html-region (point-min) (point-max)))) - (setq kiwix-libraries - (mapcar - ;; remove "/" from "/<zim_library_name>" - (lambda (slash_library) - (substring slash_library 1 nil)) - ;; list of "/<zim_library_name>" - (mapcar - (lambda (a) - (dom-attr a 'href)) - (dom-by-tag - (dom-by-class - (dom-by-class document "kiwix") ; <div class="kiwix"> - "book__list") ; <div class="book__list"> - 'a) ; <a href="/wikipedia_zh_all_maxi_2021-03"> - )))) + (cond + ((libxml-available-p) ; (and (not (featurep 'elquery)) (libxml-available-p)) + (let ((document (libxml-parse-html-region (point-min) (point-max)))) + (setq kiwix-libraries + (mapcar + ;; remove "/" from "/<zim_library_name>" + (lambda (slash_library) + (substring slash_library 1 nil)) + ;; list of "/<zim_library_name>" + (mapcar + (lambda (a) + (dom-attr a 'href)) + (dom-by-tag + (dom-by-class + (dom-by-class document "kiwix") ; <div class="kiwix"> + "book__list") ; <div class="book__list"> + 'a) ; <a href="/wikipedia_zh_all_maxi_2021-03"> + ))))) + ((featurep 'elquery) (require 'elquery) (let ((html (elquery-read-string (buffer-substring-no-properties (point-min) (point-max))))) @@ -189,7 +191,7 @@ Set it to ‘t’ will use Emacs built-in ‘completing-read’." (elquery-children ;; return the <div class="book__list"> (car (elquery-$ ".book__list" html))))))) - (elquery-children (first (elquery-$ ".book__list" html)))))) + (elquery-children (first (elquery-$ ".book__list" html))))))) :error (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) (message "Function kiwix-get-libraries error.")))