-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathol-fanyi.el
56 lines (44 loc) · 1.95 KB
/
ol-fanyi.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
;;; ol-fanyi.el --- Store query word from fanyi-mode -*- lexical-binding: t -*-
;; Copyright (C) 2021 Zhiwei Chen
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Author: Zhiwei Chen <condy0919@gmail.com>
;; Keywords: convenience, tools
;; URL: https://github.com/condy0919/fanyi.el
;; Version: 0.1.0
;; Package-Requires: ((fanyi "0.1.0"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; When this module is active, `org-store-link' in fanyi buffer stores a link to
;; the current query word of the fanyi buffer.
;;; Code:
(require 'ol)
(require 'fanyi)
(org-link-set-parameters "fanyi"
:follow #'fanyi-org-open-link
:store #'fanyi-org-store-link
:complete #'fanyi-org-complete-link)
(defun fanyi-org-open-link (word _)
"Query WORD with `fanyi-dwim' in the current buffer."
(fanyi-dwim word))
(defun fanyi-org-store-link ()
"Store a link to the query word of current fanyi buffer."
(when (eq major-mode 'fanyi-mode)
(org-link-store-props
:type "fanyi"
:link (concat "fanyi:" fanyi-current-word)
:description fanyi-current-word)))
(defun fanyi-org-complete-link (&optional _)
"Completion function for fanyi link."
(concat "fanyi:" (completing-read "Fanyi history for link: " fanyi-history nil nil nil 'fanyi-history)))
(provide 'ol-fanyi)
;;; ol-fanyi.el ends here