From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH v3] Add xwidget webkit support for macOS Cocoa Date: Wed, 05 Jun 2019 09:55:24 -0400 Message-ID: References: <20190605031823.51015-1-pcr910303@icloud.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="64639"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 05 15:56:36 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYWP4-000GfO-Qd for ged-emacs-devel@m.gmane.org; Wed, 05 Jun 2019 15:56:34 +0200 Original-Received: from localhost ([127.0.0.1]:42947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYWP3-00024K-Qo for ged-emacs-devel@m.gmane.org; Wed, 05 Jun 2019 09:56:33 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYWOR-000244-Dx for emacs-devel@gnu.org; Wed, 05 Jun 2019 09:55:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYWOP-0005r1-E6 for emacs-devel@gnu.org; Wed, 05 Jun 2019 09:55:55 -0400 Original-Received: from [195.159.176.226] (port=48612 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYWOJ-0005KS-Mq for emacs-devel@gnu.org; Wed, 05 Jun 2019 09:55:48 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hYWO6-000FW8-UV for emacs-devel@gnu.org; Wed, 05 Jun 2019 15:55:34 +0200 X-Injected-Via-Gmane: http://gmane.org/ Cancel-Lock: sha1:K7SQ5jo+UowXJEy7ToHkvsTige4= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:237259 Archived-At: Thanks, looks good for the part I can review. See additional nitpicks in case nobody comes up with more substantial comments. > +(defun xwidget-webkit-split-below () > + "Clone current URL into a new widget place in new window below. Great. > +(defun xwidget-webkit-split-right () > + "Get the URL of current session, then browse to the URL \ > +in `split-window-right' with a new xwidget webkit session." You missed this one, tho. > + (format "window.scrollBy(0, %d);" > + (or n (xwidget-window-inside-pixel-height (selected-window)))))) Great. > - "window.scrollBy(0, -50);")) > + (cond ((null n) > + (format "window.scrollBy(0, %d);" > + (- (xwidget-window-inside-pixel-height (selected-window))))) > + (t (format "window.scrollBy(0, %d);" (- n)))))) You missed this one, tho. > +(defcustom xwidget-webkit-scroll-line-height 50 > + "Default line height in pixels for scroll xwidget webkit." > + :type 'integer > + :group 'xwidget) Those `:group 'xwidget` are redundant since it defaults to the last `defgroup` in the buffer anyway. > + ;; TODO: Response handling other than download. > + ((eq xwidget-event-type 'response-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))) BTW, where does the "response-callback" name come from? According to the above code, this is used in the case of downloads, so why is it not called "download-callback"? > +(defun xwidget-webkit-save-as-file (url mime-type &optional file-name) > + "For XWIDGET webkit, save URL resource of MIME-TYPE as FILE-NAME." > + (let ((save-name (read-file-name > + (format "Save '%s' file as: " mime-type) > + xwidget-webkit-download-dir > + (expand-file-name > + file-name > + xwidget-webkit-download-dir) nil file-name))) Again, please don't pass `file-name` as INITIAL arg: leave it nil. > - `((page . ,(xwidget-webkit-current-url)) > - (handler . (lambda (bmk) (browse-url > - (bookmark-prop-get bmk 'page))))))) > - > + `((page . ,(xwidget-webkit-current-url)) > + (handler . (lambda (bmk) > + (browse-url > + (bookmark-prop-get bmk 'filename) > + xwidget-webkit-bookmark-jump-new-session) > + (switch-to-buffer > + (xwidget-buffer (xwidget-webkit-last-session)))))))) I see you reverted to `page`, which is fine, but then the (bookmark-prop-get bmk 'filename) needs to be changed back to (bookmark-prop-get bmk 'page) as well, shouldn't it? Also, I don't really understand the new code: - how do we know that `browse-url` will use the xwidget browser rather than any other? I think we should either call `browse-url` and presume it can be *any* browser, or call xwidget-webkit-browse-url instead. - Why do we need the switch-to-buffer? Why not rely on (xwidget-webkit-)browse-url to Do The Right Thing? - switch-to-buffer fails miserably in configs such as mine (separate minibuffer frame and dedicated windows), so better avoid it in Elisp and use things like pop-to-buffer or pop-to-buffer-same-window. > + ;; 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 1 'webkit bufname Please use `start` rather than 1. Stefan