Set url-proxy-services as a custom option
[org-tag-eldoc.git] / org-tag-eldoc.el
blobe65efd0fe2de56262563635295b1f044c1e1f9a2
1 ;;; org-tag-eldoc.el --- Display tag explanation in Eldoc -*- lexical-binding: t; -*-
2 ;; -*- coding: utf-8 -*-
4 ;; Authors: stardiviner <numbchild@gmail.com>
5 ;; Package-Requires: ((emacs "26.1") (request "0.3.3"))
6 ;; Version: 0.1.0
7 ;; Keywords: org
8 ;; Homepage: https://repo.or.cz/org-tag-eldoc.git
10 ;; Copyright (C) 2024-2025 Christopher M. Miles, all rights reserved.
12 ;; org-tag-eldoc is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; org-tag-eldoc is distributed in the hope that it will be useful, but WITHOUT
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 ;; License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;;; Display tag explanation in Eldoc when point on tag.
29 ;;; Code:
31 (require 'org)
32 (require 'org-tag-eldoc-pixiv-encyclopedia)
33 (require 'org-tag-eldoc-wikipedia)
35 (defcustom org-tag-eldoc-tag-explanation-functions
36 '(org-tag-eldoc-pixiv-encyclopedia-query
37 org-tag-eldoc-wikipedia-query)
38 "A list of functions to be executed for query tag explanation."
39 :type 'list
40 :safe #'listp
41 :group 'org-tags)
43 (defcustom org-tag-eldoc-request-proxy
44 (or url-proxy-services
45 '(("http" . "127.0.0.1:7890")
46 ("https" . "127.0.0.1:7890")))
47 "The proxy services inherited from `url-proxy-services'."
48 :type 'alist
49 :group 'org-tags)
51 (defcustom org-tag-eldoc-tag-explanations-alist
52 '(("Linux" . "Linux (/ˈlɪnʊks/ LIN-uuks) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds.")
53 ("Emacs" . "Emacs /ˈiːmæks/ ⓘ, originally named EMACS (an acronym for \"Editor Macros\"), is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as \"the extensible, customizable, self-documenting, real-time display editor\". Development of the first Emacs began in the mid-1970s, and work on GNU Emacs, directly descended from the original, is ongoing; its latest version is 29.2, released January 2024.")
54 ("GNU" . "GNU (/ɡnuː/ ⓘ) is an extensive collection of free software (385 packages as of September 2023), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operating systems popularly known as Linux. Most of GNU is licensed under the GNU Project's own General Public License (GPL)."))
55 "Alist of cons cell with tag and explanation."
56 :type 'alist
57 :safe #'listp
58 :group 'org-tags)
60 (defun org-tag-eldoc-tag-explanation (&optional tag)
61 "Display tag explanation in Eldoc when point on TAG."
62 (let ((tag (or tag (thing-at-point 'symbol))))
63 (cdr (or (assoc tag org-tag-eldoc-tag-explanations-alist)
64 (seq-first (seq-some (lambda (f) (apply f tag))
65 org-tag-eldoc-tag-explanation-functions))))))
67 (defun org-tag-eldoc-function (&rest args)
68 "The eldoc function to be added into `eldoc-documentation-functions' with ARGS."
69 ;; TODO: `org-element-at-point' return `headline' instead of `tags.' Need Org mode to implement it.
70 ;; Use `thing-at-point' to workaround the missing `tags' syntax element node in `org-element-at-point' / `org-context'.
71 (let ((tag (thing-at-point 'symbol))
72 (tags (org-get-tags nil 'local)))
73 (when (member tag tags) (org-tag-eldoc-tag-explanation tag))))
75 ;;; `eldoc-documentation-function', `eldoc-documentation-functions'
76 ;;;###autoload
77 (defun org-tag-eldoc-setup ()
78 "Setup `eldoc-documentation-functions'."
79 (add-hook 'eldoc-documentation-functions #'org-tag-eldoc-function nil t))
81 (add-hook 'org-mode-hook #'org-tag-eldoc-setup)
83 ;;; TODO: Add mouse hover popup info support.
88 (provide 'org-tag-eldoc)
90 ;;; org-tag-eldoc.el ends here