[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/kiwix 57d6f5c 178/192: migrate Org Mode link support to
From: |
Stefan Monnier |
Subject: |
[elpa] externals/kiwix 57d6f5c 178/192: migrate Org Mode link support to separate source code file |
Date: |
Sat, 19 Dec 2020 00:41:56 -0500 (EST) |
branch: externals/kiwix
commit 57d6f5c8bd45523b68f94a52d98b0466d736bf80
Author: stardiviner <numbchild@gmail.com>
Commit: stardiviner <numbchild@gmail.com>
migrate Org Mode link support to separate source code file
---
kiwix.el | 103 +--------------------------------------------------
org-kiwix.el | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 119 insertions(+), 102 deletions(-)
diff --git a/kiwix.el b/kiwix.el
index 412b4da..80292fe 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -321,108 +321,7 @@ for query string and library interactively."
(let ((current-prefix-arg t))
(call-interactively 'kiwix-at-point)))
-;;; Support Org-mode
-;;
-;; - [[wikipedia:(library):query]]
-;; - [[wikipedia:query]]
-;;
-;; links:
-;; - wikipedia:(zh):%E7%A6%85%E5%AE%97
-;; - wikipedia:(en):linux
-;; - wikipedia:linux
-;;
-;; - parameter `link' will be (en):linux" or linux".
-;;
-;; elisp regexp: "\\(?:(\\(.*\\)):\\)?\\([^] \n\t\r]*\\)"
-;; - non capturing group (\(?:...\)) for optional library
-;; - group 1: library (en or zh)
-;; - group 2: link? (match everything but ], space, tab, carriage return,
linefeed by using [^] \n\t\r]*)
-;; for open wiki search query with local application database.
-
-(defun chinese-string-p (string)
- "Return t if STRING is a Chinese string."
- (if (string-match (format "\\cC\\{%s\\}" (length string)) string)
- t
- nil))
-
-(defun kiwix-org-get-library (link)
- "Get library from Org-mode `LINK'."
- (cond
- ((chinese-string-p link)
- (kiwix-select-library "zh"))
- ((string-match-p "[a-zA-Z\ ]+" link)
- ;; convert between libraries full name and abbrev.
- (kiwix-select-library "en"))
- (t (kiwix-select-library))))
-
-;;;###autoload
-(defun org-wikipedia-open-link (link)
- "Open LINK in external Wikipedia program."
- ;; The regexp: (library):query
- ;; - query : should not exclude space
- ;; match link spec: "(library):query" with regexp "([^).]*):?:.*"
- ;; (string-match "\\(?:(\\(.*\\)):\\)?\\([^]\n\t\r]*\\)" link)
- (string-match "(\\([^)].*\\)):\\(.*\\)" link)
- (let* ((library (kiwix-org-get-library link))
- (query (cond
- ((chinese-string-p link) link)
- ((string-match-p "(\\([^)].*\\)):\\(.*\\)" link)
- (match-string 2 link))
- (t link)))
- (url (concat
- kiwix-server-url
- "/" library "/A/"
- ;; query need to be convert to URL encoding: "禅宗"
https://zh.wikipedia.org/wiki/%E7%A6%85%E5%AE%97
- (url-encode-url
- ;; convert space to underline: "Beta distribution"
"Beta_distribution"
- (replace-regexp-in-string
- " " "_"
- ;; only capitalize the first word. like: "meta-circular
interpreter" -> "Meta-circular interpreter"
- (kiwix-capitalize-first query)
- nil nil))
- ".html")))
- ;; (prin1 (format "library: %s, query: %s, url: %s" library query url))
- (browse-url url)))
-
-;;;###autoload
-(defun org-wikipedia-export-link (link description format)
- "Export the Wikipedia LINK with DESCRIPTION for FORMAT from Org files."
- (when (string-match "\\(?:(\\(.*\\)):\\)?\\([^] \n\t\r]*\\)" link)
- (let* ((library (kiwix-org-get-library link))
- (query (url-encode-url (or (match-string 2 link) description)))
- ;; "http://en.wikipedia.org/wiki/Linux"
- ;; --
- ;; ^- library: en, zh
- (path (concat "http://" library ".wikipedia.org/wiki/" query))
- (desc (or (match-string 2 link) description)))
- (when (stringp path)
- (cond
- ((eq format 'html) (format "<a href=\"%s\">%s</a>" path desc))
- ((eq format 'latex) (format "\\href{%s}{%s}" path desc))
- (t path))))))
-
-;;;###autoload
-(defun org-wikipedia-store-link ()
- "Store a link to a Wikipedia link."
- ;; [C-c o C-l l] `org-store-link'
- ;; remove those interactive functions. use normal function instead.
- (when (eq major-mode 'wiki-mode)
- (let* ((query (read-string "Wikipedia Query with Kiwix: "))
- (library (kiwix-select-library))
- (link (concat "wikipedia:" "(" library "):" query)))
- (org-store-link-props :type "wikipedia"
- :link link
- :description query)
- link)))
-
-;;;###autoload
-(org-link-set-parameters "wikipedia" ; NOTE: use `wikipedia' for future
backend changing.
- :follow #'org-wikipedia-open-link
- :store #'org-wikipedia-store-link
- :export #'org-wikipedia-export-link)
-
-;;;###autoload
-(add-hook 'org-store-link-functions 'org-wikipedia-store-link t)
+;;===============================================================================
(defun kiwix-mode-enable ()
"Enable kiwix-mode."
diff --git a/org-kiwix.el b/org-kiwix.el
new file mode 100644
index 0000000..0516c72
--- /dev/null
+++ b/org-kiwix.el
@@ -0,0 +1,118 @@
+;;; org-kiwix.el --- Org Mode link support -*- lexical-binding: t; -*-
+
+;;; Time-stamp: <2020-04-28 10:06:10 stardiviner>
+
+;;; Commentary:
+
+;;; Support Org-mode
+;;
+;; - [[wikipedia:(library):query]]
+;; - [[wikipedia:query]]
+;;
+;; links:
+;; - wikipedia:(zh):%E7%A6%85%E5%AE%97
+;; - wikipedia:(en):linux
+;; - wikipedia:linux
+;;
+;; - parameter `link' will be (en):linux" or linux".
+;;
+;; elisp regexp: "\\(?:(\\(.*\\)):\\)?\\([^] \n\t\r]*\\)"
+;; - non capturing group (\(?:...\)) for optional library
+;; - group 1: library (en or zh)
+;; - group 2: link? (match everything but ], space, tab, carriage return,
linefeed by using [^] \n\t\r]*)
+;; for open wiki search query with local application database.
+
+;;; Code:
+
+(require 'kiwix)
+
+(defun chinese-string-p (string)
+ "Return t if STRING is a Chinese string."
+ (if (string-match (format "\\cC\\{%s\\}" (length string)) string)
+ t
+ nil))
+
+(defun kiwix-org-get-library (link)
+ "Get library from Org-mode `LINK'."
+ (cond
+ ((chinese-string-p link)
+ (kiwix-select-library "zh"))
+ ((string-match-p "[a-zA-Z\ ]+" link)
+ ;; convert between libraries full name and abbrev.
+ (kiwix-select-library "en"))
+ (t (kiwix-select-library))))
+
+;;;###autoload
+(defun org-wikipedia-open-link (link)
+ "Open LINK in external Wikipedia program."
+ ;; The regexp: (library):query
+ ;; - query : should not exclude space
+ ;; match link spec: "(library):query" with regexp "([^).]*):?:.*"
+ ;; (string-match "\\(?:(\\(.*\\)):\\)?\\([^]\n\t\r]*\\)" link)
+ (string-match "(\\([^)].*\\)):\\(.*\\)" link)
+ (let* ((library (kiwix-org-get-library link))
+ (query (cond
+ ((chinese-string-p link) link)
+ ((string-match-p "(\\([^)].*\\)):\\(.*\\)" link)
+ (match-string 2 link))
+ (t link)))
+ (url (concat
+ kiwix-server-url
+ "/" library "/A/"
+ ;; query need to be convert to URL encoding: "禅宗"
https://zh.wikipedia.org/wiki/%E7%A6%85%E5%AE%97
+ (url-encode-url
+ ;; convert space to underline: "Beta distribution"
"Beta_distribution"
+ (replace-regexp-in-string
+ " " "_"
+ ;; only capitalize the first word. like: "meta-circular
interpreter" -> "Meta-circular interpreter"
+ (kiwix-capitalize-first query)
+ nil nil))
+ ".html")))
+ ;; (prin1 (format "library: %s, query: %s, url: %s" library query url))
+ (browse-url url)))
+
+;;;###autoload
+(defun org-wikipedia-export-link (link description format)
+ "Export the Wikipedia LINK with DESCRIPTION for FORMAT from Org files."
+ (when (string-match "\\(?:(\\(.*\\)):\\)?\\([^] \n\t\r]*\\)" link)
+ (let* ((library (kiwix-org-get-library link))
+ (query (url-encode-url (or (match-string 2 link) description)))
+ ;; "http://en.wikipedia.org/wiki/Linux"
+ ;; --
+ ;; ^- library: en, zh
+ (path (concat "http://" library ".wikipedia.org/wiki/" query))
+ (desc (or (match-string 2 link) description)))
+ (when (stringp path)
+ (cond
+ ((eq format 'html) (format "<a href=\"%s\">%s</a>" path desc))
+ ((eq format 'latex) (format "\\href{%s}{%s}" path desc))
+ (t path))))))
+
+;;;###autoload
+(defun org-wikipedia-store-link ()
+ "Store a link to a Wikipedia link."
+ ;; [C-c o C-l l] `org-store-link'
+ ;; remove those interactive functions. use normal function instead.
+ (when (eq major-mode 'wiki-mode)
+ (let* ((query (read-string "Wikipedia Query with Kiwix: "))
+ (library (kiwix-select-library))
+ (link (concat "wikipedia:" "(" library "):" query)))
+ (org-store-link-props :type "wikipedia"
+ :link link
+ :description query)
+ link)))
+
+;;;###autoload
+(org-link-set-parameters "wikipedia" ; NOTE: use `wikipedia' for future
backend changing.
+ :follow #'org-wikipedia-open-link
+ :store #'org-wikipedia-store-link
+ :export #'org-wikipedia-export-link)
+
+;;;###autoload
+(add-hook 'org-store-link-functions 'org-wikipedia-store-link t)
+
+
+
+(provide 'org-kiwix)
+
+;;; org-kiwix.el ends here
- [elpa] externals/kiwix 648916d 154/192: add option to set Kiwix default completing-read framework, default is Ivy., (continued)
- [elpa] externals/kiwix 648916d 154/192: add option to set Kiwix default completing-read framework, default is Ivy., Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix eee7cbd 157/192: auto pull download Docker image if it is not available, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix ba929ec 159/192: update Docker run container command, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 2d31741 160/192: auto launch server if ping not available, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 8cc16b1 161/192: no need to select library when use Docker container, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix f11e8fb 167/192: support more web browsers, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix fbd00ab 170/192: select library every time you query because Docker container use libraries index, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix d5e5780 173/192: fix GitHub Org Mode inline image display format, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix e2933785 174/192: add autoload cookie for kiwix.el Org link functions, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 0155c9a 177/192: rename org-link functions, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 57d6f5c 178/192: migrate Org Mode link support to separate source code file,
Stefan Monnier <=
- [elpa] externals/kiwix 36b15f3c 179/192: add kiwix.el load in README, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 2011a9f 183/192: update package config in README, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix dd02284 185/192: fix free variable `kiwix-response', Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix f5d7a2f 180/192: support Org Mode link :complete property function, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 5f60388 181/192: update kiwix-server-url everytime used, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 4bdf16b 188/192: smarter `kiwix-org-get-library' detect existing library in link, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 6878b7d 182/192: add condition to detect kiwix server is available when get search hints, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix cb3e253 190/192: Merge pull request #2 from syohex/syohex/warnings, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix 15fd8fa 191/192: use hook to auto setup org-kiwix link type, Stefan Monnier, 2020/12/19
- [elpa] externals/kiwix ddeecd1 186/192: fix void org link functions by autoload, Stefan Monnier, 2020/12/19