Browse Source

Deprecate `org-link-analytic-bracket-re'

* lisp/ob-tangle.el (org-babel-detangle):
(org-babel-tangle-jump-to-org): Use `org-link-bracket-re'.
* lisp/ol.el (org-link-analytic-bracket-re): Remove variable.
(org-link-make-regexps): Do not set it.
(org-link-display-format): Use `org-link-bracket-re'
(org-link-trim-scheme): New function.
(org-store-link): Remove code duplication.
Nicolas Goaziou 1 year ago
parent
commit
3318b50a39
3 changed files with 11 additions and 40 deletions
  1. 7 13
      lisp/ob-tangle.el
  2. 3 26
      lisp/ol.el
  3. 1 1
      lisp/org-compat.el

+ 7 - 13
lisp/ob-tangle.el

@@ -39,10 +39,10 @@
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-type "org-element" (element))
 (declare-function org-heading-components "org" ())
-(declare-function org-id-find "org-id" (id &optional markerp))
 (declare-function org-in-commented-heading-p "org" (&optional no-inheritance))
 (declare-function org-link-escape "org" (text &optional table merge))
 (declare-function org-link-open-from-string "ol" (s &optional arg))
+(declare-function org-link-trim-scheme "ol" (uri))
 (declare-function org-store-link "org" (arg &optional interactive?))
 (declare-function outline-previous-heading "outline" ())
 
@@ -516,7 +516,6 @@ non-nil, return the full association list to be used by
 	  (org-fill-template org-babel-tangle-comment-format-end link-data))))
 
 ;; de-tangling functions
-(defvar org-link-analytic-bracket-re)
 (defun org-babel-detangle (&optional source-code-file)
   "Propagate changes in source file back original to Org file.
 This requires that code blocks were tangled with link comments
@@ -526,9 +525,9 @@ which enable the original code blocks to be found."
     (when source-code-file (find-file source-code-file))
     (goto-char (point-min))
     (let ((counter 0) new-body end)
-      (while (re-search-forward org-link-analytic-bracket-re nil t)
+      (while (re-search-forward org-link-bracket-re nil t)
         (when (re-search-forward
-	       (concat " " (regexp-quote (match-string 5)) " ends here"))
+	       (concat " " (regexp-quote (match-string 3)) " ends here"))
           (setq end (match-end 0))
           (forward-line -1)
           (save-excursion
@@ -542,17 +541,15 @@ which enable the original code blocks to be found."
   "Jump from a tangled code file to the related Org mode file."
   (interactive)
   (let ((mid (point))
-	start body-start end
-        target-buffer target-char link path block-name body)
+	start body-start end target-buffer target-char link block-name body)
     (save-window-excursion
       (save-excursion
-	(while (and (re-search-backward org-link-analytic-bracket-re nil t)
+	(while (and (re-search-backward org-link-bracket-re nil t)
 		    (not ; ever wider searches until matching block comments
 		     (and (setq start (line-beginning-position))
 			  (setq body-start (line-beginning-position 2))
 			  (setq link (match-string 0))
-			  (setq path (match-string 3))
-			  (setq block-name (match-string 5))
+			  (setq block-name (match-string 3))
 			  (save-excursion
 			    (save-match-data
 			      (re-search-forward
@@ -562,12 +559,9 @@ which enable the original code blocks to be found."
 	(unless (and start (< start mid) (< mid end))
 	  (error "Not in tangled code"))
         (setq body (buffer-substring body-start end)))
-      (when (string-match "::" path)
-        (setq path (substring path 0 (match-beginning 0))))
-      (find-file (or (car (org-id-find path)) path))
-      (setq target-buffer (current-buffer))
       ;; Go to the beginning of the relative block in Org file.
       (org-link-open-from-string link)
+      (setq target-buffer (current-buffer))
       (if (string-match "[^ \t\n\r]:\\([[:digit:]]+\\)" block-name)
           (let ((n (string-to-number (match-string 1 block-name))))
 	    (if (org-before-first-heading-p) (goto-char (point-min))

+ 3 - 26
lisp/ol.el

@@ -489,15 +489,6 @@ This is the list that is used for internal purposes.")
 (defvar org-link-bracket-re nil
   "Matches a link in double brackets.")
 
-(defvar org-link-analytic-bracket-re nil
-  "Regular expression used to analyze links.
-Here is what the match groups contain after a match:
-1: http:
-2: http
-3: path
-4: [desc]
-5: desc")
-
 (defvar org-link-any-re nil
   "Regular expression matching any link.")
 
@@ -760,14 +751,6 @@ This should be called after the variable `org-link-parameters' has changed."
 	  ;;	 "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
 	  org-link-bracket-re
 	  "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
-	  org-link-analytic-bracket-re
-	  (concat
-	   "\\[\\["
-	   "\\(" types-re ":\\)?"
-	   "\\([^]]+\\)"
-	   "\\]"
-	   "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
-	   "\\]")
 	  org-link-any-re
 	  (concat "\\(" org-link-bracket-re "\\)\\|\\("
 		  org-link-angle-re "\\)\\|\\("
@@ -1223,10 +1206,8 @@ of matched result, which is either `dedicated' or `fuzzy'."
 If there is no description, use the link target."
   (save-match-data
     (replace-regexp-in-string
-     org-link-analytic-bracket-re
-     (lambda (m)
-       (if (match-end 5) (match-string 5 m)
-	 (concat (match-string 1 m) (match-string 3 m))))
+     org-link-bracket-re
+     (lambda (m) (or (match-string 3 m) (match-string 1 m)))
      s nil t)))
 
 (defun org-link-add-angle-brackets (s)
@@ -1613,11 +1594,7 @@ non-nil."
 	    desc (or desc cpltxt))
       (cond ((not desc))
 	    ((equal desc "NONE") (setq desc nil))
-	    (t (setq desc
-		     (replace-regexp-in-string
-		      org-link-analytic-bracket-re
-		      (lambda (m) (or (match-string 5 m) (match-string 3 m)))
-		      desc))))
+	    (t (setq desc (org-link-display-format desc))))
       ;; Return the link
       (if (not (and interactive? link))
 	  (or agenda-link (and link (org-link-make-string link desc)))

+ 1 - 1
lisp/org-compat.el

@@ -517,7 +517,7 @@ use of this function is for the stuck project list."
   'org-link-bracket-re "Org 9.3")
 
 (define-obsolete-variable-alias 'org-bracket-link-analytic-regexp
-  'org-link-analytic-bracket-re "Org 9.3")
+  'org-link-bracket-re "Org 9.3")
 
 (define-obsolete-variable-alias 'org-any-link-re
   'org-link-any-re "Org 9.3")