all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: stardiviner <numbchild@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: emacs-orgmode@gnu.org
Subject: Re: [ANN] Changes to link syntax
Date: Wed, 27 Mar 2019 10:00:04 +0800	[thread overview]
Message-ID: <87imw5rs9n.fsf@gmail.com> (raw)
In-Reply-To: <87sgvotkrt.fsf@nicolasgoaziou.fr>


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> stardiviner <numbchild@gmail.com> 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
[[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][牛津通识读本: 科学哲学 (azw3)]] -- by 萨米尔·奥卡沙

[[file:~/Org/Wiki/Computer%20Technology/Programming/Data%20Structure/Data/Books/%E5%A4%A7%E8%AF%9D%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84.pdf::%25PDF-1.4][数据结构起源 -- 《大话数据结构》]]

[[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]]

- [[file:Data/Videos/%E8%B5%8C%E5%8D%9A%E9%BB%98%E7%A4%BA%E5%BD%95/%5B%E8%B5%8C%E5%8D%9A%E9%BB%98%E7%A4%BA%E5%BD%95%5D%20Ultimate_Survivor_Kaiji%20-%2015.rmvb][Ultimate Survivor Kaiji 15]]
#+end_src

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
      

  parent reply	other threads:[~2019-03-27  2:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-10 17:19 [ANN] Changes to link syntax Nicolas Goaziou
2019-03-10 20:02 ` Samuel Wales
2019-03-10 22:13   ` Amin Bandali
2019-03-12 13:44     ` Nicolas Goaziou
2019-03-10 23:00 ` Daniele Nicolodi
2019-03-11 16:35   ` Nicolas Goaziou
2019-03-11 17:06     ` Eric S Fraga
2019-03-11 17:31     ` Daniele Nicolodi
2019-03-11 17:27 ` Marco Wahl
2019-03-11 18:00   ` Diego Zamboni
2019-03-11 23:07     ` Nicolas Goaziou
2019-03-12  5:42       ` Diego Zamboni
2019-03-15  5:23 ` stardiviner
2019-03-15 10:55   ` Nicolas Goaziou
2019-03-18  1:04     ` stardiviner
2019-03-18 21:33       ` Nicolas Goaziou
2019-03-19  8:06         ` stardiviner
2019-03-15 11:55   ` Nicolas Goaziou
2019-03-26  9:08     ` stardiviner
2019-03-27  2:00     ` stardiviner [this message]
2019-04-02 21:16       ` Nicolas Goaziou
2019-04-07 11:20       ` stardiviner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imw5rs9n.fsf@gmail.com \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.