From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [ANN] Changes to link syntax Date: Fri, 15 Mar 2019 12:55:02 +0100 Message-ID: <87sgvotkrt.fsf@nicolasgoaziou.fr> References: <87sgvusl43.fsf@nicolasgoaziou.fr> <87h8c490eh.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([209.51.188.92]:51121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4mTx-000354-V6 for emacs-orgmode@gnu.org; Fri, 15 Mar 2019 09:02:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4mGJ-0001If-Ny for emacs-orgmode@gnu.org; Fri, 15 Mar 2019 08:48:37 -0400 Received: from mslow2.mail.gandi.net ([217.70.178.242]:50662) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h4mGI-0001Hk-15 for emacs-orgmode@gnu.org; Fri, 15 Mar 2019 08:48:35 -0400 Received: from relay5-d.mail.gandi.net (unknown [217.70.183.197]) by mslow2.mail.gandi.net (Postfix) with ESMTP id DE6533AA57A for ; Fri, 15 Mar 2019 11:55:29 +0000 (UTC) In-Reply-To: <87h8c490eh.fsf@gmail.com> (stardiviner's message of "Fri, 15 Mar 2019 13:23:02 +0800") 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: stardiviner Cc: emacs-orgmode@gnu.org 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]\\)" 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)))))))))))