diff --git a/README.md b/README.md index 2bb62b8..971c30d 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,15 @@ Enable with eaf-evil will dynamically rebind eaf keybindings so that evil-mode works nicely in normal state. +### Integration with Org Mode + +Enable with +```elisp +(require 'eaf-org) +``` + +- Support `org-store-link` and `org-link-open` + - Currently only support pdf-viewer app. ## EAF in the community diff --git a/README.zh-CN.md b/README.zh-CN.md index d5167c3..2bba1f9 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -194,7 +194,12 @@ Markdown预览程序依赖grip,你需要访问[Github Personal access token](h eaf-evil 会动态查询 eaf 应用的按键绑定, 使得 evil 在 normal 模式下也能够很好的支持 eaf 应用。 +### Org Mode 集成 +加载 `eaf-org` 来启用: +```elisp +(require 'eaf-org) +``` ## EAF社区 diff --git a/eaf-org.el b/eaf-org.el new file mode 100644 index 0000000..a0a27ab --- /dev/null +++ b/eaf-org.el @@ -0,0 +1,76 @@ +;; eaf-org.el --- Emacs application framework -*- lexical-binding: t; -*- + +;; Filename: eaf-org.el +;; Description: Emacs application framework +;; Author: stardiviner +;; Maintainer: Andy Stewart +;; Copyright (C) 2018, Andy Stewart, all rights reserved. +;; Created: 2020-05-17 12:31:12 +;; Version: 0.5 +;; Last-Updated: Wed May 20 11:48:43 2020 (-0400) +;; By: Mingde (Matthew) Zeng +;; URL: http://www.emacswiki.org/emacs/download/eaf.el +;; Keywords: +;; Compatibility: GNU Emacs 27.0.50 +;; +;; Features that might be required by this library: +;; +;; Please check README +;; + +;;; This file is NOT part of GNU Emacs + +;;; License +;; +;; 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, 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; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth +;; Floor, Boston, MA 02110-1301, USA. + +(defun eaf-org-store-link () + "Store the page of PDF as link support for `org-store-link'. + +The raw link looks like this: [[eaf:::::]]" + (interactive) + (when (eq major-mode 'eaf-mode) + (let* ((app eaf--buffer-app-name) + (url eaf--buffer-url) + (extra-args (cl-case (intern app) + ('pdf-viewer + (eaf-call "call_function" eaf--buffer-id "current_page")))) + ;; (eaf-call "call_function_with_args" eaf--buffer-id "store_session_data" (format "%s" page-num)) + (link (concat "eaf:" app "::" url "::" extra-args)) + (description (buffer-name))) + (org-link-store-props + :type "eaf" + :link link + :description description)))) + +(defun eaf-org-open (link _) + "Open EAF link with EAF correspoinding application." + (let* ((list (split-string link "::")) + (app (intern (car list))) + (url (cadr list)) + (extra-args (caddr list))) + (cl-case app + ('pdf-viewer + ;; TODO open the PDF file + (eaf-open url "pdf-viewer") + (eaf-call "call_function_with_args" eaf--buffer-id + "jump_to_page_with_num" (format "%s" extra-args)))))) + +(org-link-set-parameters "eaf" + :follow #'eaf-org-open + :store #'eaf-org-store-link) + +(provide 'eaf-org)