Generalize get_bookmark into get_url with eaf-get-path-or-url

master
Matthew 6 years ago
parent 29c6305e1e
commit d4627fd717
  1. 3
      app/pdf-viewer/buffer.py
  2. 4
      core/browser_buffer.py
  3. 4
      core/buffer.py
  4. 6
      docs/HACKING.md
  5. 14
      eaf.el

@ -113,9 +113,6 @@ class AppBuffer(Buffer):
def toggle_inverted_mode(self): def toggle_inverted_mode(self):
self.buffer_widget.toggle_inverted_mode() self.buffer_widget.toggle_inverted_mode()
def get_bookmark(self):
return self.buffer_widget.url
class PdfViewerWidget(QWidget): class PdfViewerWidget(QWidget):
translate_double_click_word = QtCore.pyqtSignal(str) translate_double_click_word = QtCore.pyqtSignal(str)

@ -94,7 +94,5 @@ class BrowserBuffer(Buffer):
def refresh_page(self): def refresh_page(self):
self.eval_js("location.reload()") self.eval_js("location.reload()")
def get_bookmark(self): def get_url(self):
return self.buffer_widget.web_page.executeJavaScript("window.location.href;") return self.buffer_widget.web_page.executeJavaScript("window.location.href;")

@ -291,5 +291,5 @@ class Buffer(QGraphicsScene):
def update_settings(self): def update_settings(self):
pass pass
def get_bookmark(self): def get_url(self):
return "" return self.url

@ -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 ### 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 ```Python
def get_bookmark(self): def get_url(self):
return "" return ""
``` ```
At Elisp side, we can use below code call Python method and store function result to Elisp variable: At Elisp side, we can use below code call Python method and store function result to Elisp variable:
```Elisp ```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. 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.

@ -7,7 +7,7 @@
;; Copyright (C) 2018, Andy Stewart, all rights reserved. ;; Copyright (C) 2018, Andy Stewart, all rights reserved.
;; Created: 2018-06-15 14:10:12 ;; Created: 2018-06-15 14:10:12
;; Version: 0.5 ;; 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 ;; By: Mingde (Matthew) Zeng
;; URL: http://www.emacswiki.org/emacs/download/eaf.el ;; URL: http://www.emacswiki.org/emacs/download/eaf.el
;; Keywords: ;; Keywords:
@ -355,15 +355,13 @@ For now only EAF browser app is supported."
`((handler . eaf--bookmark-restore) `((handler . eaf--bookmark-restore)
(eaf-app . "browser") (eaf-app . "browser")
(defaults . ,(list eaf--bookmark-title)) (defaults . ,(list eaf--bookmark-title))
(filename . ,(eaf-call "call_function" (filename . ,(eaf-get-path-or-url))))
eaf--buffer-id "get_bookmark"))))
(defun eaf--pdf-viewer-bookmark () (defun eaf--pdf-viewer-bookmark ()
`((handler . eaf--bookmark-restore) `((handler . eaf--bookmark-restore)
(eaf-app . "pdf-viewer") (eaf-app . "pdf-viewer")
(defaults . ,(list eaf--bookmark-title)) (defaults . ,(list eaf--bookmark-title))
(filename . ,(eaf-call "call_function" (filename . ,(eaf-get-path-or-url))))
eaf--buffer-id "get_bookmark"))))
(defun eaf--bookmark-restore (bookmark) (defun eaf--bookmark-restore (bookmark)
"Restore EAF buffer according to BOOKMARK." "Restore EAF buffer according to BOOKMARK."
@ -500,6 +498,12 @@ buffer."
(let ((this-command cmd)) (let ((this-command cmd))
(call-interactively 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) (defun eaf-proxy-function (fun)
"Define elisp command which can call python function FUN." "Define elisp command which can call python function FUN."

Loading…
Cancel
Save