Merge pull request #156 from MatthewZMD/generalize_get_url

Generalize get_bookmark into get_url with eaf-get-path-or-url
master
Andy Stewart 6 years ago committed by GitHub
commit 0c2a9f2064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/pdf-viewer/buffer.py
  2. 4
      core/browser_buffer.py
  3. 4
      core/buffer.py
  4. 6
      docs/HACKING.md
  5. 18
      eaf.el

@ -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)

@ -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;")

@ -291,5 +291,5 @@ class Buffer(QGraphicsScene):
def update_settings(self):
pass
def get_bookmark(self):
return ""
def get_url(self):
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
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.

@ -7,7 +7,7 @@
;; Copyright (C) 2018, Andy Stewart, all rights reserved.
;; Created: 2018-06-15 14:10:12
;; Version: 0.5
;; Last-Updated: Sat Dec 14 14:07:57 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,16 @@ buffer."
(let ((this-command cmd))
(call-interactively cmd))))
(defun eaf-get-path-or-url ()
"Get the current file path or web URL.
When called interactively, copy to kill-ring."
(interactive)
(if (derived-mode-p 'eaf-mode)
(if (called-interactively-p 'any)
(message (kill-new (eaf-call "call_function" eaf--buffer-id "get_url")))
(eaf-call "call_function" eaf--buffer-id "get_url"))
(user-error "This command can only be called in an EAF buffer!")))
(defun eaf--make-proxy-function (fun)
"Define elisp command which can call python function string FUN."

Loading…
Cancel
Save