From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 12 01:26:27 2021 Received: (at submit) by debbugs.gnu.org; 12 Mar 2021 06:26:27 +0000 Received: from localhost ([127.0.0.1]:55859 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lKbFi-0003Gj-Mc for submit@debbugs.gnu.org; Fri, 12 Mar 2021 01:26:27 -0500 Received: from lists.gnu.org ([209.51.188.17]:50738) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lKbFg-0003Ga-N3 for submit@debbugs.gnu.org; Fri, 12 Mar 2021 01:26:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKbFg-000659-GH for bug-gnu-emacs@gnu.org; Fri, 12 Mar 2021 01:26:24 -0500 Received: from mout.gmx.net ([212.227.17.20]:41955) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKbFd-0003M0-Oz for bug-gnu-emacs@gnu.org; Fri, 12 Mar 2021 01:26:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1615530378; bh=qm8TioieF6dQ5miTVsDSMM0dLWuTErc7cBq3yqFw6L0=; h=X-UI-Sender-Class:Date:From:To:Subject; b=j5oUr/tZISjRPL54g97yQK9ybeYACb1LngxFKAf6ouEvF3+w45kJ9fmfVTRUJkypR gqF25RWPiQVBP2kbsPY59anvSk//OlaW1B287HjqFOax0FEuOr9dOkaRkTc9+dTOTS rNo0fG/IYCLFKh6W7M/YMESyrlP4ubSq33hejOWs= 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 1MyKDU-1lfiXV3Qy4-00yfeE for ; Fri, 12 Mar 2021 07:26:18 +0100 Date: Fri, 12 Mar 2021 01:26:14 -0500 From: Boruch Baum To: Emacs Bug Reporting Subject: org-w3m: handle w3m-image link information Message-ID: <20210312062614.usandeuwplmn7fu3@E15-2016.optimum.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="j7c3mxqbopbgd6ek" Content-Disposition: inline User-Agent: NeoMutt/20180716 X-Provags-ID: V03:K1:+BsIlxdKWSp9SovLrArrWDRnKJSq/SJ3fm2+x9VMt3FRNrGiR6H 0MWIS36tSYnHgMs72DSPG+aH7qqZJIIoM4MfJEIBvyuor41YTPiEXwlYGwyUq31pppVPE1g vkvERzvZPeM41c0VY0TnFrmj+GB6nhWVCpsPcFgLNWsqlCzE/6XmzLxwYNL6eeIDbRGvuP9 9sWOQcccm9rfNLmHM22fA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:ua6+/ReIczc=:Qax74AlZljVWtqZnG7YUe+ pJn507qpvwv66rCpCq2phQL0CVendU3z7CClxE7nHnz4eqr04Pb7b42z6AIIExphxXgKmUImD LQ5yzEliJ1VxogZfV+tFV5j5kYTFxgsxdo1JS88+K4zCetBHvuQaJX4fRW9ry3dXhtov/oFGG O/trFCxg6qxVK4xT24dwiDY2t5KlKKpLMFQR6/jCo4mz+AKjKsxRGdk5nNOuQgCSm0+EnjZOv 2XJ9VgMeq7FQdNA1Wi9/1goV2xjpAtaP5B2ErMexKFC1Nt76FJ9dDqZxNgmCnwZUdtkm513Dw VfaPloHyDYwwv7Rga/Hm/1cdslJR9/RDOlnQ1liVWRx0EprZ+5Hmv3a7I0sgg2aH76khAkYR7 ONLSUMNSlyttpy4Fu0rtd+QocHU5f2iLmUtht/NN20DOe4GxCxyX45nuu0GU4ElNPa4UPMzn9 bB8fL55a00N0U62E/JmyJ5NpVbW4Z0q4Bm1iIuGqZv2krgh+fHoHKZjoUFOiZwToIiTiv1Ukq sZD5IIBRRV/hXZ/h2eRx/UqAuowr8G/36I3/jKRv7Pn4WsGoSYVVF1KZjV6LUwjfsGZYYBQjo z1wBscfQ+pOLlgQZR0bcGkVWjJQBLDEXIJf7V49fRBpZ8n2cqbS/qmKidhEA/2xOaPCtpGmSJ rc5Fw42SvjBcFFovW4VvMCot/Dh30HXj9pV0fRVjOBfM/EmiiIHcDxl7V/KPP8CQth3t19UbO xsHnUulgpapqF2N/MBpJoU/rXKPoEQNuenygnH6RnVcR/p9FXPht0fkKDDO1Zch42OnK2AemS POFgdBWMC3lyGutQ0vRFhXJObmxosM10nFaFQqBsfQMOrTVJqCnpr1UAn7x8fjVdFs4A9p/nG jiHw8/RAycnzF9vqirlQ== Received-SPF: pass client-ip=212.227.17.20; envelope-from=boruch_baum@gmx.com; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --j7c3mxqbopbgd6ek Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Attached is a patch that adds to function `org-w3m-copy-for-org-mode' support for w3m-image links. Note that because function `org-make-link-string' is used for constructing the buffer substring to be copied, w3m's special face to distinguish an image link is not transfered. =2D- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0 --j7c3mxqbopbgd6ek Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="image.patch" diff --git a/org-w3m.el b/org-w3m.el index 9690c8e..9b3a092 100644 --- a/org-w3m.el +++ b/org-w3m.el @@ -82,25 +82,42 @@ so that it can be yanked into an Org buffer with links 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-next-link-start)) - (if (<= (point) transform-end) ; if point is inside transform bound - (progn - ;; get content between two links. - (if (> (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-anchor)) - ;; 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 - (org-make-link-string - link-location link-title)))) + (cond + ((<= (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-anchor)) + ;; 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 + (org-make-link-string + link-location 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-image-end))) + ;; concat Org style url to `return-content'. + (setq return-content (concat return-content + (org-make-link-string + link-location link-title)))) + (t ; current point is neither a link nor an image + ;; NOTE: Should this point ever legitimately be reached? + ;; Let's explicitly unset some variables just to be + ;; safe... + (setq link-location nil + link-title nil)))) + (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 (if (< (point) transform-end) (setq return-content @@ -113,6 +130,7 @@ so that it can be yanked into an Org buffer with links 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-sequence) (point)))) @@ -122,26 +140,46 @@ so that it can be yanked into an Org buffer with links working correctly." (goto-char (or (next-single-property-change (point) 'w3m-anchor-sequence) (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-sequence)) - (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-sequence)) + (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-sequence)) - (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-sequence)) + (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 () @@ -153,6 +191,7 @@ Return t if there is no next link; otherwise, return nil." (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)))) --j7c3mxqbopbgd6ek-- From debbugs-submit-bounces@debbugs.gnu.org Wed May 05 04:16:59 2021 Received: (at 47088) by debbugs.gnu.org; 5 May 2021 08:16:59 +0000 Received: from localhost ([127.0.0.1]:58506 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1leCiJ-0005kC-8F for submit@debbugs.gnu.org; Wed, 05 May 2021 04:16:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52308) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1leCiH-0005jh-Bo for 47088@debbugs.gnu.org; Wed, 05 May 2021 04:16:57 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:40027) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leCiB-0000ZO-Pt; Wed, 05 May 2021 04:16:51 -0400 Received: from [2a01:e34:ec2b:7150:e50e:b79f:a75a:65f7] (port=42706 helo=guerry) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1leCiA-0001jl-O2; Wed, 05 May 2021 04:16:51 -0400 Received: by guerry (Postfix, from userid 1000) id 68FF91A60E9C; Wed, 5 May 2021 10:16:48 +0200 (CEST) From: Bastien To: Boruch Baum Subject: Re: bug#47088: org-w3m: handle w3m-image link information In-Reply-To: <20210312062614.usandeuwplmn7fu3@E15-2016.optimum.net> (Boruch Baum's message of "Fri, 12 Mar 2021 01:26:14 -0500") Organization: GNU References: <20210312062614.usandeuwplmn7fu3@E15-2016.optimum.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Date: Wed, 05 May 2021 10:16:48 +0200 Message-ID: <87zgx9ioi7.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 47088 Cc: 47088@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Boruch Baum writes: > Attached is a patch that adds to function `org-w3m-copy-for-org-mode' > support for w3m-image links. Note that because function > `org-make-link-string' is used for constructing the buffer substring to > be copied, w3m's special face to distinguish an image link is not > transfered. 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. -- Bastien From debbugs-submit-bounces@debbugs.gnu.org Thu May 06 18:05:28 2021 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 To: Bastien Subject: Re: bug#47088: org-w3m: handle w3m-image link information 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-Spam-Flag: NO 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-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 47088 Cc: 47088@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --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-- From debbugs-submit-bounces@debbugs.gnu.org Sun May 09 02:50:11 2021 Received: (at 47088-done) by debbugs.gnu.org; 9 May 2021 06:50:11 +0000 Received: from localhost ([127.0.0.1]:54575 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfdGV-0007WE-4P for submit@debbugs.gnu.org; Sun, 09 May 2021 02:50:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47994) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfdGU-0007W3-2a for 47088-done@debbugs.gnu.org; Sun, 09 May 2021 02:50:10 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:54518) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lfdGO-0005RT-OI; Sun, 09 May 2021 02:50:04 -0400 Received: from [78.194.183.21] (port=38724 helo=guerry) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfdGN-0005N1-Hp; Sun, 09 May 2021 02:50:04 -0400 Received: by guerry (Postfix, from userid 1000) id 3EF691A60E75; Sun, 9 May 2021 08:50:01 +0200 (CEST) From: Bastien To: Boruch Baum Subject: Re: bug#47088: org-w3m: handle w3m-image link information In-Reply-To: <20210506220515.fr7ebcvvtb3jj5yp@E15-2016.optimum.net> (Boruch Baum's message of "Thu, 6 May 2021 18:05:15 -0400") Organization: GNU References: <20210312062614.usandeuwplmn7fu3@E15-2016.optimum.net> <87zgx9ioi7.fsf@gnu.org> <20210506220515.fr7ebcvvtb3jj5yp@E15-2016.optimum.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Date: Sun, 09 May 2021 08:50:01 +0200 Message-ID: <874kfch04m.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 47088-done Cc: 47088-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) I'm closing this report as the patch has been applied upstream. -- Bastien From unknown Sun Jun 22 08:09:56 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 06 Jun 2021 11:24:11 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator