From mboxrd@z Thu Jan 1 00:00:00 1970 From: stardiviner Subject: Re: [ANN] Changes to link syntax Date: Wed, 27 Mar 2019 10:00:04 +0800 Message-ID: <87imw5rs9n.fsf@gmail.com> References: <87sgvusl43.fsf@nicolasgoaziou.fr> <87h8c490eh.fsf@gmail.com> <87sgvotkrt.fsf@nicolasgoaziou.fr> Reply-To: numbchild@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([209.51.188.92]:45073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8xrg-0006J6-Rf for emacs-orgmode@gnu.org; Tue, 26 Mar 2019 22:00:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h8xrd-0004q2-1H for emacs-orgmode@gnu.org; Tue, 26 Mar 2019 22:00:28 -0400 Received: from [61.175.244.13] (port=22334 helo=dark.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8xrU-0004le-9W for emacs-orgmode@gnu.org; Tue, 26 Mar 2019 22:00:19 -0400 In-reply-to: <87sgvotkrt.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Nicolas Goaziou Cc: emacs-orgmode@gnu.org Nicolas Goaziou writes: > stardiviner writes: > >> Hi, @Nicolas, will you release a method to update all existing Org >> file links? > > On second though, you may want to test the following: > > (defun org-update-link-syntax () > "Update syntax for links in current buffer." > (org-with-point-at 1 > (let ((case-fold-search t)) > (while (re-search-forward "\\[\\[[^]]*?%\\(?:2[05]\\|5[BD]\\)" ni= l t) > (let ((object (save-match-data (org-element-context)))) > (when (and (eq 'link (org-element-type object)) > (=3D (match-beginning 0) > (org-element-property :begin object))) > (goto-char (org-element-property :end object)) > (let* ((uri-start (+ 2 (match-beginning 0))) > (uri-end (save-excursion > (goto-char uri-start) > (re-search-forward "\\][][]" nil t) > (match-beginning 0))) > (uri (buffer-substring-no-properties uri-start uri-e= nd)) > (start 0)) > (when (catch :obsolete > (while (string-match "%\\(..\\)?" uri start) > (setq start (match-end 0)) > (unless (member (match-string 1 uri) > '("25" "5B" "5D" "20")) > (throw :obsolete nil))) > (y-or-n-p > (format "Possibly obsolete URI syntax: %S. Upda= te?" > uri))) > (setf (buffer-substring uri-start uri-end) > (org-link-escape (org-link-decode uri))))))))))) >=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 I found a simple and better solution to replace those. I use =3Drg (ripgrep= )=3D to search you mentioned escape characters "%20 %25 %5B %5D". I then use =3Dwgr= ep=3D on results. I spend pretty long time to processing all links. There are about = 40000 links matched. And about 20000 links processed. Still there are some links matched but not process (or ignored) by your upper function. Here I picked some typical cases: #+begin_src org [[file:~/Org/Wiki/Computer%20Technology/Softwares/%E9%9A%8F%E6%89%8B%E8%AE%= B0.org::*Export%20through%20Web%20client][Export through Web client]] - [ ] [[file:Data/Books/%E7%89%9B%E6%B4%A5%E9%80%9A%E8%AF%86%E8%AF%BB%E6%9C= %AC:%20%E7%A7%91%E5%AD%A6%E5%93%B2%E5%AD%A6.azw3][=E7=89=9B=E6=B4=A5=E9=80= =9A=E8=AF=86=E8=AF=BB=E6=9C=AC: =E7=A7=91=E5=AD=A6=E5=93=B2=E5=AD=A6 (azw3)= ]] -- by =E8=90=A8=E7=B1=B3=E5=B0=94=C2=B7=E5=A5=A5=E5=8D=A1=E6=B2=99 [[file:~/Org/Wiki/Computer%20Technology/Programming/Data%20Structure/Data/B= ooks/%E5%A4%A7%E8%AF%9D%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84.pdf::%25PDF-1.4= ][=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E8=B5=B7=E6=BA=90 -- =E3=80=8A=E5=A4= =A7=E8=AF=9D=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E3=80=8B]] [[file:~/Org/Wiki/Computer Technology/Programming/Emacs/Data/Emacs Packages= /Org mode/Org mode.org::*Write Online Book of Programming Data Structures a= nd Algorithms][Write Online Book of Programming Data Structures and Algorit= hms]] - [[file:Data/Videos/%E8%B5%8C%E5%8D%9A%E9%BB%98%E7%A4%BA%E5%BD%95/%5B%E8%B= 5%8C%E5%8D%9A%E9%BB%98%E7%A4%BA%E5%BD%95%5D%20Ultimate_Survivor_Kaiji%20-%2= 015.rmvb][Ultimate Survivor Kaiji 15]] #+end_src After finished this upgrading, I will write a blog post about this for help= ing user migration. --=20 [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 =20=20=20=20=20=20