all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] xwidget.el: limit buffer-name flicker in mode-line.
@ 2021-11-08  6:23 tumashu
  2021-11-08  6:27 ` Po Lu
  0 siblings, 1 reply; 8+ messages in thread
From: tumashu @ 2021-11-08  6:23 UTC (permalink / raw)
  To: emacs-devel@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #1.2: Type: text/html, Size: 111 bytes --]

[-- Attachment #2: 0001-xwidget.el-limit-buffer-name-flicker-in-mode-line.patch --]
[-- Type: application/octet-stream, Size: 6545 bytes --]

From e2ccea178782fdafe70c812eabf6ad44704ded1c Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@163.com>
Date: Mon, 8 Nov 2021 14:14:15 +0800
Subject: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.

* lisp/xwidget.el (xwidget-webkit-buffer-name-prefix): New variable.
(xwidget-webkit-callback): with-current-buffer only after get title,
which can limit buffer-name change in mode-line.
(xwidget-webkit-new-session, xwidget-webkit-import-widget): Use
current buffer to generate a temp xwidget-webkit buffer.
---
 lisp/xwidget.el | 85 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 53 insertions(+), 32 deletions(-)

diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index 1d91e863e4..5efda3db45 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -89,6 +89,9 @@ xwidget-at
 (require 'seq)
 (require 'url-handlers)
 
+(defvar xwidget-webkit-buffer-name-prefix "* xwidget-webkit "
+  "Buffer name prefix used by xwidget-webkit buffer.")
+
 (defvar-local xwidget-webkit--title ""
   "The title of the WebKit widget, used for the header line.")
 
@@ -345,32 +348,36 @@ xwidget-webkit-callback
   (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)
-             (let ((title (xwidget-webkit-title xwidget)))
-               (setq xwidget-webkit--title title)
-               (force-mode-line-update)
-               (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))))))
+    (cond ((eq xwidget-event-type 'load-changed)
+           (let ((title (xwidget-webkit-title xwidget)))
+             ;; This funciton will be called multi times, so only
+             ;; change buffer name when get a valid title.  this can
+             ;; limit buffer-name flicker in mode-line.
+             (when (> (length title) 0)
+               (with-current-buffer (xwidget-buffer xwidget)
+                 (setq xwidget-webkit--title title)
+                 (force-mode-line-update)
+                 (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 (concat xwidget-webkit-buffer-name-prefix 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)
 (when (memq window-system '(mac ns))
@@ -682,11 +689,16 @@ 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))
-       (current-session (xwidget-webkit-current-session))
-       xw)
+  (let* ((bufname
+          ;; Generate a temp-name based on current buffer name. it
+          ;; will be renamed by `xwidget-webkit-callback' in the
+          ;; future.  This approach can limit flicker of buffer-name
+          ;; in mode-line.  .
+          (concat xwidget-webkit-buffer-name-prefix
+                  (generate-new-buffer-name (buffer-name))))
+         (callback (or callback #'xwidget-webkit-callback))
+         (current-session (xwidget-webkit-current-session))
+         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
@@ -707,7 +719,16 @@ xwidget-webkit-new-session
 (defun xwidget-webkit-import-widget (xwidget)
   "Create a new webkit session buffer from XWIDGET, an existing xwidget.
 Return the buffer."
-  (let* ((bufname (generate-new-buffer-name "*xwidget-webkit*"))
+  (let* ((bufname
+          ;; Generate a temp-name based on current buffer name.  it
+          ;; will be renamed by `xwidget-webkit-callback' in the
+          ;; future.  This approach can limit flicker of buffer-name
+          ;; in mode-line.
+          (if (string-prefix-p xwidget-webkit-buffer-name-prefix
+                               (buffer-name))
+              (generate-new-buffer-name (buffer-name))
+            (concat xwidget-webkit-buffer-name-prefix
+                    (generate-new-buffer-name (buffer-name)))))
          (callback #'xwidget-webkit-callback)
          (buffer (get-buffer-create bufname)))
     (with-current-buffer buffer
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.
  2021-11-08  6:23 [PATCH] xwidget.el: limit buffer-name flicker in mode-line tumashu
@ 2021-11-08  6:27 ` Po Lu
  2021-11-08  6:32   ` tumashu
  0 siblings, 1 reply; 8+ messages in thread
From: Po Lu @ 2021-11-08  6:27 UTC (permalink / raw)
  To: tumashu; +Cc: emacs-devel@gnu.org

Looks good to me, but one question:

> +(defvar xwidget-webkit-buffer-name-prefix "* xwidget-webkit "
> +  "Buffer name prefix used by xwidget-webkit buffer.")

Shouldn't this be a `defcustom'?  It seems like an option a user might
want to customize.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re:Re: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.
  2021-11-08  6:27 ` Po Lu
@ 2021-11-08  6:32   ` tumashu
  2021-11-08  6:40     ` Po Lu
  0 siblings, 1 reply; 8+ messages in thread
From: tumashu @ 2021-11-08  6:32 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 116 bytes --]


>Shouldn't this be a `defcustom'?  It seems like an option a user might
>want to customize.

good idea,  updated.


[-- Attachment #2: 0001-xwidget.el-limit-buffer-name-flicker-in-mode-line.patch --]
[-- Type: application/octet-stream, Size: 6567 bytes --]

From 2ee45784e80362206f7a0401cc04f816898447ff Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@163.com>
Date: Mon, 8 Nov 2021 14:14:15 +0800
Subject: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.

* lisp/xwidget.el (xwidget-webkit-buffer-name-prefix): New variable.
(xwidget-webkit-callback): with-current-buffer only after get title,
which can limit buffer-name change in mode-line.
(xwidget-webkit-new-session, xwidget-webkit-import-widget): Use
current buffer to generate a temp xwidget-webkit buffer.
---
 lisp/xwidget.el | 86 +++++++++++++++++++++++++++++++------------------
 1 file changed, 54 insertions(+), 32 deletions(-)

diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index 1d91e863e4..c376c817f3 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -89,6 +89,10 @@ xwidget-at
 (require 'seq)
 (require 'url-handlers)
 
+(defcustom xwidget-webkit-buffer-name-prefix "* xwidget-webkit: "
+  "Buffer name prefix used by xwidget-webkit buffer."
+  :type 'string)
+
 (defvar-local xwidget-webkit--title ""
   "The title of the WebKit widget, used for the header line.")
 
@@ -345,32 +349,36 @@ xwidget-webkit-callback
   (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)
-             (let ((title (xwidget-webkit-title xwidget)))
-               (setq xwidget-webkit--title title)
-               (force-mode-line-update)
-               (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))))))
+    (cond ((eq xwidget-event-type 'load-changed)
+           (let ((title (xwidget-webkit-title xwidget)))
+             ;; This funciton will be called multi times, so only
+             ;; change buffer name when get a valid title.  this can
+             ;; limit buffer-name flicker in mode-line.
+             (when (> (length title) 0)
+               (with-current-buffer (xwidget-buffer xwidget)
+                 (setq xwidget-webkit--title title)
+                 (force-mode-line-update)
+                 (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 (concat xwidget-webkit-buffer-name-prefix 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)
 (when (memq window-system '(mac ns))
@@ -682,11 +690,16 @@ 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))
-       (current-session (xwidget-webkit-current-session))
-       xw)
+  (let* ((bufname
+          ;; Generate a temp-name based on current buffer name. it
+          ;; will be renamed by `xwidget-webkit-callback' in the
+          ;; future.  This approach can limit flicker of buffer-name
+          ;; in mode-line.  .
+          (concat xwidget-webkit-buffer-name-prefix
+                  (generate-new-buffer-name (buffer-name))))
+         (callback (or callback #'xwidget-webkit-callback))
+         (current-session (xwidget-webkit-current-session))
+         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
@@ -707,7 +720,16 @@ xwidget-webkit-new-session
 (defun xwidget-webkit-import-widget (xwidget)
   "Create a new webkit session buffer from XWIDGET, an existing xwidget.
 Return the buffer."
-  (let* ((bufname (generate-new-buffer-name "*xwidget-webkit*"))
+  (let* ((bufname
+          ;; Generate a temp-name based on current buffer name.  it
+          ;; will be renamed by `xwidget-webkit-callback' in the
+          ;; future.  This approach can limit flicker of buffer-name
+          ;; in mode-line.
+          (if (string-prefix-p xwidget-webkit-buffer-name-prefix
+                               (buffer-name))
+              (generate-new-buffer-name (buffer-name))
+            (concat xwidget-webkit-buffer-name-prefix
+                    (generate-new-buffer-name (buffer-name)))))
          (callback #'xwidget-webkit-callback)
          (buffer (get-buffer-create bufname)))
     (with-current-buffer buffer
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.
  2021-11-08  6:32   ` tumashu
@ 2021-11-08  6:40     ` Po Lu
  2021-11-08  6:54       ` tumashu
  0 siblings, 1 reply; 8+ messages in thread
From: Po Lu @ 2021-11-08  6:40 UTC (permalink / raw)
  To: tumashu; +Cc: emacs-devel@gnu.org

tumashu  <tumashu@163.com> writes:

> good idea,  updated.

I think it would be a good idea to have a custom group for
xwidget-webkit.

Thanks.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re:Re: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.
  2021-11-08  6:40     ` Po Lu
@ 2021-11-08  6:54       ` tumashu
  2021-11-08  6:59         ` Po Lu
  0 siblings, 1 reply; 8+ messages in thread
From: tumashu @ 2021-11-08  6:54 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel@gnu.org

















At 2021-11-08 14:40:48, "Po Lu" <luangruo@yahoo.com> wrote:
>tumashu  <tumashu@163.com> writes:
>
>> good idea,  updated.
>
>I think it would be a good idea to have a custom group for
>xwidget-webkit.

Do you mean create a new group like below?

(defgroup xwidget-webkit nil
  "Displaying webkit xwidgets in Emacs buffers."
  :group 'xwidget)

>
>Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.
  2021-11-08  6:54       ` tumashu
@ 2021-11-08  6:59         ` Po Lu
  2021-11-08  7:06           ` tumashu
  0 siblings, 1 reply; 8+ messages in thread
From: Po Lu @ 2021-11-08  6:59 UTC (permalink / raw)
  To: tumashu; +Cc: emacs-devel@gnu.org

tumashu  <tumashu@163.com> writes:

> Do you mean create a new group like below?
>
> (defgroup xwidget-webkit nil
>   "Displaying webkit xwidgets in Emacs buffers."
>   :group 'xwidget)
>

Something closer to:

  (defgroup xwidget-webkit nil
    "Displaying webkit xwidgets in Emacs buffers."
    :version "29.1"
    :group 'web
    :prefix "xwidget-webkit-")

Thanks.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re:Re: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.
  2021-11-08  6:59         ` Po Lu
@ 2021-11-08  7:06           ` tumashu
  2021-11-09  3:53             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: tumashu @ 2021-11-08  7:06 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 199 bytes --]



>Something closer to:
>
>  (defgroup xwidget-webkit nil
>    "Displaying webkit xwidgets in Emacs buffers."
>    :version "29.1"
>    :group 'web
>    :prefix "xwidget-webkit-")
>

added

>Thanks.

[-- Attachment #2: 0001-xwidget.el-limit-buffer-name-flicker-in-mode-line.patch --]
[-- Type: application/octet-stream, Size: 6706 bytes --]

From 00f9022d71741efc481d86011aece1f148c525e5 Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@163.com>
Date: Mon, 8 Nov 2021 14:14:15 +0800
Subject: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.

* lisp/xwidget.el (xwidget-webkit-buffer-name-prefix): New variable.
(xwidget-webkit-callback): with-current-buffer only after get title,
which can limit buffer-name change in mode-line.
(xwidget-webkit-new-session, xwidget-webkit-import-widget): Use
current buffer to generate a temp xwidget-webkit buffer.
---
 lisp/xwidget.el | 92 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 60 insertions(+), 32 deletions(-)

diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index 1d91e863e4..88d4178553 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -89,6 +89,16 @@ xwidget-at
 (require 'seq)
 (require 'url-handlers)
 
+(defgroup xwidget-webkit nil
+  "Displaying webkit xwidgets in Emacs buffers."
+  :version "29.1"
+  :group 'web
+  :prefix "xwidget-webkit-")
+
+(defcustom xwidget-webkit-buffer-name-prefix "* xwidget-webkit: "
+  "Buffer name prefix used by xwidget-webkit buffer."
+  :type 'string)
+
 (defvar-local xwidget-webkit--title ""
   "The title of the WebKit widget, used for the header line.")
 
@@ -345,32 +355,36 @@ xwidget-webkit-callback
   (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)
-             (let ((title (xwidget-webkit-title xwidget)))
-               (setq xwidget-webkit--title title)
-               (force-mode-line-update)
-               (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))))))
+    (cond ((eq xwidget-event-type 'load-changed)
+           (let ((title (xwidget-webkit-title xwidget)))
+             ;; This funciton will be called multi times, so only
+             ;; change buffer name when get a valid title. this can
+             ;; limit buffer-name flicker in mode-line.
+             (when (> (length title) 0)
+               (with-current-buffer (xwidget-buffer xwidget)
+                 (setq xwidget-webkit--title title)
+                 (force-mode-line-update)
+                 (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 (concat xwidget-webkit-buffer-name-prefix 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)
 (when (memq window-system '(mac ns))
@@ -682,11 +696,16 @@ 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))
-       (current-session (xwidget-webkit-current-session))
-       xw)
+  (let* ((bufname
+          ;; Generate a temp-name based on current buffer name. it
+          ;; will be renamed by `xwidget-webkit-callback' in the
+          ;; future. This approach can limit flicker of buffer-name in
+          ;; mode-line.
+          (concat xwidget-webkit-buffer-name-prefix
+                  (generate-new-buffer-name (buffer-name))))
+         (callback (or callback #'xwidget-webkit-callback))
+         (current-session (xwidget-webkit-current-session))
+         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
@@ -707,7 +726,16 @@ xwidget-webkit-new-session
 (defun xwidget-webkit-import-widget (xwidget)
   "Create a new webkit session buffer from XWIDGET, an existing xwidget.
 Return the buffer."
-  (let* ((bufname (generate-new-buffer-name "*xwidget-webkit*"))
+  (let* ((bufname
+          ;; Generate a temp-name based on current buffer name. it
+          ;; will be renamed by `xwidget-webkit-callback' in the
+          ;; future. This approach can limit flicker of buffer-name in
+          ;; mode-line.
+          (if (string-prefix-p xwidget-webkit-buffer-name-prefix
+                               (buffer-name))
+              (generate-new-buffer-name (buffer-name))
+            (concat xwidget-webkit-buffer-name-prefix
+                    (generate-new-buffer-name (buffer-name)))))
          (callback #'xwidget-webkit-callback)
          (buffer (get-buffer-create bufname)))
     (with-current-buffer buffer
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] xwidget.el: limit buffer-name flicker in mode-line.
  2021-11-08  7:06           ` tumashu
@ 2021-11-09  3:53             ` Lars Ingebrigtsen
  0 siblings, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-09  3:53 UTC (permalink / raw)
  To: tumashu; +Cc: Po Lu, emacs-devel@gnu.org

tumashu  <tumashu@163.com> writes:

>>  (defgroup xwidget-webkit nil
>>    "Displaying webkit xwidgets in Emacs buffers."
>>    :version "29.1"
>>    :group 'web
>>    :prefix "xwidget-webkit-")
>>
>
> added

Thanks; pushed to Emacs 29 (with some extremely minor changes).

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-11-09  3:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-08  6:23 [PATCH] xwidget.el: limit buffer-name flicker in mode-line tumashu
2021-11-08  6:27 ` Po Lu
2021-11-08  6:32   ` tumashu
2021-11-08  6:40     ` Po Lu
2021-11-08  6:54       ` tumashu
2021-11-08  6:59         ` Po Lu
2021-11-08  7:06           ` tumashu
2021-11-09  3:53             ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.