2020-01-22 21:34:42 +01:00
|
|
|
;;; evil-collection-xwidget.el --- Evil bindings for Xwidget -*- lexical-binding: t -*-
|
|
|
|
|
2022-01-13 21:31:29 +01:00
|
|
|
;; Copyright (C) 2020, 2022 Ruslan Kamashev
|
2020-01-22 21:34:42 +01:00
|
|
|
|
|
|
|
;; Author: Ruslan Kamashev <rynffoll@gmail.com>
|
|
|
|
;; Maintainer: James Nguyen <james@jojojames.com>
|
|
|
|
;; Pierre Neidhardt <mail@ambrevar.xyz>
|
|
|
|
;; URL: https://github.com/emacs-evil/evil-collection
|
|
|
|
;; Version: 0.0.1
|
2022-06-07 02:53:16 +02:00
|
|
|
;; Package-Requires: ((emacs "26.3"))
|
2020-01-22 21:34:42 +01:00
|
|
|
;; Keywords: evil, xwidget, tools
|
|
|
|
|
|
|
|
;; This file 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 file 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.
|
|
|
|
;;
|
|
|
|
;; For a full copy of the GNU General Public License
|
|
|
|
;; see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Evil bindings for Xwidget.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
(require 'xwidget)
|
|
|
|
(require 'evil-collection)
|
|
|
|
|
|
|
|
(defvar evil-collection-xwidget-maps '(xwidget-webkit-mode-map))
|
|
|
|
|
2022-01-13 21:31:29 +01:00
|
|
|
;; Silence compile errors
|
2022-05-22 03:39:00 +02:00
|
|
|
(declare-function xwidget-webkit-uri "xwidget")
|
2022-01-13 21:31:29 +01:00
|
|
|
(declare-function xwidget-window-inside-pixel-height "xwidget")
|
|
|
|
|
|
|
|
;; HACK: elisp byte-opt can't optimize 'format' out, so it's checked at runtime.
|
|
|
|
(defun evil-collection-xwidget-webkit--scroll-trampoline (f n)
|
2022-06-04 19:51:23 +02:00
|
|
|
"Compatible wrapper for `xwidget-webkit-scroll-up' and so on.
|
|
|
|
|
2022-01-13 21:31:29 +01:00
|
|
|
F is the name of function, N is the pixel height."
|
|
|
|
(let ((realf (intern (format "%s" f))))
|
|
|
|
(if (>= emacs-major-version 28)
|
|
|
|
(funcall realf n)
|
|
|
|
(funcall realf))))
|
|
|
|
|
|
|
|
(defun evil-collection-xwidget-webkit-scroll-half-page-up ()
|
2022-06-04 19:51:23 +02:00
|
|
|
"Compatible wrapper for `xwidget-webkit-scroll-up'."
|
2022-01-13 21:31:29 +01:00
|
|
|
(interactive)
|
|
|
|
(evil-collection-xwidget-webkit--scroll-trampoline
|
|
|
|
"xwidget-webkit-scroll-up"
|
|
|
|
(/ (xwidget-window-inside-pixel-height (selected-window)) 2)))
|
|
|
|
|
|
|
|
(defun evil-collection-xwidget-webkit-scroll-half-page-down ()
|
2022-06-04 19:51:23 +02:00
|
|
|
"Compatible wrapper for `xwidget-webkit-scroll-down'."
|
2022-01-13 21:31:29 +01:00
|
|
|
(interactive)
|
|
|
|
(evil-collection-xwidget-webkit--scroll-trampoline
|
|
|
|
"xwidget-webkit-scroll-down"
|
|
|
|
(/ (xwidget-window-inside-pixel-height (selected-window)) 2)))
|
|
|
|
|
|
|
|
(defun evil-collection-xwidget-webkit-new-tab (url)
|
|
|
|
"New tab (new buffer) of URL."
|
2022-05-22 03:31:22 +02:00
|
|
|
(interactive "s(New Tab) xwidget-webkit URL: ")
|
2022-01-13 21:31:29 +01:00
|
|
|
(xwidget-webkit-browse-url url :new-session))
|
|
|
|
|
2022-05-22 03:33:22 +02:00
|
|
|
(defvar evil-collection-xwidget-webkit-last-closed-tab-url nil)
|
2022-01-13 21:31:29 +01:00
|
|
|
(defun evil-collection-xwidget-webkit-close-tab ()
|
|
|
|
"Close tab (kill buffer) without confirmation."
|
|
|
|
(interactive)
|
2022-05-22 03:33:22 +02:00
|
|
|
(setq evil-collection-xwidget-webkit-last-closed-tab-url
|
|
|
|
(xwidget-webkit-uri (xwidget-webkit-current-session)))
|
2022-01-13 21:31:29 +01:00
|
|
|
(let ((kill-buffer-query-functions nil))
|
|
|
|
(kill-this-buffer)))
|
|
|
|
|
2022-05-22 03:33:22 +02:00
|
|
|
(defun evil-collection-xwidget-webkit-restore-last-closed-tab ()
|
|
|
|
"Restore last closed tab."
|
|
|
|
(interactive)
|
|
|
|
(if (null evil-collection-xwidget-webkit-last-closed-tab-url)
|
|
|
|
(message "No url to restore.")
|
|
|
|
(message (format "Restoring last closed tab %s"
|
|
|
|
evil-collection-xwidget-webkit-last-closed-tab-url))
|
|
|
|
(xwidget-webkit-browse-url
|
|
|
|
evil-collection-xwidget-webkit-last-closed-tab-url :new-session)
|
|
|
|
(setq evil-collection-xwidget-webkit-last-closed-tab-url nil)))
|
|
|
|
|
2022-01-13 21:31:29 +01:00
|
|
|
(defun evil-collection-xwidget-webkit-search-tabs ()
|
2022-06-04 19:51:23 +02:00
|
|
|
"Search tabs (buffers) with `buffer-name'."
|
2022-01-13 21:31:29 +01:00
|
|
|
(interactive)
|
2022-05-22 03:33:01 +02:00
|
|
|
(cl-flet ((is-xwidget-webkit-buffer?
|
|
|
|
(b) (with-current-buffer b
|
|
|
|
(equal major-mode 'xwidget-webkit-mode))))
|
2022-01-13 21:31:29 +01:00
|
|
|
(let ((bufs (cl-loop for b in (buffer-list)
|
|
|
|
when (is-xwidget-webkit-buffer? b)
|
|
|
|
collect (buffer-name b))))
|
2022-05-22 03:33:01 +02:00
|
|
|
(switch-to-buffer (completing-read "Switch to Tab: " bufs nil t)))))
|
2022-01-13 21:31:29 +01:00
|
|
|
|
2020-01-22 21:34:42 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun evil-collection-xwidget-setup ()
|
|
|
|
"Set up `evil' bindings for `xwidget'."
|
2022-01-13 21:31:29 +01:00
|
|
|
(evil-collection-set-readonly-bindings 'xwidget-webkit-mode-map)
|
2022-05-22 03:31:44 +02:00
|
|
|
|
|
|
|
(evil-collection-define-key 'visual 'xwidget-webkit-mode-map
|
|
|
|
"y" 'xwidget-webkit-copy-selection-as-kill)
|
|
|
|
|
2020-01-22 21:34:42 +01:00
|
|
|
(evil-collection-define-key 'normal 'xwidget-webkit-mode-map
|
2022-01-13 21:31:29 +01:00
|
|
|
;; Mimic vimium (a browser extension)
|
|
|
|
;;
|
2022-06-04 19:51:23 +02:00
|
|
|
;; Since xwidget has no tab concept, `open-url-new-tab' etc are not
|
2022-01-13 21:31:29 +01:00
|
|
|
;; supported.
|
|
|
|
;;
|
|
|
|
;; TODO: edit-mode, visual-mode
|
|
|
|
;;
|
|
|
|
;; Navigating the page
|
2020-01-22 21:34:42 +01:00
|
|
|
"j" 'xwidget-webkit-scroll-up-line
|
2022-01-13 21:31:29 +01:00
|
|
|
"k" 'xwidget-webkit-scroll-down-line
|
|
|
|
"gg" 'xwidget-webkit-scroll-top
|
|
|
|
"G" 'xwidget-webkit-scroll-bottom
|
|
|
|
"d" 'evil-collection-xwidget-webkit-scroll-half-page-up
|
|
|
|
"u" 'evil-collection-xwidget-webkit-scroll-half-page-down
|
2020-01-22 21:34:42 +01:00
|
|
|
"h" 'xwidget-webkit-scroll-backward
|
|
|
|
"l" 'xwidget-webkit-scroll-forward
|
2022-01-13 21:31:29 +01:00
|
|
|
"r" 'xwidget-webkit-reload
|
|
|
|
"yy" 'xwidget-webkit-current-url
|
2022-06-04 19:51:23 +02:00
|
|
|
;; TODO `first-text-input', `open-link-in-current-tab'
|
2022-01-13 21:31:29 +01:00
|
|
|
"gi" 'undefined
|
|
|
|
"f" 'undefined
|
|
|
|
|
|
|
|
;; Using the vomnibar
|
|
|
|
;;
|
|
|
|
;; For bookmark, use C-x r m, C-x r j.
|
|
|
|
"o" 'xwidget-webkit-browse-url
|
|
|
|
"T" 'evil-collection-xwidget-webkit-search-tabs
|
|
|
|
|
|
|
|
;; Using find
|
|
|
|
;;
|
|
|
|
;; TODO
|
|
|
|
|
|
|
|
;; Navigating history
|
|
|
|
"H" 'xwidget-webkit-back
|
|
|
|
"L" 'xwidget-webkit-forward
|
|
|
|
|
|
|
|
;; Manipulating tabs (actually buffers)
|
|
|
|
;;
|
2022-06-04 19:51:23 +02:00
|
|
|
;; Only `new-tab' and `close-tab' are supported.
|
2022-01-13 21:31:29 +01:00
|
|
|
"t" 'evil-collection-xwidget-webkit-new-tab
|
|
|
|
"x" 'evil-collection-xwidget-webkit-close-tab
|
2022-05-22 03:33:22 +02:00
|
|
|
"X" 'evil-collection-xwidget-webkit-restore-last-closed-tab
|
2022-01-13 21:31:29 +01:00
|
|
|
|
|
|
|
;; Miscellaneous
|
|
|
|
"?" 'describe-mode
|
|
|
|
|
|
|
|
;; Evil style
|
2022-05-22 03:32:22 +02:00
|
|
|
|
|
|
|
"<" 'xwidget-webkit-back
|
|
|
|
">" 'xwidget-webkit-forward
|
|
|
|
|
|
|
|
;; Additional bindings to browse url.
|
|
|
|
"gu" 'xwidget-webkit-browse-url
|
|
|
|
"J" 'xwidget-webkit-browse-url
|
|
|
|
|
|
|
|
;; Additional binding to browse tabs.
|
|
|
|
"gt" 'evil-collection-xwidget-webkit-search-tabs
|
|
|
|
|
2022-01-13 21:31:29 +01:00
|
|
|
"gr" 'xwidget-webkit-reload
|
2020-01-22 21:34:42 +01:00
|
|
|
(kbd "C-f") 'xwidget-webkit-scroll-up
|
|
|
|
(kbd "C-b") 'xwidget-webkit-scroll-down
|
2022-01-13 21:31:29 +01:00
|
|
|
(kbd "RET") 'xwidget-webkit-insert-string
|
|
|
|
|
|
|
|
;; zoom
|
2020-01-22 21:34:42 +01:00
|
|
|
"+" 'xwidget-webkit-zoom-in
|
|
|
|
"=" 'xwidget-webkit-zoom-in
|
2022-01-13 21:31:29 +01:00
|
|
|
"-" 'xwidget-webkit-zoom-out)
|
2020-01-22 21:34:42 +01:00
|
|
|
|
|
|
|
(when evil-want-C-d-scroll
|
|
|
|
(evil-collection-define-key 'normal 'xwidget-webkit-mode-map
|
|
|
|
(kbd "C-d") 'xwidget-webkit-scroll-up))
|
|
|
|
(when evil-want-C-u-scroll
|
|
|
|
(evil-collection-define-key 'normal 'xwidget-webkit-mode-map
|
2020-04-26 07:37:30 +02:00
|
|
|
(kbd "C-u") 'xwidget-webkit-scroll-down)))
|
2020-01-22 21:34:42 +01:00
|
|
|
|
|
|
|
(provide 'evil-collection-xwidget)
|
|
|
|
;;; evil-collection-xwidget.el ends here
|