emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1657e0f: Add command to browse xwidget history


From: Po Lu
Subject: master 1657e0f: Add command to browse xwidget history
Date: Tue, 16 Nov 2021 04:40:02 -0500 (EST)

branch: master
commit 1657e0fb177d6a107479306e17ffbb9016a9a40c
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Add command to browse xwidget history
    
    * doc/emacs/misc.texi (Embedded WebKit Widgets)
    * etc/NEWS: Document `xwidget-webkit-browse-history'.
    
    * lisp/xwidget.el (xwidget-webkit-mode-map): Bind "H" to
    xwidget-webkit-browse-history.
    (xwidget-webkit-import-widget): Set last session buffer correctly.
    (xwidget-webkit-browse-history): New command.
    (xwidget-webkit-history--session): New variable.
    
    (xwidget-webkit-history--insert-item)
    (xwidget-webkit-history-select-item)
    (xwidget-webkit-history-reload): New functions.
    
    (xwidget-webkit-history-mode): New major mode.
---
 doc/emacs/misc.texi |  8 ++++++
 etc/NEWS            |  5 ++++
 lisp/xwidget.el     | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+)

diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index 3d423d7..1f2c852 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -3011,6 +3011,14 @@ the WebKit widget to display the next search result, 
while typing
 
 To leave incremental search, you can type @kbd{C-g}.
 
+@findex xwidget-webkit-browse-history
+@cindex history of webkit buffers
+  The command @code{xwidget-webkit-browse-history} displays a buffer
+containing a list of pages previously loaded by the current WebKit
+buffer, and lets you navigate to those pages by hitting @kbd{RET}.
+
+It is bound to @kbd{H}.
+
 @node Browse-URL
 @subsection  Following URLs
 @cindex World Wide Web
diff --git a/etc/NEWS b/etc/NEWS
index ce4c86b..80be6c0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -498,6 +498,11 @@ This mode acts similarly to incremental search, and allows 
to search
 the contents of a WebKit widget.  In xwidget-webkit mode, it is bound
 to 'C-s' and 'C-r'.
 
++++
+*** New command 'xwidget-webkit-browse-history'.
+This command displays a buffer containing the page load history of
+the current WebKit widget, and allows you to navigate it.
+
 ---
 *** On X11, the WebKit inspector is now available inside xwidgets.
 To access the inspector, right click on the widget and select "Inspect
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index a587fe8..c1d0cd6 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -55,6 +55,7 @@
 (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))
+(declare-function xwidget-webkit-back-forward-list "xwidget.c" (xwidget 
&optional limit))
 
 (defgroup xwidget nil
   "Displaying native widgets in Emacs buffers."
@@ -194,6 +195,7 @@ for the actual events that will be sent."
     (define-key map "e" 'xwidget-webkit-edit-mode)
     (define-key map "\C-r" 'xwidget-webkit-isearch-mode)
     (define-key map "\C-s" 'xwidget-webkit-isearch-mode)
+    (define-key map "H" 'xwidget-webkit-browse-history)
 
     ;;similar to image mode bindings
     (define-key map (kbd "SPC")                 'xwidget-webkit-scroll-up)
@@ -228,6 +230,7 @@ for the actual events that will be sent."
         ["Back" xwidget-webkit-back t]
         ["Forward" xwidget-webkit-forward t]
         ["Reload" xwidget-webkit-reload t]
+        ["History" xwidget-webkit-browse-history t]
         ["Insert String" xwidget-webkit-insert-string
          :active t
          :help "Insert a string into the currently active field"]
@@ -396,6 +399,9 @@ XWIDGET instance, XWIDGET-EVENT-TYPE depends on the 
originating xwidget."
              (when (or (string-equal (nth 3 last-input-event)
                                      "load-finished")
                        (> (length title) 0))
+               (when-let ((buffer (get-buffer "*Xwidget WebKit History*")))
+                 (with-current-buffer buffer
+                   (revert-buffer)))
                (with-current-buffer (xwidget-buffer xwidget)
                  (setq xwidget-webkit--title title)
                  (force-mode-line-update)
@@ -775,6 +781,7 @@ Return the buffer."
          (callback #'xwidget-webkit-callback)
          (buffer (get-buffer-create bufname)))
     (with-current-buffer buffer
+      (setq xwidget-webkit-last-session-buffer buffer)
       (save-excursion
         (erase-buffer)
         (insert ".")
@@ -821,6 +828,15 @@ Return the buffer."
   (let ((url (xwidget-webkit-uri (xwidget-webkit-current-session))))
     (message "URL: %s" (kill-new (or url "")))))
 
+(defun xwidget-webkit-browse-history ()
+  "Display a buffer containing the history of page loads."
+  (interactive)
+  (setq xwidget-webkit-last-session-buffer (current-buffer))
+  (let ((buffer (get-buffer-create "*Xwidget WebKit History*")))
+    (with-current-buffer buffer
+      (xwidget-webkit-history-mode))
+    (display-buffer buffer)))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun xwidget-webkit-get-selection (proc)
   "Get the webkit selection and pass it to PROC."
@@ -1059,6 +1075,66 @@ Press 
\\<xwidget-webkit-isearch-mode-map>\\[xwidget-webkit-isearch-exit] to exit
         (concat xwidget-webkit-isearch--string
                 (current-kill 0)))
   (xwidget-webkit-isearch--update))
+
+(defvar-local xwidget-webkit-history--session nil
+  "The xwidget this history buffer controls.")
+
+(define-button-type 'xwidget-webkit-history 'action 
#'xwidget-webkit-history-select-item)
+
+(defun xwidget-webkit-history--insert-item (item)
+  "Insert specified ITEM into the current buffer."
+  (let ((idx (car item))
+        (title (cadr item))
+        (uri (caddr item)))
+    (push (list idx (vector (list (number-to-string idx)
+                                  :type 'xwidget-webkit-history)
+                            (list title :type 'xwidget-webkit-history)
+                            (list uri :type 'xwidget-webkit-history)))
+          tabulated-list-entries)))
+
+(defun xwidget-webkit-history-select-item (pos)
+  "Navigate to the history item underneath POS."
+  (interactive "P")
+  (let ((id (tabulated-list-get-id pos)))
+    (xwidget-webkit-goto-history xwidget-webkit-history--session id))
+  (xwidget-webkit-history-reload))
+
+(defun xwidget-webkit-history-reload (&rest ignored)
+  "Reload the current history buffer."
+  (interactive)
+  (setq tabulated-list-entries nil)
+  (let* ((back-forward-list
+          (xwidget-webkit-back-forward-list xwidget-webkit-history--session))
+         (back-list (car back-forward-list))
+         (here (cadr back-forward-list))
+         (forward-list (caddr back-forward-list)))
+    (mapc #'xwidget-webkit-history--insert-item (nreverse forward-list))
+    (xwidget-webkit-history--insert-item here)
+    (mapc #'xwidget-webkit-history--insert-item back-list)
+    (tabulated-list-print t nil)
+    (goto-char (point-min))
+    (let ((position (line-beginning-position (1+ (length back-list)))))
+      (goto-char position)
+      (setq-local overlay-arrow-position (make-marker))
+      (set-marker overlay-arrow-position position))))
+
+(define-derived-mode xwidget-webkit-history-mode tabulated-list-mode
+  "Xwidget Webkit History"
+  "Major mode for browsing the history of an Xwidget Webkit buffer.
+Each line describes an entry in history."
+  (setq truncate-lines t)
+  (setq buffer-read-only t)
+  (setq tabulated-list-format [("Index" 10 nil)
+                               ("Title" 50 nil)
+                               ("URL" 100 nil)])
+  (setq tabulated-list-entries nil)
+  (setq xwidget-webkit-history--session (xwidget-webkit-current-session))
+  (xwidget-webkit-history-reload)
+  (setq-local revert-buffer-function #'xwidget-webkit-history-reload)
+  (tabulated-list-init-header))
+
+(define-key xwidget-webkit-history-mode-map (kbd "RET")
+  #'xwidget-webkit-history-select-item)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defvar xwidget-view-list)              ; xwidget.c



reply via email to

[Prev in Thread] Current Thread [Next in Thread]