[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [ANN] Changes to link syntax

From: stardiviner
Subject: Re: [O] [ANN] Changes to link syntax
Date: Wed, 27 Mar 2019 10:00:04 +0800
User-agent: mu4e 1.1.0; emacs 27.0.50

Nicolas Goaziou <address@hidden> writes:

> stardiviner <address@hidden> 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]\\)" nil t)
>           (let ((object (save-match-data (org-element-context))))
>             (when (and (eq 'link (org-element-type object))
>                        (= (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-end))
>                      (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.  Update?"
>                                  uri)))
>                   (setf (buffer-substring uri-start uri-end)
>                         (org-link-escape (org-link-decode uri)))))))))))

I found a simple and better solution to replace those. I use =rg (ripgrep)= to
search you mentioned escape characters "%20 %25 %5B %5D". I then use =wgrep= 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
 through Web client]]

- [ ] 
 科学哲学 (azw3)]] -- by 萨米尔·奥卡沙

 -- 《大话数据结构》]]

[[file:~/Org/Wiki/Computer Technology/Programming/Emacs/Data/Emacs Packages/Org 
mode/Org mode.org::*Write Online Book of Programming Data Structures and 
Algorithms][Write Online Book of Programming Data Structures and Algorithms]]

 Survivor Kaiji 15]]

After finished this upgrading, I will write a blog post about this for helping 
user migration.

[ 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]