[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/kiwix 53f2b72 008/192: add file kiwix-at-point.el
From: |
Stefan Monnier |
Subject: |
[elpa] externals/kiwix 53f2b72 008/192: add file kiwix-at-point.el |
Date: |
Sat, 19 Dec 2020 00:41:22 -0500 (EST) |
branch: externals/kiwix
commit 53f2b72a58680a0db0377786cb33412639de9c75
Author: stardiviner <numbchild@gmail.com>
Commit: stardiviner <numbchild@gmail.com>
add file kiwix-at-point.el
---
kiwix-at-point.el | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
diff --git a/kiwix-at-point.el b/kiwix-at-point.el
new file mode 100644
index 0000000..d0cfbe5
--- /dev/null
+++ b/kiwix-at-point.el
@@ -0,0 +1,104 @@
+;;; kiwix-at-point.el --- Kiwix client for Emacs
+;;; -*- coding: utf-8 -*-
+
+;;; Commentary:
+
+
+
+;;; Code:
+
+(defgroup kiwix-at-point nil
+ "Search in Kiwix for text at point."
+ :group 'external)
+
+(defcustom kiwix-at-point-library-alist
+ ;; e.g.
"~/.www.kiwix.org/kiwix/8ip89lik.default/data/index/wikinews_en_all_2015-11.zim.idx"
+ '((wikipedia . "")
+ (wiktionary . "")
+ (wikinews . "")
+ (wikibooks . "")
+ (wikiquote . "")
+ (wikisource . "")
+ (wikiversity . "")
+ (wikimed . "") ; "WikiMed Medical Encyclopedia" "Wikispecies"
+ )
+ "Alist which contains available kiwix libraries."
+ :type '(repeat 'string)
+ :group 'kiwix-at-point)
+
+(defvar kiwix-at-point-library nil
+ "Variable used to specify the library for the current search.")
+(make-variable-buffer-local 'kiwix-at-point-library)
+
+(defvar kiwix-at-point--library-history nil)
+
+(defun kiwix-at-point-get-library ()
+ "Guess which library suit to the current search."
+ (or kiwix-at-point-library
+ kiwix-at-point--library-history))
+
+(defun kiwix-at-point-maybe-specify-library (search-string)
+ "Prefix SEARCH-STRING with the guessed library, if any."
+ (let ((library (kiwix-at-point-get-library)))
+ (concat (when library
+ (concat library ":"))
+ search-string)))
+
+(defun kiwix-at-point-get-idx ()
+ "Get the idx file path."
+ ;; TODO:
+ )
+
+(defun kiwix-at-point-run-search (search)
+ (if (executable-find "kiwix")
+ ;; TODO:
+ (start-process "Kiwix" nil "kiwix-search" (kiwix-at-point-get-idx)
search)
+ (message "Kiwix wasn't found, install it first http://www.kiwix.org")))
+
+;;;###autoload
+(defun kiwix-at-point (&optional edit-search)
+ "Search for the word at point in Kiwix."
+ (interactive "P")
+ (let* ((thing (if mark-active
+ (buffer-substring (region-beginning) (region-end))
+ (thing-at-point 'symbol)))
+ (search (kiwix-at-point-maybe-specify-library thing)))
+ (kiwix-at-point-run-search
+ (if (or edit-search (null thing))
+ (read-string "Kiwix search: " search)
+ search))))
+
+(defun kiwix-at-point--library-candidates ()
+ kiwix-at-point-library-alist)
+
+(defun kiwix-at-point--set-library-prompt ()
+ (let ((default-library (kiwix-at-point-get-library)))
+ (format "Kiwix library%s: "
+ (if default-library
+ (format "[Default: %s]" default-library)
+ ""))))
+
+;;;###autoload
+(defun kiwix-at-point-set-library ()
+ "Set current search's library."
+ (interactive)
+ (let ((minibuffer-local-completion-map
+ (copy-keymap minibuffer-local-completion-map)))
+ (define-key minibuffer-local-completion-map (kbd "SPC") nil)
+ (setq-local kiwix-at-point-library
+ (completing-read (kiwix-at-point--set-library-prompt)
+ (kiwix-at-point--library-candidates) nil nil
nil
+ 'kiwix-at-point--library-history
(kiwix-at-point-get-library)))))
+
+;;;###autoload
+(defun kiwix-at-point-search (&optional edit-search)
+ "Prompt and search in Kiwix."
+ (interactive "P")
+ (let ((search (kiwix-at-point-maybe-specify-library "")))
+ (kiwix-at-point-run-search
+ (read-string "Kiwix search: " search))))
+
+
+(provide 'kiwix-at-point)
+
+;;; kiwix-at-point.el ends here
- [elpa] externals/kiwix 5bfc5a2 053/192: support more flexible library name, (continued)
- [elpa] externals/kiwix 5bfc5a2 053/192: support more flexible library name, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix d5e1ad0 057/192: add config section comments., Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 38986bb 058/192: Merge branch 'release/v0.4.3', Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 634b5ae 061/192: enhance function kiwix-query to support space between strings., Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix ec62ab0 063/192: Merge branch 'release/v0.5.0', Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix a11fcd4 064/192: remove org-mode link prefix setup, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 74ce07a 065/192: fix query invalid when the query contains space, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 6e85607 066/192: validate query is english or non-english., Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix c325402 012/192: fix add kiwix link abbrev to org-mode list, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 5f60967 013/192: use browse-url to replace custom browser custom, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 53f2b72 008/192: add file kiwix-at-point.el,
Stefan Monnier <=
- [elpa] externals/kiwix 06ad0af 009/192: remove duplicate function names, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 6d7bc71 010/192: change default Kiwix library, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 126b172 015/192: update defgroup and defcustom, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 7413397 019/192: add options to whether add org-mode link support, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 9c9d784 020/192: fix cl-lib dependent issue, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 5d25121 021/192: fix alias function name, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix aa4ac22 023/192: improve interactive function, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix d684140 024/192: Quote path argument each time it's used, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix f43e006 028/192: add Kiwix installation commentary, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix e527614 032/192: Merge branch 'release/v0.2.1', Stefan Monnier, 2020/12/19