1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-27 07:37:33 +00:00
emacs/lisp/xwidget.el

728 lines
28 KiB
EmacsLisp
Raw Normal View History

;;; xwidget.el --- api functions for xwidgets -*- lexical-binding: t -*-
;;
;; Copyright (C) 2011-2021 Free Software Foundation, Inc.
;;
;; Author: Joakim Verona (joakim@verona.se)
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs 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 of the License, or
;; (at your option) any later version.
;; GNU Emacs 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.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;
;; --------------------------------------------------------------------
;;; Commentary:
;;
2016-01-20 00:06:32 +00:00
;; See xwidget.c for more api functions.
;; This breaks compilation when we don't have xwidgets.
;; And is pointless when we do, since it's in C and so preloaded.
;;(require 'xwidget-internal)
;;; Code:
(require 'cl-lib)
(require 'bookmark)
(declare-function make-xwidget "xwidget.c"
(type title width height arguments &optional buffer))
(declare-function xwidget-buffer "xwidget.c" (xwidget))
(declare-function xwidget-size-request "xwidget.c" (xwidget))
(declare-function xwidget-resize "xwidget.c" (xwidget new-width new-height))
(declare-function xwidget-webkit-execute-script "xwidget.c"
(xwidget script &optional callback))
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(declare-function xwidget-webkit-uri "xwidget.c" (xwidget))
(declare-function xwidget-webkit-title "xwidget.c" (xwidget))
(declare-function xwidget-webkit-goto-uri "xwidget.c" (xwidget uri))
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(declare-function xwidget-webkit-goto-history "xwidget.c" (xwidget rel-pos))
(declare-function xwidget-webkit-zoom "xwidget.c" (xwidget factor))
(declare-function xwidget-plist "xwidget.c" (xwidget))
(declare-function set-xwidget-plist "xwidget.c" (xwidget plist))
(declare-function xwidget-view-window "xwidget.c" (xwidget-view))
(declare-function xwidget-view-model "xwidget.c" (xwidget-view))
(declare-function delete-xwidget-view "xwidget.c" (xwidget-view))
(declare-function get-buffer-xwidgets "xwidget.c" (buffer))
(declare-function xwidget-query-on-exit-flag "xwidget.c" (xwidget))
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(defgroup xwidget nil
"Displaying native widgets in Emacs buffers."
:group 'widgets)
(defun xwidget-insert (pos type title width height &optional args)
"Insert an xwidget at position POS.
Supply the xwidget's TYPE, TITLE, WIDTH, and HEIGHT.
See `make-xwidget' for the possible TYPE values.
The usage of optional argument ARGS depends on the xwidget.
This returns the result of `make-xwidget'."
(goto-char pos)
(let ((id (make-xwidget type title width height args)))
(put-text-property (point) (+ 1 (point))
'display (list 'xwidget ':xwidget id))
id))
(defun xwidget-at (pos)
"Return xwidget at POS."
2016-01-20 00:06:32 +00:00
;; TODO this function is a bit tedious because the C layer isn't well
;; protected yet and xwidgetp apparently doesn't work yet.
(let* ((disp (get-text-property pos 'display))
(xw (car (cdr (cdr disp)))))
;;(if (xwidgetp xw) xw nil)
(if (equal 'xwidget (car disp)) xw)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; webkit support
(require 'browse-url)
(require 'image-mode);;for some image-mode alike functionality
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(require 'seq)
(require 'url-handlers)
;;;###autoload
(defun xwidget-webkit-browse-url (url &optional new-session)
"Ask xwidget-webkit to browse URL.
NEW-SESSION specifies whether to create a new xwidget-webkit session.
Interactively, URL defaults to the string looking like a url around point."
(interactive (progn
(require 'browse-url)
2021-08-22 23:52:16 +00:00
(browse-url-interactive-arg "xwidget-webkit URL: ")))
(or (featurep 'xwidget-internal)
(user-error "Your Emacs was not compiled with xwidgets support"))
(when (stringp url)
;; If it's a "naked url", just try adding https: to it.
(unless (string-match "\\`[A-Za-z]+:" url)
(setq url (concat "https://" url)))
(if new-session
(xwidget-webkit-new-session url)
(xwidget-webkit-goto-url url))))
Add xwidget support for macOS Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * configure.ac: Allow '--with-xwidgets' for "${NS_IMPL_COCOA}". * etc/NEWS: Mention new feature. * etc/TODO: Remove done TODO to implement xwidget in NeXTstep port. * lisp/xwidget.el (xwidget-webkit-clone-and-split-below) (xwidget-webkit-clone-and-split-right): New procedures. (xwidget-webkit-callback): Remove call to 'xwidget-webkit-adjust-size-to-window' as adjusting xwidget size is handled in 'x_draw_xwidget_glyph_string'. (xwidget-webkit-enable-plugins): New variable. * nextstep/templates/Info.plist.in: Add 'NSAppTransportSecurity'. * src/Makefile.in: Add nsxwidget.o for compilation. * src/emacs.c (main): Move conditional call to 'syms_of_xwidget'. * src/nsterm.m (ns_draw_glyph_string): Add case for 'XWIDGET_GLYPH'. (note_mouse_movement mouseMoved): Make it easy to resize window by dragging mode-line or vertical separator adjacent to large glyph. * src/nsxwidget.h src/nsxwidget.m: Newly added files, xwidget webkit backend for macOS Cocoa. * src/xwidget.c (Fmake_xwidget, xwidget_init_view) (x_draw_xwidget_glyph_string, xwidget_is_web_view) (Fxwidget_webkit_goto_uri, Fxwidget_webkit_zoom, Fxwidget_resize) (Fxwidget_size_request, Fdelete_xwidget_view, xwidget_end_redisplay) (kill_buffer_xwidgets): Add macOS Cocoa specific functions and code with 'NS_IMPL_COCOA' and guard GTK specific functions and code with 'USE_GTK'. (x_draw_xwidget_glyph_string): Handle adjusting xwidget size. * src/xwidget.h (xwidget, xwidget_view): Add macOS Cocoa specific fields with 'NS_IMPL_COCOA' and guard GTK specific fields with USE_GTK.
2020-08-12 10:12:34 +00:00
(defun xwidget-webkit-clone-and-split-below ()
"Clone current URL into a new widget place in new window below.
Get the URL of current session, then browse to the URL
in `split-window-below' with a new xwidget webkit session."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
Add xwidget support for macOS Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * configure.ac: Allow '--with-xwidgets' for "${NS_IMPL_COCOA}". * etc/NEWS: Mention new feature. * etc/TODO: Remove done TODO to implement xwidget in NeXTstep port. * lisp/xwidget.el (xwidget-webkit-clone-and-split-below) (xwidget-webkit-clone-and-split-right): New procedures. (xwidget-webkit-callback): Remove call to 'xwidget-webkit-adjust-size-to-window' as adjusting xwidget size is handled in 'x_draw_xwidget_glyph_string'. (xwidget-webkit-enable-plugins): New variable. * nextstep/templates/Info.plist.in: Add 'NSAppTransportSecurity'. * src/Makefile.in: Add nsxwidget.o for compilation. * src/emacs.c (main): Move conditional call to 'syms_of_xwidget'. * src/nsterm.m (ns_draw_glyph_string): Add case for 'XWIDGET_GLYPH'. (note_mouse_movement mouseMoved): Make it easy to resize window by dragging mode-line or vertical separator adjacent to large glyph. * src/nsxwidget.h src/nsxwidget.m: Newly added files, xwidget webkit backend for macOS Cocoa. * src/xwidget.c (Fmake_xwidget, xwidget_init_view) (x_draw_xwidget_glyph_string, xwidget_is_web_view) (Fxwidget_webkit_goto_uri, Fxwidget_webkit_zoom, Fxwidget_resize) (Fxwidget_size_request, Fdelete_xwidget_view, xwidget_end_redisplay) (kill_buffer_xwidgets): Add macOS Cocoa specific functions and code with 'NS_IMPL_COCOA' and guard GTK specific functions and code with 'USE_GTK'. (x_draw_xwidget_glyph_string): Handle adjusting xwidget size. * src/xwidget.h (xwidget, xwidget_view): Add macOS Cocoa specific fields with 'NS_IMPL_COCOA' and guard GTK specific fields with USE_GTK.
2020-08-12 10:12:34 +00:00
(let ((url (xwidget-webkit-current-url)))
(with-selected-window (split-window-below)
(xwidget-webkit-new-session url))))
(defun xwidget-webkit-clone-and-split-right ()
"Clone current URL into a new widget place in new window right.
Get the URL of current session, then browse to the URL
in `split-window-right' with a new xwidget webkit session."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
Add xwidget support for macOS Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * configure.ac: Allow '--with-xwidgets' for "${NS_IMPL_COCOA}". * etc/NEWS: Mention new feature. * etc/TODO: Remove done TODO to implement xwidget in NeXTstep port. * lisp/xwidget.el (xwidget-webkit-clone-and-split-below) (xwidget-webkit-clone-and-split-right): New procedures. (xwidget-webkit-callback): Remove call to 'xwidget-webkit-adjust-size-to-window' as adjusting xwidget size is handled in 'x_draw_xwidget_glyph_string'. (xwidget-webkit-enable-plugins): New variable. * nextstep/templates/Info.plist.in: Add 'NSAppTransportSecurity'. * src/Makefile.in: Add nsxwidget.o for compilation. * src/emacs.c (main): Move conditional call to 'syms_of_xwidget'. * src/nsterm.m (ns_draw_glyph_string): Add case for 'XWIDGET_GLYPH'. (note_mouse_movement mouseMoved): Make it easy to resize window by dragging mode-line or vertical separator adjacent to large glyph. * src/nsxwidget.h src/nsxwidget.m: Newly added files, xwidget webkit backend for macOS Cocoa. * src/xwidget.c (Fmake_xwidget, xwidget_init_view) (x_draw_xwidget_glyph_string, xwidget_is_web_view) (Fxwidget_webkit_goto_uri, Fxwidget_webkit_zoom, Fxwidget_resize) (Fxwidget_size_request, Fdelete_xwidget_view, xwidget_end_redisplay) (kill_buffer_xwidgets): Add macOS Cocoa specific functions and code with 'NS_IMPL_COCOA' and guard GTK specific functions and code with 'USE_GTK'. (x_draw_xwidget_glyph_string): Handle adjusting xwidget size. * src/xwidget.h (xwidget, xwidget_view): Add macOS Cocoa specific fields with 'NS_IMPL_COCOA' and guard GTK specific fields with USE_GTK.
2020-08-12 10:12:34 +00:00
(let ((url (xwidget-webkit-current-url)))
(with-selected-window (split-window-right)
(xwidget-webkit-new-session url))))
;;todo.
;; - check that the webkit support is compiled in
(defvar xwidget-webkit-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "g" 'xwidget-webkit-browse-url)
(define-key map "a" 'xwidget-webkit-adjust-size-dispatch)
(define-key map "b" 'xwidget-webkit-back)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(define-key map "f" 'xwidget-webkit-forward)
(define-key map "r" 'xwidget-webkit-reload)
(define-key map "t" (lambda () (interactive) (message "o"))) ;FIXME: ?!?
(define-key map "\C-m" 'xwidget-webkit-insert-string)
(define-key map "w" 'xwidget-webkit-current-url)
(define-key map "+" 'xwidget-webkit-zoom-in)
(define-key map "-" 'xwidget-webkit-zoom-out)
;;similar to image mode bindings
(define-key map (kbd "SPC") 'xwidget-webkit-scroll-up)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(define-key map (kbd "S-SPC") 'xwidget-webkit-scroll-down)
(define-key map (kbd "DEL") 'xwidget-webkit-scroll-down)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(define-key map [remap scroll-up] 'xwidget-webkit-scroll-up-line)
(define-key map [remap scroll-up-command] 'xwidget-webkit-scroll-up)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(define-key map [remap scroll-down] 'xwidget-webkit-scroll-down-line)
(define-key map [remap scroll-down-command] 'xwidget-webkit-scroll-down)
(define-key map [remap forward-char] 'xwidget-webkit-scroll-forward)
(define-key map [remap backward-char] 'xwidget-webkit-scroll-backward)
(define-key map [remap right-char] 'xwidget-webkit-scroll-forward)
(define-key map [remap left-char] 'xwidget-webkit-scroll-backward)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(define-key map [remap previous-line] 'xwidget-webkit-scroll-down-line)
(define-key map [remap next-line] 'xwidget-webkit-scroll-up-line)
;; (define-key map [remap move-beginning-of-line] 'image-bol)
;; (define-key map [remap move-end-of-line] 'image-eol)
(define-key map [remap beginning-of-buffer] 'xwidget-webkit-scroll-top)
(define-key map [remap end-of-buffer] 'xwidget-webkit-scroll-bottom)
map)
"Keymap for `xwidget-webkit-mode'.")
(defun xwidget-webkit-zoom-in ()
"Increase webkit view zoom factor."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
(xwidget-webkit-zoom (xwidget-webkit-current-session) 0.1))
(defun xwidget-webkit-zoom-out ()
"Decrease webkit view zoom factor."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
(xwidget-webkit-zoom (xwidget-webkit-current-session) -0.1))
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(defun xwidget-webkit-scroll-up (&optional arg)
"Scroll webkit up by ARG pixels; or full window height if no ARG.
Stop if bottom of page is reached.
Interactively, ARG is the prefix numeric argument.
Negative ARG scrolls down."
2021-08-22 23:52:16 +00:00
(interactive "P" xwidget-webkit-mode)
(xwidget-webkit-execute-script
(xwidget-webkit-current-session)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(format "window.scrollBy(0, %d);"
(or arg (xwidget-window-inside-pixel-height (selected-window))))))
(defun xwidget-webkit-scroll-down (&optional arg)
"Scroll webkit down by ARG pixels; or full window height if no ARG.
Stop if top of page is reached.
Interactively, ARG is the prefix numeric argument.
Negative ARG scrolls up."
2021-08-22 23:52:16 +00:00
(interactive "P" xwidget-webkit-mode)
(xwidget-webkit-execute-script
(xwidget-webkit-current-session)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(format "window.scrollBy(0, -%d);"
(or arg (xwidget-window-inside-pixel-height (selected-window))))))
(defun xwidget-webkit-scroll-up-line (&optional n)
"Scroll webkit up by N lines.
The height of line is calculated with `window-font-height'.
Stop if the bottom edge of the page is reached.
If N is omitted or nil, scroll up by one line."
2021-08-22 23:52:16 +00:00
(interactive "p" xwidget-webkit-mode)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(xwidget-webkit-scroll-up (* n (window-font-height))))
(defun xwidget-webkit-scroll-down-line (&optional n)
"Scroll webkit down by N lines.
The height of line is calculated with `window-font-height'.
Stop if the top edge of the page is reached.
If N is omitted or nil, scroll down by one line."
2021-08-22 23:52:16 +00:00
(interactive "p" xwidget-webkit-mode)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(xwidget-webkit-scroll-down (* n (window-font-height))))
(defun xwidget-webkit-scroll-forward (&optional n)
"Scroll webkit horizontally by N chars.
The width of char is calculated with `window-font-width'.
2020-09-21 11:29:10 +00:00
If N is omitted or nil, scroll forwards by one char."
2021-08-22 23:52:16 +00:00
(interactive "p" xwidget-webkit-mode)
(xwidget-webkit-execute-script
(xwidget-webkit-current-session)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(format "window.scrollBy(%d, 0);"
(* n (window-font-width)))))
(defun xwidget-webkit-scroll-backward (&optional n)
"Scroll webkit back by N chars.
The width of char is calculated with `window-font-width'.
2020-09-21 11:29:10 +00:00
If N is omitted or nil, scroll backwards by one char."
2021-08-22 23:52:16 +00:00
(interactive "p" xwidget-webkit-mode)
(xwidget-webkit-execute-script
(xwidget-webkit-current-session)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(format "window.scrollBy(-%d, 0);"
(* n (window-font-width)))))
(defun xwidget-webkit-scroll-top ()
"Scroll webkit to the very top."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
(xwidget-webkit-execute-script
(xwidget-webkit-current-session)
"window.scrollTo(pageXOffset, 0);"))
(defun xwidget-webkit-scroll-bottom ()
"Scroll webkit to the very bottom."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
(xwidget-webkit-execute-script
(xwidget-webkit-current-session)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
"window.scrollTo(pageXOffset, window.document.body.scrollHeight);"))
2016-01-20 00:06:32 +00:00
;; The xwidget event needs to go into a higher level handler
;; since the xwidget can generate an event even if it's offscreen.
;; TODO this needs to use callbacks and consider different xwidget event types.
(define-key (current-global-map) [xwidget-event] #'xwidget-event-handler)
(defun xwidget-log (&rest msg)
"Log MSG to a buffer."
(let ((buf (get-buffer-create " *xwidget-log*")))
(with-current-buffer buf
(insert (apply #'format msg))
(insert "\n"))))
(defun xwidget-event-handler ()
"Receive xwidget event."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
(xwidget-log "stuff happened to xwidget %S" last-input-event)
(let*
((xwidget-event-type (nth 1 last-input-event))
(xwidget (nth 2 last-input-event))
(xwidget-callback (xwidget-get xwidget 'callback)))
(funcall xwidget-callback xwidget xwidget-event-type)))
(defun xwidget-webkit-callback (xwidget xwidget-event-type)
"Callback for xwidgets.
XWIDGET instance, XWIDGET-EVENT-TYPE depends on the originating xwidget."
(if (not (buffer-live-p (xwidget-buffer xwidget)))
(xwidget-log
"error: callback called for xwidget with dead buffer")
(with-current-buffer (xwidget-buffer xwidget)
(cond ((eq xwidget-event-type 'load-changed)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(let ((title (xwidget-webkit-title xwidget)))
(xwidget-log "webkit finished loading: %s" title)
;; Do not adjust webkit size to window here, the selected window
;; can be the mini-buffer window unwantedly.
(rename-buffer (format "*xwidget webkit: %s *" title) t)))
((eq xwidget-event-type 'decide-policy)
(let ((strarg (nth 3 last-input-event)))
(if (string-match ".*#\\(.*\\)" strarg)
(xwidget-webkit-show-id-or-named-element
xwidget
(match-string 1 strarg)))))
;; TODO: Response handling other than download.
((eq xwidget-event-type 'download-callback)
(let ((url (nth 3 last-input-event))
(mime-type (nth 4 last-input-event))
(file-name (nth 5 last-input-event)))
(xwidget-webkit-save-as-file url mime-type file-name)))
((eq xwidget-event-type 'javascript-callback)
(let ((proc (nth 3 last-input-event))
(arg (nth 4 last-input-event)))
(funcall proc arg)))
(t (xwidget-log "unhandled event:%s" xwidget-event-type))))))
(defvar bookmark-make-record-function)
Add xwidget support for macOS Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * configure.ac: Allow '--with-xwidgets' for "${NS_IMPL_COCOA}". * etc/NEWS: Mention new feature. * etc/TODO: Remove done TODO to implement xwidget in NeXTstep port. * lisp/xwidget.el (xwidget-webkit-clone-and-split-below) (xwidget-webkit-clone-and-split-right): New procedures. (xwidget-webkit-callback): Remove call to 'xwidget-webkit-adjust-size-to-window' as adjusting xwidget size is handled in 'x_draw_xwidget_glyph_string'. (xwidget-webkit-enable-plugins): New variable. * nextstep/templates/Info.plist.in: Add 'NSAppTransportSecurity'. * src/Makefile.in: Add nsxwidget.o for compilation. * src/emacs.c (main): Move conditional call to 'syms_of_xwidget'. * src/nsterm.m (ns_draw_glyph_string): Add case for 'XWIDGET_GLYPH'. (note_mouse_movement mouseMoved): Make it easy to resize window by dragging mode-line or vertical separator adjacent to large glyph. * src/nsxwidget.h src/nsxwidget.m: Newly added files, xwidget webkit backend for macOS Cocoa. * src/xwidget.c (Fmake_xwidget, xwidget_init_view) (x_draw_xwidget_glyph_string, xwidget_is_web_view) (Fxwidget_webkit_goto_uri, Fxwidget_webkit_zoom, Fxwidget_resize) (Fxwidget_size_request, Fdelete_xwidget_view, xwidget_end_redisplay) (kill_buffer_xwidgets): Add macOS Cocoa specific functions and code with 'NS_IMPL_COCOA' and guard GTK specific functions and code with 'USE_GTK'. (x_draw_xwidget_glyph_string): Handle adjusting xwidget size. * src/xwidget.h (xwidget, xwidget_view): Add macOS Cocoa specific fields with 'NS_IMPL_COCOA' and guard GTK specific fields with USE_GTK.
2020-08-12 10:12:34 +00:00
(when (memq window-system '(mac ns))
(defcustom xwidget-webkit-enable-plugins nil
Add xwidget support for macOS Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * configure.ac: Allow '--with-xwidgets' for "${NS_IMPL_COCOA}". * etc/NEWS: Mention new feature. * etc/TODO: Remove done TODO to implement xwidget in NeXTstep port. * lisp/xwidget.el (xwidget-webkit-clone-and-split-below) (xwidget-webkit-clone-and-split-right): New procedures. (xwidget-webkit-callback): Remove call to 'xwidget-webkit-adjust-size-to-window' as adjusting xwidget size is handled in 'x_draw_xwidget_glyph_string'. (xwidget-webkit-enable-plugins): New variable. * nextstep/templates/Info.plist.in: Add 'NSAppTransportSecurity'. * src/Makefile.in: Add nsxwidget.o for compilation. * src/emacs.c (main): Move conditional call to 'syms_of_xwidget'. * src/nsterm.m (ns_draw_glyph_string): Add case for 'XWIDGET_GLYPH'. (note_mouse_movement mouseMoved): Make it easy to resize window by dragging mode-line or vertical separator adjacent to large glyph. * src/nsxwidget.h src/nsxwidget.m: Newly added files, xwidget webkit backend for macOS Cocoa. * src/xwidget.c (Fmake_xwidget, xwidget_init_view) (x_draw_xwidget_glyph_string, xwidget_is_web_view) (Fxwidget_webkit_goto_uri, Fxwidget_webkit_zoom, Fxwidget_resize) (Fxwidget_size_request, Fdelete_xwidget_view, xwidget_end_redisplay) (kill_buffer_xwidgets): Add macOS Cocoa specific functions and code with 'NS_IMPL_COCOA' and guard GTK specific functions and code with 'USE_GTK'. (x_draw_xwidget_glyph_string): Handle adjusting xwidget size. * src/xwidget.h (xwidget, xwidget_view): Add macOS Cocoa specific fields with 'NS_IMPL_COCOA' and guard GTK specific fields with USE_GTK.
2020-08-12 10:12:34 +00:00
"Enable plugins for xwidget webkit.
If non-nil, plugins are enabled. Otherwise, disabled."
:type 'boolean
:version "28.1"))
Add xwidget support for macOS Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * configure.ac: Allow '--with-xwidgets' for "${NS_IMPL_COCOA}". * etc/NEWS: Mention new feature. * etc/TODO: Remove done TODO to implement xwidget in NeXTstep port. * lisp/xwidget.el (xwidget-webkit-clone-and-split-below) (xwidget-webkit-clone-and-split-right): New procedures. (xwidget-webkit-callback): Remove call to 'xwidget-webkit-adjust-size-to-window' as adjusting xwidget size is handled in 'x_draw_xwidget_glyph_string'. (xwidget-webkit-enable-plugins): New variable. * nextstep/templates/Info.plist.in: Add 'NSAppTransportSecurity'. * src/Makefile.in: Add nsxwidget.o for compilation. * src/emacs.c (main): Move conditional call to 'syms_of_xwidget'. * src/nsterm.m (ns_draw_glyph_string): Add case for 'XWIDGET_GLYPH'. (note_mouse_movement mouseMoved): Make it easy to resize window by dragging mode-line or vertical separator adjacent to large glyph. * src/nsxwidget.h src/nsxwidget.m: Newly added files, xwidget webkit backend for macOS Cocoa. * src/xwidget.c (Fmake_xwidget, xwidget_init_view) (x_draw_xwidget_glyph_string, xwidget_is_web_view) (Fxwidget_webkit_goto_uri, Fxwidget_webkit_zoom, Fxwidget_resize) (Fxwidget_size_request, Fdelete_xwidget_view, xwidget_end_redisplay) (kill_buffer_xwidgets): Add macOS Cocoa specific functions and code with 'NS_IMPL_COCOA' and guard GTK specific functions and code with 'USE_GTK'. (x_draw_xwidget_glyph_string): Handle adjusting xwidget size. * src/xwidget.h (xwidget, xwidget_view): Add macOS Cocoa specific fields with 'NS_IMPL_COCOA' and guard GTK specific fields with USE_GTK.
2020-08-12 10:12:34 +00:00
2021-08-22 23:52:16 +00:00
(define-derived-mode xwidget-webkit-mode special-mode "xwidget-webkit"
"Xwidget webkit view mode."
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(setq buffer-read-only t)
(setq-local bookmark-make-record-function
#'xwidget-webkit-bookmark-make-record)
;; Keep track of [vh]scroll when switching buffers
(image-mode-setup-winprops))
;;; Download, save as file.
(defcustom xwidget-webkit-download-dir "~/Downloads/"
"Directory where download file saved."
:version "28.1"
:type 'file)
(defun xwidget-webkit-save-as-file (url mime-type file-name)
"For XWIDGET webkit, save URL of MIME-TYPE to location specified by user.
FILE-NAME combined with `xwidget-webkit-download-dir' is the default file name
of the prompt when reading. When the file name the user specified is a
directory, URL is saved at the specified directory as FILE-NAME."
(let ((save-name (read-file-name
(format "Save URL `%s' of type `%s' in file/directory: "
url mime-type)
xwidget-webkit-download-dir
(when file-name
(expand-file-name
file-name
xwidget-webkit-download-dir)))))
(if (file-directory-p save-name)
(setq save-name
(expand-file-name (file-name-nondirectory file-name) save-name)))
(setq xwidget-webkit-download-dir (file-name-directory save-name))
(url-copy-file url save-name t)))
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
;;; Bookmarks integration
(defcustom xwidget-webkit-bookmark-jump-new-session nil
"Control bookmark jump to use new session or not.
If non-nil, use a new xwidget webkit session after bookmark jump.
Otherwise, it will use `xwidget-webkit-last-session'.
When you set this variable to nil, consider further customization with
`xwidget-webkit-last-session-buffer'."
:version "28.1"
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
:type 'boolean)
(defun xwidget-webkit-bookmark-make-record ()
"Create bookmark record in webkit xwidget.
See `xwidget-webkit-bookmark-jump-new-session' for whether this
should create a new session or not."
(nconc (bookmark-make-record-default t t)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
`((page . ,(xwidget-webkit-uri (xwidget-webkit-current-session)))
(handler . (lambda (bmk)
(xwidget-webkit-browse-url
(bookmark-prop-get bmk 'page)
xwidget-webkit-bookmark-jump-new-session))))))
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
;;; xwidget webkit session
(defvar xwidget-webkit-last-session-buffer nil)
2016-01-20 00:06:32 +00:00
(defun xwidget-webkit-last-session ()
"Last active webkit, or nil."
(if (buffer-live-p xwidget-webkit-last-session-buffer)
(with-current-buffer xwidget-webkit-last-session-buffer
(xwidget-at (point-min)))
nil))
(defun xwidget-webkit-current-session ()
2016-01-20 00:06:32 +00:00
"Either the webkit in the current buffer, or the last one used.
The latter might be nil."
(or (xwidget-at (point-min)) (xwidget-webkit-last-session)))
(defun xwidget-adjust-size-to-content (xw)
"Resize XW to content."
2016-01-20 00:06:32 +00:00
;; xwidgets doesn't support widgets that have their own opinions about
;; size well, yet this reads the desired size and resizes the Emacs
2016-01-20 00:06:32 +00:00
;; allocated area accordingly.
(let ((size (xwidget-size-request xw)))
(xwidget-resize xw (car size) (cadr size))))
(defvar xwidget-webkit-activeelement-js"
function findactiveelement(doc){
//alert(doc.activeElement.value);
if(doc.activeElement.value != undefined){
return doc.activeElement;
}else{
// recurse over the child documents:
var frames = doc.getElementsByTagName('frame');
for (var i = 0; i < frames.length; i++)
{
var d = frames[i].contentDocument;
var rv = findactiveelement(d);
if(rv != undefined){
return rv;
}
}
}
return undefined;
};
"
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
"Javascript that finds the active element."
2016-01-20 00:06:32 +00:00
;; Yes it's ugly, because:
;; - there is apparently no way to find the active frame other than recursion
;; - the js "for each" construct misbehaved on the "frames" collection
;; - a window with no frameset still has frames.length == 1, but
;; frames[0].document.activeElement != document.activeElement
;;TODO the activeelement type needs to be examined, for iframe, etc.
)
(defun xwidget-webkit-insert-string ()
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
"Insert string into the active field in the current webkit widget."
2016-01-20 00:06:32 +00:00
;; Read out the string in the field first and provide for edit.
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
;; As the prompt differs on JavaScript execution results,
;; the function must handle the prompt itself.
(let ((xww (xwidget-webkit-current-session)))
(xwidget-webkit-execute-script
xww
(concat xwidget-webkit-activeelement-js "
(function () {
var res = findactiveelement(document);
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
if (res)
return [res.value, res.type];
})();")
(lambda (field)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
"Prompt a string for the FIELD and insert in the active input."
(let ((str (pcase field
(`[,val "text"]
(read-string "Text: " val))
(`[,val "password"]
(read-passwd "Password: " nil val))
(`[,val "textarea"]
(xwidget-webkit-begin-edit-textarea xww val)))))
(xwidget-webkit-execute-script
xww
(format "findactiveelement(document).value='%s'" str)))))))
(defvar xwidget-xwbl)
(defun xwidget-webkit-begin-edit-textarea (xw text)
"Start editing of a webkit text area.
XW is the xwidget identifier, TEXT is retrieved from the webkit."
(switch-to-buffer
(generate-new-buffer "textarea"))
Prefer setq-local in most files * lisp/apropos.el (apropos-print): * lisp/buff-menu.el (Buffer-menu-mode): * lisp/calc/calc.el (calc-trail-buffer): * lisp/chistory.el (command-history-mode): * lisp/dabbrev.el: * lisp/dframe.el (dframe-frame-mode): * lisp/doc-view.el (doc-view-presentation-mode): * lisp/ebuff-menu.el (electric-buffer-menu-mode) (electric-buffer-update-highlight): * lisp/edmacro.el (edit-kbd-macro): * lisp/face-remap.el (buffer-face-set, buffer-face-toggle): * lisp/files.el: (find-file-noselect-1, hack-local-variables-confirm) (set-visited-file-name, revert-buffer--default): * lisp/filesets.el (filesets-spawn-external-viewer): * lisp/find-dired.el (find-dired): * lisp/find-lisp.el (find-lisp-find-dired-internal): * lisp/finder.el (finder-mode): * lisp/font-core.el (font-lock-default-function): * lisp/format.el (format-annotate-function): * lisp/help-fns.el (describe-variable): * lisp/help-mode.el (help-mode): * lisp/icomplete.el (icomplete-minibuffer-setup) (icomplete--in-region-setup): * lisp/ido.el (ido-completion-help, ido-tidy): * lisp/international/robin.el (robin-activate): * lisp/leim/quail/hangul.el (hangul-input-method-activate): * lisp/leim/quail/uni-input.el (ucs-input-activate): * lisp/man.el (Man-mode): * lisp/master.el (master-set-slave): * lisp/minibuffer.el (minibuffer-completion-help) (read-file-name-default): * lisp/outline.el (outline-minor-mode): * lisp/pcomplete.el (pcomplete-comint-setup): * lisp/proced.el (proced-mode): * lisp/recentf.el (recentf-edit-list, recentf-open-files-items): * lisp/replace.el (occur-1): * lisp/reveal.el (reveal-mode): * lisp/ruler-mode.el (ruler--save-header-line-format): * lisp/scroll-lock.el (scroll-lock-mode): * lisp/startup.el (normal-top-level, normal-splash-screen): * lisp/strokes.el (strokes-list-strokes): * lisp/thumbs.el (thumbs-insert-image, thumbs-show-thumbs-list): * lisp/tree-widget.el (tree-widget-set-theme): * lisp/window.el (read-buffer-to-switch): * lisp/xwidget.el (xwidget-webkit-begin-edit-textarea): Prefer setq-local.
2020-12-09 08:44:38 +00:00
(setq-local xwidget-xwbl xw)
(insert text))
(defun xwidget-webkit-end-edit-textarea ()
"End editing of a webkit text area."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
(goto-char (point-min))
(while (search-forward "\n" nil t)
(replace-match "\\n" nil t))
(xwidget-webkit-execute-script
xwidget-xwbl
(format "findactiveelement(document).value='%s'"
(buffer-substring (point-min) (point-max))))
;;TODO convert linefeed to \n
)
(defun xwidget-webkit-show-element (xw element-selector)
"Make webkit xwidget XW show a named element ELEMENT-SELECTOR.
The ELEMENT-SELECTOR must be a valid CSS selector. For example,
use this to display an anchor."
(interactive (list (xwidget-webkit-current-session)
2021-08-22 23:52:16 +00:00
(read-string "Element selector: "))
xwidget-webkit-mode)
(xwidget-webkit-execute-script
xw
(format "
(function (query) {
var el = document.querySelector(query);
if (el !== null) {
window.scrollTo(0, el.offsetTop);
}
})('%s');"
element-selector)))
(defun xwidget-webkit-show-named-element (xw element-name)
"Make webkit xwidget XW show a named element ELEMENT-NAME.
For example, use this to display an anchor."
(interactive (list (xwidget-webkit-current-session)
2021-08-22 23:52:16 +00:00
(read-string "Element name: "))
xwidget-webkit-mode)
;; TODO: This needs to be interfaced into browse-url somehow. The
;; tricky part is that we need to do this in two steps: A: load the
;; base url, wait for load signal to arrive B: navigate to the
;; anchor when the base url is finished rendering
(xwidget-webkit-execute-script
xw
(format "
(function (query) {
var el = document.getElementsByName(query)[0];
if (el !== undefined) {
window.scrollTo(0, el.offsetTop);
}
})('%s');"
element-name)))
(defun xwidget-webkit-show-id-element (xw element-id)
"Make webkit xwidget XW show an id-element ELEMENT-ID.
For example, use this to display an anchor."
(interactive (list (xwidget-webkit-current-session)
2021-08-22 23:52:16 +00:00
(read-string "Element id: "))
xwidget-webkit-mode)
(xwidget-webkit-execute-script
xw
(format "
(function (query) {
var el = document.getElementById(query);
if (el !== null) {
window.scrollTo(0, el.offsetTop);
}
})('%s');"
element-id)))
(defun xwidget-webkit-show-id-or-named-element (xw element-id)
"Make webkit xwidget XW show a name or element id ELEMENT-ID.
For example, use this to display an anchor."
(interactive (list (xwidget-webkit-current-session)
2021-08-22 23:52:16 +00:00
(read-string "Name or element id: "))
xwidget-webkit-mode)
(xwidget-webkit-execute-script
xw
(format "
(function (query) {
var el = document.getElementById(query) ||
document.getElementsByName(query)[0];
if (el !== undefined) {
window.scrollTo(0, el.offsetTop);
}
})('%s');"
element-id)))
(defun xwidget-webkit-adjust-size-to-content ()
"Adjust webkit to content size."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
(xwidget-adjust-size-to-content (xwidget-webkit-current-session)))
(defun xwidget-webkit-adjust-size-dispatch ()
"Adjust size according to mode."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
(xwidget-webkit-adjust-size-to-window (xwidget-webkit-current-session))
;; The recenter is intended to correct a visual glitch.
2016-01-20 00:06:32 +00:00
;; It errors out if the buffer isn't visible, but then we don't get
;; the glitch, so silence errors.
(ignore-errors
(recenter-top-bottom)))
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
;; Utility functions
(defun xwidget-window-inside-pixel-width (window)
"Return Emacs WINDOW body width in pixel."
(let ((edges (window-inside-pixel-edges window)))
(- (nth 2 edges) (nth 0 edges))))
(defun xwidget-window-inside-pixel-height (window)
"Return Emacs WINDOW body height in pixel."
(let ((edges (window-inside-pixel-edges window)))
(- (nth 3 edges) (nth 1 edges))))
(defun xwidget-webkit-adjust-size-to-window (xwidget &optional window)
"Adjust the size of the webkit XWIDGET to fit the WINDOW."
(xwidget-resize xwidget
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(xwidget-window-inside-pixel-width window)
(xwidget-window-inside-pixel-height window)))
(defun xwidget-webkit-adjust-size (w h)
"Manually set webkit size to width W, height H."
;; TODO shouldn't be tied to the webkit xwidget
2021-08-22 23:52:16 +00:00
(interactive "nWidth:\nnHeight:\n" xwidget-webkit-mode)
(xwidget-resize (xwidget-webkit-current-session) w h))
(defun xwidget-webkit-fit-width ()
"Adjust width of webkit to window width."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
(xwidget-webkit-adjust-size (- (nth 2 (window-inside-pixel-edges))
(car (window-inside-pixel-edges)))
1000))
(defun xwidget-webkit-auto-adjust-size (window)
"Adjust the size of the webkit widget in the given WINDOW."
(with-current-buffer (window-buffer window)
(when (eq major-mode 'xwidget-webkit-mode)
(let ((xwidget (xwidget-webkit-current-session)))
(xwidget-webkit-adjust-size-to-window xwidget window)))))
(defun xwidget-webkit-adjust-size-in-frame (frame)
"Dynamically adjust webkit widget for all windows of the FRAME."
(walk-windows 'xwidget-webkit-auto-adjust-size 'no-minibuf frame))
(eval-after-load 'xwidget-webkit-mode
(add-to-list 'window-size-change-functions
'xwidget-webkit-adjust-size-in-frame))
(defun xwidget-webkit-new-session (url &optional callback)
"Create a new webkit session buffer with URL."
(let*
((bufname (generate-new-buffer-name "*xwidget-webkit*"))
(callback (or callback #'xwidget-webkit-callback))
xw)
(setq xwidget-webkit-last-session-buffer (switch-to-buffer
(get-buffer-create bufname)))
;; The xwidget id is stored in a text property, so we need to have
;; at least character in this buffer.
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
;; Insert invisible url, good default for next `g' to browse url.
(let ((start (point)))
(insert url)
(put-text-property start (+ start (length url)) 'invisible t)
(setq xw (xwidget-insert
start 'webkit bufname
(xwidget-window-inside-pixel-width (selected-window))
(xwidget-window-inside-pixel-height (selected-window)))))
(xwidget-put xw 'callback callback)
(xwidget-webkit-mode)
(xwidget-webkit-goto-uri (xwidget-webkit-last-session) url)))
(defun xwidget-webkit-goto-url (url)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
"Goto URL with xwidget webkit."
(if (xwidget-webkit-current-session)
(progn
(xwidget-webkit-goto-uri (xwidget-webkit-current-session) url))
(xwidget-webkit-new-session url)))
(defun xwidget-webkit-back ()
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
"Go back to previous URL in xwidget webkit buffer."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(xwidget-webkit-goto-history (xwidget-webkit-current-session) -1))
(defun xwidget-webkit-forward ()
"Go forward in history."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(xwidget-webkit-goto-history (xwidget-webkit-current-session) 1))
(defun xwidget-webkit-reload ()
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
"Reload current URL."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(xwidget-webkit-goto-history (xwidget-webkit-current-session) 0))
(defun xwidget-webkit-current-url ()
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
"Display the current xwidget webkit URL and place it on the `kill-ring'."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(let ((url (xwidget-webkit-uri (xwidget-webkit-current-session))))
(message "URL: %s" (kill-new (or url "")))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun xwidget-webkit-get-selection (proc)
"Get the webkit selection and pass it to PROC."
(xwidget-webkit-execute-script
(xwidget-webkit-current-session)
"window.getSelection().toString();"
proc))
(defun xwidget-webkit-copy-selection-as-kill ()
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
"Get the webkit selection and put it on the `kill-ring'."
2021-08-22 23:52:16 +00:00
(interactive nil xwidget-webkit-mode)
Add utility functions and new xwidget commands Co-authored-by: Jaesup Kwak <veshboo@gmail.com> * etc/NEWS: Announce new functions and options. * lisp/xwidget.el (xwidget): New defgroup. (xwidget-webkit-mode-map): Add new keybindings. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down) (xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Add optional argument to specify specific amounts to scroll down. (xwidget-webkit-scroll-up-line, xwidget-webkit-scroll-down-line): New functions. (xwidget-webkit-scroll-bottom): Fix function to scroll to the bottom of the document. (xwidget-webkit-callback): Use new function to update buffer title even when Javascript is disabled. (xwidget-webkit-bookmark-jump-new-session): New variable. (xwidget-webkit-bookmark-make-record): Modify to use xwidget-webkit to open bookmark that is created in xwidget-webkit. (xwidget-webkit-insert-string): Fix Javascript snippet to not throw Javsscript exceptions. (xwidget-webkit-inside-pixel-width) (xwidget-window-inside-pixel-height): New functions. (xwidget-webkit-adjust-size-to-window): Use new functions. (xwidget-webkit-new-session): Insert invisible URL instead of an empty string to achieve better default behavior. (xwidget-webkit-back, xwidget-webkit-forward, xwidget-webkit-reload) (xwidget-webkit-current-url): Use new functions to enable scrolling even when Javascript is disabled. (xwidget-webkit-copy-selection-as-kill): Remove unnecessary lambda. * src/nsxwidget.h src/nsxwidget.m (nsxwidget_webkit_uri) (nsxwidget_webkit_title, nsxwidget_webkit_goto_history): Add new functions. * src/xwidget.c (Fxwidget_webkit_uri, Fxwidget_webkit_title) (Fxwidget_webkit_goto_history): Add new functions. (syms_of_xwidget): Define new functions.
2020-08-12 10:34:29 +00:00
(xwidget-webkit-get-selection #'kill-new))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2016-01-20 00:06:32 +00:00
;; Xwidget plist management (similar to the process plist functions)
(defun xwidget-get (xwidget propname)
"Get an xwidget's property value.
XWIDGET is an xwidget, PROPNAME a property.
Returns the last value stored with `xwidget-put'."
(plist-get (xwidget-plist xwidget) propname))
(defun xwidget-put (xwidget propname value)
"Set an xwidget's property value.
XWIDGET is an xwidget, PROPNAME a property to be set to specified VALUE.
You can retrieve the value with `xwidget-get'."
(set-xwidget-plist xwidget
(plist-put (xwidget-plist xwidget) propname value)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar xwidget-view-list) ; xwidget.c
(defvar xwidget-list) ; xwidget.c
(defun xwidget-delete-zombies ()
"Helper for `xwidget-cleanup'."
(dolist (xwidget-view xwidget-view-list)
(when (or (not (window-live-p (xwidget-view-window xwidget-view)))
(not (memq (xwidget-view-model xwidget-view)
xwidget-list)))
(delete-xwidget-view xwidget-view))))
(defun xwidget-cleanup ()
"Delete zombie xwidgets."
;; During development it was sometimes easy to wind up with zombie
;; xwidget instances.
;; This function tries to implement a workaround should it occur again.
(interactive)
2016-01-20 00:06:32 +00:00
;; Kill xviews that should have been deleted but still linger.
(xwidget-delete-zombies)
;; Redraw display otherwise ghost of zombies will remain to haunt the screen
(redraw-display))
(defun xwidget-kill-buffer-query-function ()
2016-01-20 00:06:32 +00:00
"Ask before killing a buffer that has xwidgets."
(let ((xwidgets (get-buffer-xwidgets (current-buffer))))
(or (not xwidgets)
(not (memq t (mapcar #'xwidget-query-on-exit-flag xwidgets)))
(yes-or-no-p
(format "Buffer %S has xwidgets; kill it? " (buffer-name))))))
(when (featurep 'xwidget-internal)
(add-hook 'kill-buffer-query-functions #'xwidget-kill-buffer-query-function)
;; This would have felt better in C, but this seems to work well in
;; practice though.
(add-hook 'window-configuration-change-hook #'xwidget-delete-zombies))
(provide 'xwidget)
;;; xwidget.el ends here