~xwidget configuration

Just new functionality, read it to know
This commit is contained in:
2020-09-01 23:29:25 +01:00
parent 8ff51cad63
commit bd7a94bb5f

View File

@@ -1046,59 +1046,60 @@ learnt the basics of org).
#+end_src #+end_src
** Xwidget ** Xwidget
*** Preamble *** Preamble
Xwidget is a package (that must be compiled at source) which allows Xwidget is a package (must be compiled at source) which allows for the
for the insertion of arbitrary xwidgets into Emacs through insertion of arbitrary xwidgets into Emacs through buffers. One of its
buffers. One of its premier uses is in navigating the web which it premier uses is in navigating the web which it provides through the
provides through the function =xwidget-webkit-browse-url=. This function =xwidget-webkit-browse-url=. This renders a fully functional
renders a fully functional web browser within Emacs. web browser within Emacs.
Though I am not to keen on using Emacs to browse the web /via/ xwidget Though I am not to keen on using Emacs to browse the web /via/ xwidget
(EWW does a good job on its own), I am very interested in its (EWW does a good job on its own), I am very interested in its
capability to render full fledged HTML documents, as it may come of capability to render full fledged web pages which include JavaScript,
use when doing web development. I can see the results of work very as it may come of use when doing web development. I can see the
quickly without switching windows or workspaces. results of work very quickly without switching windows or workspaces.
*** Core *** Core
Define a function =+xwidget/render-file= that reads a file name and Define a function =+xwidget/render-file= that reads a file name and
presents it in an xwidget. If the current file is an HTML file, ask if presents it in an xwidget. If the current file is an HTML file, ask if
user wants to open current file. Bind it to =au= in the leader. user wants to open current file. Bind it to =aU= in the leader.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package xwidget (use-package xwidget
:straight nil :commands +xwidget/render-file
:general :straight nil
(leader "aU" #'xwidget-webkit-browse-url) :general
(general-def (leader "au" #'xwidget-webkit-browse-url
:states 'normal "aU" #'+xwidget/render-file)
:keymaps 'xwidget-webkit-mode-map (general-def
"q" #'quit-window :states 'normal
"h" #'xwidget-webkit-scroll-backward :keymaps 'xwidget-webkit-mode-map
"j" #'xwidget-webkit-scroll-up "q" #'quit-window
"k" #'xwidget-webkit-scroll-down "h" #'xwidget-webkit-scroll-backward
"l" #'xwidget-webkit-scroll-forward "j" #'xwidget-webkit-scroll-up
(kbd "C-f") #'xwidget-webkit-scroll-up "k" #'xwidget-webkit-scroll-down
(kbd "C-b") #'xwidget-webkit-scroll-down "l" #'xwidget-webkit-scroll-forward
"H" #'xwidget-webkit-back (kbd "C-f") #'xwidget-webkit-scroll-up
"L" #'xwidget-webkit-forward (kbd "C-b") #'xwidget-webkit-scroll-down
"gu" #'xwidget-webkit-browse-url "H" #'xwidget-webkit-back
"gr" #'xwidget-webkit-reload "L" #'xwidget-webkit-forward
"gg" #'xwidget-webkit-scroll-top "gu" #'xwidget-webkit-browse-url
"G" #'xwidget-webkit-scroll-bottom) "gr" #'xwidget-webkit-reload
:config "gg" #'xwidget-webkit-scroll-top
(defun +xwidget/render-file (&optional FORCE) "G" #'xwidget-webkit-scroll-bottom)
"Find file (or use current file) and render in xwidget." :config
(interactive) (defun +xwidget/render-file (&optional FORCE)
(cond "Find file (or use current file) and render in xwidget."
((and (not FORCE) (or (string= (replace-regexp-in-string ".*.html" "html" (buffer-name)) (interactive)
"html") (cond
(eq major-mode 'web-mode) ((and (not FORCE) (or (string= (replace-regexp-in-string ".*.html"
(eq major-mode 'html-mode))) ; If in html file "html" (buffer-name)) "html")
(if (y-or-n-p "Open current file?: ") ; Maybe they want to open a separate file (eq major-mode 'web-mode)
(xwidget-webkit-browse-url (format "file://%s" (buffer-file-name))) (eq major-mode 'html-mode))) ; If in html file
(+xwidget/render-file t))) ; recurse and open file via prompt (if (y-or-n-p "Open current file?: ") ; Maybe they want to open a separate file
(t (xwidget-webkit-browse-url (format "file://%s" (buffer-file-name)))
(xwidget-webkit-browse-url (format "file://%s" (read-file-name "Enter file to open: ")))))) (+xwidget/render-file t))) ; recurse and open file via prompt
(t
(leader "au" #'+xwidget/render-file)) (xwidget-webkit-browse-url
(format "file://%s" (read-file-name "Enter file to open: ")))))))
#+end_src #+end_src
** Eshell ** Eshell