From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EBykIGZolGDubgEAgWs5BA (envelope-from ) for ; Fri, 07 May 2021 00:06:30 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id GLpcHGZolGDnWQAA1q6Kng (envelope-from ) for ; Thu, 06 May 2021 22:06:30 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 814278855 for ; Fri, 7 May 2021 00:06:29 +0200 (CEST) Received: from localhost ([::1]:51094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lem8a-0007Up-Fk for larch@yhetil.org; Thu, 06 May 2021 18:06:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lem8A-0007UM-HR for emacs-orgmode@gnu.org; Thu, 06 May 2021 18:06:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56707) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lem8A-0003fE-9r for emacs-orgmode@gnu.org; Thu, 06 May 2021 18:06:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lem8A-0000uu-3Z for emacs-orgmode@gnu.org; Thu, 06 May 2021 18:06:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#47088: org-w3m: handle w3m-image link information Resent-From: Boruch Baum Original-Sender: "Debbugs-submit" Resent-CC: emacs-orgmode@gnu.org Resent-Date: Thu, 06 May 2021 22:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47088 X-GNU-PR-Package: org-mode X-GNU-PR-Keywords: To: Bastien Received: via spool by 47088-submit@debbugs.gnu.org id=B47088.16203387283505 (code B ref 47088); Thu, 06 May 2021 22:06:02 +0000 Received: (at 47088) by debbugs.gnu.org; 6 May 2021 22:05:28 +0000 Received: from localhost ([127.0.0.1]:40018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lem7c-0000uS-0O for submit@debbugs.gnu.org; Thu, 06 May 2021 18:05:28 -0400 Received: from mout.gmx.net ([212.227.17.21]:38731) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lem7Z-0000uL-Ct for 47088@debbugs.gnu.org; Thu, 06 May 2021 18:05:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1620338719; bh=WoqSRn1eMV0of02wkNo5z9nVchM4aSnSA03sAIROwTI=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=NvooYobT1BzUSp0vQryHy6HQ/ZbuArAEHcY+5eIxVIzAkyyKv1VdWrXgk1qFTtsu1 GxYq22eqT18RD/68mkmA2lp6XcCQdRVn2jVE25RC6K6JLi2wlW+u50ksnQ8nKwfwHg 2qCkOx459jHgAjbg1m1puVi9qvI+z7W6OmJjt8JM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from E15-2016.optimum.net ([70.19.86.82]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1N3bX1-1lWq5d2Uxn-010aZh; Fri, 07 May 2021 00:05:18 +0200 Date: Thu, 6 May 2021 18:05:15 -0400 From: Boruch Baum Message-ID: <20210506220515.fr7ebcvvtb3jj5yp@E15-2016.optimum.net> References: <20210312062614.usandeuwplmn7fu3@E15-2016.optimum.net> <87zgx9ioi7.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="7bpnx4ijob5a46ui" Content-Disposition: inline In-Reply-To: <87zgx9ioi7.fsf@gnu.org> User-Agent: NeoMutt/20180716 X-Provags-ID: V03:K1:rPMJcZ4oH+gnq8VsL6E4JMVXcjiI6jqrcuJQwuzdRf97Ix80Lx8 fRXK585NSzHUay/suZY0MAADTJacKyURRuvJVH+kxf92th8iuOjLSbMVe7R4UXMOuDqUdrS togpjXbfyx1liWDv1ZHqUmlNHs3cjrXsL3pZjE9GPxA5lcP2n5VpRRNwkIZmj13Yzr6RyWF KdQLu4PApyddRiBkBeT+w== X-UI-Out-Filterresults: notjunk:1;V03:K0:7bz00NZJpkc=:cTLchf6SDvpd+yHeLgC+uk 5JlYPqGRdC48wO8s2j9T96Cd0fl9/6T7eUe61L8I1kr17SCbeb9hbvxxUwKFzCp7EoqxkTh/E RRoMeoSk0FFcQ/7j4QYMTqQgKgw1dQrjyBqX2k3xzfnpR+Ehx/eRmfeIfkAZL3yCML4IsPd/x bJXTVxYEvJzhhuJYD2Upv4geJZ2sj+GOdPfWi2IXjvafBK4DQ64FRG/Wb8DLUrzlN7nSTKY9u XMJqyIhK+l2Q/DUz9tr9BC2ytgDliu+qGzppuW/2YmchysU+rI8+MsU2kuQwzc4OIcSUriH8b 6JiAmFW9GHXz4U/eds81/hRcnAd287kaDQEmS5SgH4x5f4slbnY1s9WLaSW/zM5Zte3nP1s00 vuy4fjKkrfPX2s45fbaZwT97ipZXBi6ENWh4q1Mui5fRNeJriS9OVASKAnS3xbK6Utz1A7u2c pilVfPvyGZi1ZP9/4aW57NTSruyrOweK51AVFmGt8/B9LUcSM59wPZ3VU7bP+uNoaCFgHE+Lj JnEOIeqLcV0qi2HhZRCaanJfxsOCOItMDw700FL2KeM/TWTCJG3nLM5oDMTuXU0H8UWDHN5KS skLa3Fhq9eNlF5mX/yauJte+4XtOIy6TC/tICkDR5rPDtPh/wEXTnZSAByHLAMC7U0YHSuHuZ 0DGBN/Y26fkCmEqN16gUhTI8JT4sSJx5/olRyN3FY1qkVd8AYJ++pz+7MdpHz1Me0LYobY/kR srw8AckKilm3tLm/2UHg/P2sVfbEMOy2EATuotqWr4/AZVA7vXdNkjzBQ/C0RsPOBoaed8nlw 2TDT1hIXvJGGsFFrue4ZYY4IEowIry3Uz1a4D6/ZQM0g1sTc19mxLjRCZAucW95Ekb6xH6xaw eBaD7I854JWKmbXHhcgHZjYUJ45/AhCcCwKCMkxp0hHsSHzLXeFDovCu0XaarAh3xMK2rK91U 4AuuVlE5XyvSak+twpsTvobUl5EYLH9GVxglriGl1Yys5630umMMXSlC4y2AOszOytQfLDiUJ LzZBYiwzF+lCHk+l8iXWG433ZgUAV4cyQUpoIFd6KAZYgVeXP5dB6PneI+uJRlmwgqNrYYqhK K3tOBzev2Ypg0zewFHzu4pe3qrZRkHEAxqlCdZNO45UL/OdTox+1TgnXxt6UUAKKqjdqL6w8N 45dIde1hVRcjLqsoQ5BaS6XGUHOSc1M0vIrhFgY+cUVVld/0Ge5w8OcXkiPs97rwvY1w0= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: emacs-orgmode@gnu.org List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 47088@debbugs.gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1620338790; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=yEbuVBMJEt2KALAhFwMGZMX13k3SAjCz+NPcNlW2huE=; b=GyzE92rw6wyaaEIaBPKqw614eyOrAkjeDeCifMJpF4iXCpj2dD9MONajNr1PJevVcKK3Vc GVhWMMSi7H4LHoCuao66Ajw8yaZloiPGT1GQdCRPyYBKGIdMe3mrjRcJEIUkAYgebqdAt2 fpHmBOkZ8I8oeKLwrR9V2z1ILwpwalweZ4lRtPT1ZIbkGl0Zfk1fqpWA8kYN98clVZcDLR xGoorAvxrx1ERKH/mtTmPUnORC5U4WWi5VRwKI1CiByCgmQplKXBkxuRtKHAf9aEqJDN2e Jed4DXEJtm8dkVWgahAZHnhI+vnrPTYkUuFEhKzYzuIIke8qCSEJwPgPi48puA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1620338790; a=rsa-sha256; cv=none; b=Z4gY2gN8RKN7BVfJYf/P3E0wMIB4jD9V9v9X0UQwaQJ/5ug0xzDOxkFSvCkPTxMLFpBEqw LwI6g1Vy/2k/aBltGl91UU9vB9VOJodiHHh0yhIZOX3CgQDONUBKHqWyQ/9abdImz72qPX gzzUy609bKwMNzEx8PyA/Eu9NZC/B2S0GPI+szIOiB0E+OH8CdbSNIq6NnIOF6VOPU3tn/ sS//Zc4FDuh5QBPiscI8e0nMnY9WRCtLrHwyHs/LnU1fe/GPcDiISXyX4r65g0pfDeLBw+ MmHISVBLpFS19SKmKzJeDZj5r/+l1BOmpWtPkjR2IpoKbFxC9eLy5bSp99dbhg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmx.net header.s=badeba3b8450 header.b=NvooYobT; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmx.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: 0.14 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmx.net header.s=badeba3b8450 header.b=NvooYobT; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmx.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 814278855 X-Spam-Score: 0.14 X-Migadu-Scanner: scn0.migadu.com X-TUID: hASlZ5AYYyrx --7bpnx4ijob5a46ui Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2021-05-05 10:16, Bastien wrote: > Thanks, it looks good. > > Can you try updating the patch against Org's upstream repository at > https://code.orgmode.org/bzg/org-mode/? > > Note that the file is lisp/ol-w3m.el there. 1] Attached. 2] Here's a commit message in the Changelog style: 2021-05-06 Boruch Baum * ol-w3m.el (org-w3m-copy-for-org-mode) (org-w3m-get-next-link-start, org-w3m-get-prev-link-start): Account for w3m-img links. (org-w3m-get-anchor-start, org-w3m-get-prev-link-start) (org-w3m-no-prev-link-p): Unused function notes. (org-w3m-get-image-end): New function, for w3m-img links. 3] As mentioned in the patch, and in the commit message, there seem to be several functioned unused in the code base that could be candidates for removal... org-w3m-get-anchor-start org-w3m-no-prev-link-p org-w3m-get-prev-link-start 4] Additionally, in performing the merge I came across function org-string-nw-p, which seems to be an unnecessary duplicate of the emacs core function string-blank-p. It may be that historically you once needed your own home-made functions/macros, but now that emacs core has them, you may want to consider a refactor. =2D- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0 --7bpnx4ijob5a46ui Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="ol-w3m.patch" Content-Transfer-Encoding: quoted-printable diff --git a/ol-w3m.el b/ol-w3m.el index ebb11ce..2738e01 100644 =2D-- a/ol-w3m.el +++ b/ol-w3m.el @@ -82,26 +82,41 @@ so that it can be yanked into an Org buffer with link= s working correctly." (setq temp-position (point)) ;; move to next anchor when current point is not at anchor (or (get-text-property (point) 'w3m-href-anchor) (org-w3m-get-nex= t-link-start)) - (if (<=3D (point) transform-end) ; if point is inside transform b= ound - (progn - ;; get content between two links. - (when (> (point) temp-position) - (setq return-content (concat return-content - (buffer-substring - temp-position (point))))) - ;; get link location at current point. - (setq link-location (get-text-property (point) 'w3m-href-an= chor)) - ;; get link title at current point. - (setq link-title (buffer-substring (point) - (org-w3m-get-anchor-end)= )) - ;; concat Org style url to `return-content'. - (setq return-content - (concat return-content - (if (org-string-nw-p link-location) - (org-link-make-string link-location link-title) - link-title)))) + (cond + ((<=3D (point) transform-end) ; point is inside transform bound + ;; get content between two links. + (when (> (point) temp-position) + (setq return-content (concat return-content + (buffer-substring + temp-position (point))))) + (cond + ((setq link-location (get-text-property (point) 'w3m-href-anc= hor)) + ;; current point is a link + ;; (we thus also got link location at current point) + ;; get link title at current point. + (setq link-title (buffer-substring (point) + (org-w3m-get-anchor-end))= ) + ;; concat Org style url to `return-content'. + (setq return-content + (concat return-content + (if (org-string-nw-p link-location) + (org-link-make-string link-location link-title) + link-title)))) + ((setq link-location (get-text-property (point) 'w3m-image)) + ;; current point is an image + ;; (we thus also got image link location at current point) + ;; get link title at current point. + (setq link-title (buffer-substring (point) (org-w3m-get-imag= e-end))) + ;; concat Org style url to `return-content'. + (setq return-content + (concat return-content + (if (org-string-nw-p link-location) + (org-link-make-string link-location link-title) + link-title)))) + (t nil))); current point is neither a link nor an image + (t ; point is NOT inside transform bound (goto-char temp-position) ; reset point before jump next anchor - (setq out-bound t))) ; for break out `while' loop + (setq out-bound t)))) ; for break out `while' loop ;; add the rest until end of the region to be copied (when (< (point) transform-end) (setq return-content @@ -114,6 +129,7 @@ so that it can be yanked into an Org buffer with link= s working correctly." (defun org-w3m-get-anchor-start () "Move cursor to the start of current anchor. Return point." ;; get start position of anchor or current point + ;; NOTE: This function seems never to be used. Should it be removed? (goto-char (or (previous-single-property-change (point) 'w3m-anchor-seq= uence) (point)))) @@ -123,26 +139,46 @@ so that it can be yanked into an Org buffer with li= nks working correctly." (goto-char (or (next-single-property-change (point) 'w3m-anchor-sequenc= e) (point)))) +(defun org-w3m-get-image-end () + "Move cursor to the end of current image. Return point." + ;; get end position of image or point + ;; NOTE: Function `org-w3m-get-image-start' was not created because + ;; function `org-w3m-get-anchor-start' is never used. + (goto-char (or (next-single-property-change (point) 'w3m-image) + (point)))) + (defun org-w3m-get-next-link-start () - "Move cursor to the start of next link. Return point." - (catch 'reach - (while (next-single-property-change (point) 'w3m-anchor-sequence) - ;; jump to next anchor - (goto-char (next-single-property-change (point) 'w3m-anchor-sequenc= e)) - (when (get-text-property (point) 'w3m-href-anchor) - ;; return point when current is valid link - (throw 'reach nil)))) - (point)) + "Move cursor to the start of next link or image. Return point." + (let (pos start-pos anchor-pos image-pos) + (setq pos (setq start-pos (point))) + (setq anchor-pos + (catch 'reach + (while (setq pos (next-single-property-change pos 'w3m-anchor-seq= uence)) + (when (get-text-property pos 'w3m-href-anchor) + (throw 'reach pos))))) + (setq pos start-pos) + (setq image-pos + (catch 'reach + (while (setq pos (next-single-property-change pos 'w3m-image)) + (when (get-text-property pos 'w3m-image) + (throw 'reach pos))))) + (goto-char (min (or anchor-pos (point-max)) (or image-pos (point-max)= ))))) (defun org-w3m-get-prev-link-start () "Move cursor to the start of previous link. Return point." + ;; NOTE: This function is only called by `org-w3m-no-prev-link-p', + ;; which itself seems never to be used. Should it be removed? + ;; + ;; WARNING: This function has not been updated to account for + ;; `w3m-image'. See `org-w3m-get-next-link-start'. (catch 'reach - (while (previous-single-property-change (point) 'w3m-anchor-sequence) - ;; jump to previous anchor - (goto-char (previous-single-property-change (point) 'w3m-anchor-seq= uence)) - (when (get-text-property (point) 'w3m-href-anchor) - ;; return point when current is valid link - (throw 'reach nil)))) + (let ((pos (point))) + (while (setq pos (previous-single-property-change pos 'w3m-anchor-s= equence)) + (when (get-text-property pos 'w3m-href-anchor) + ;; jump to previous anchor + (goto-char pos) + ;; return point when current is valid link + (throw 'reach nil))))) (point)) (defun org-w3m-no-next-link-p () @@ -154,6 +190,7 @@ Return t if there is no next link; otherwise, return n= il." (defun org-w3m-no-prev-link-p () "Whether there is no previous link after the cursor. Return t if there is no previous link; otherwise, return nil." + ;; NOTE: This function seems never to be used. Should it be removed? (save-excursion (equal (point) (org-w3m-get-prev-link-start)))) --7bpnx4ijob5a46ui--