diff --git a/app/pdf-viewer/buffer.py b/app/pdf-viewer/buffer.py index dd328b1..a8d69e4 100755 --- a/app/pdf-viewer/buffer.py +++ b/app/pdf-viewer/buffer.py @@ -113,9 +113,6 @@ class AppBuffer(Buffer): def toggle_inverted_mode(self): self.buffer_widget.toggle_inverted_mode() - def get_bookmark(self): - return self.buffer_widget.url - class PdfViewerWidget(QWidget): translate_double_click_word = QtCore.pyqtSignal(str) diff --git a/core/browser_buffer.py b/core/browser_buffer.py index ca34608..850c6c0 100755 --- a/core/browser_buffer.py +++ b/core/browser_buffer.py @@ -94,7 +94,5 @@ class BrowserBuffer(Buffer): def refresh_page(self): self.eval_js("location.reload()") - def get_bookmark(self): + def get_url(self): return self.buffer_widget.web_page.executeJavaScript("window.location.href;") - - diff --git a/core/buffer.py b/core/buffer.py index a7eb993..712e7aa 100755 --- a/core/buffer.py +++ b/core/buffer.py @@ -291,5 +291,5 @@ class Buffer(QGraphicsScene): def update_settings(self): pass - def get_bookmark(self): - return "" + def get_url(self): + return self.url diff --git a/docs/HACKING.md b/docs/HACKING.md index c87c1f2..50bc396 100644 --- a/docs/HACKING.md +++ b/docs/HACKING.md @@ -238,17 +238,17 @@ Above is an example of ```eaf-camera-save-path```, you can customize any variabl ### Call Python method and store function result to temp Elisp variable -In EAF buffer have interface ```get_bookmark``` +In EAF buffer have interface ```get_url``` ```Python -def get_bookmark(self): +def get_url(self): return "" ``` At Elisp side, we can use below code call Python method and store function result to Elisp variable: ```Elisp -(setq temp-var (eaf-call "call_function" eaf--buffer-id "get_bookmark")) +(setq temp-var (eaf-call "call_function" eaf--buffer-id "get_url")) ``` Once you understand principle, you can define your own interface function in core/buffer.py , then use ```call_function``` method on Elisp side to fetch Python function result, don't need define temp elisp variable everywhere. diff --git a/eaf.el b/eaf.el index c650053..00bc381 100644 --- a/eaf.el +++ b/eaf.el @@ -7,7 +7,7 @@ ;; Copyright (C) 2018, Andy Stewart, all rights reserved. ;; Created: 2018-06-15 14:10:12 ;; Version: 0.5 -;; Last-Updated: Fri Dec 13 22:57:38 2019 (-0500) +;; Last-Updated: Sat Dec 14 17:34:32 2019 (-0500) ;; By: Mingde (Matthew) Zeng ;; URL: http://www.emacswiki.org/emacs/download/eaf.el ;; Keywords: @@ -355,15 +355,13 @@ For now only EAF browser app is supported." `((handler . eaf--bookmark-restore) (eaf-app . "browser") (defaults . ,(list eaf--bookmark-title)) - (filename . ,(eaf-call "call_function" - eaf--buffer-id "get_bookmark")))) + (filename . ,(eaf-get-path-or-url)))) (defun eaf--pdf-viewer-bookmark () `((handler . eaf--bookmark-restore) (eaf-app . "pdf-viewer") (defaults . ,(list eaf--bookmark-title)) - (filename . ,(eaf-call "call_function" - eaf--buffer-id "get_bookmark")))) + (filename . ,(eaf-get-path-or-url)))) (defun eaf--bookmark-restore (bookmark) "Restore EAF buffer according to BOOKMARK." @@ -500,6 +498,12 @@ buffer." (let ((this-command cmd)) (call-interactively cmd)))) +(defun eaf-get-path-or-url () + "Get the current file path or web URL, and copy to ‘kill-ring’." + (interactive) + (if (derived-mode-p 'eaf-mode) + (message (kill-new (eaf-call "call_function" eaf--buffer-id "get_url"))) + (user-error "This command can only be called in an EAF buffer!"))) (defun eaf-proxy-function (fun) "Define elisp command which can call python function FUN."