emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/org 62c90be 2/2: compat: Add `org-string-distance'


From: ELPA Syncer
Subject: [elpa] externals/org 62c90be 2/2: compat: Add `org-string-distance'
Date: Wed, 5 May 2021 11:57:18 -0400 (EDT)

branch: externals/org
commit 62c90bef351cab794a9ba673ff901274c9d82f42
Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Commit: Nicolas Goaziou <mail@nicolasgoaziou.fr>

    compat: Add `org-string-distance'
    
    * lisp/ob-core.el (org-babel-edit-distance): Rename function
    `org-string-distance' and move it to "org-compat.el".
    (org-babel-check-src-block): Use `org-string-distance' instead.
    * lisp/org-compat.el: Add `org-string-distance' for a future
    deprecation in favor of `string-distance'.
---
 lisp/ob-core.el    | 23 +----------------------
 lisp/org-compat.el | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 12f67a8..857e03e 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -809,27 +809,6 @@ arguments and pop open the results in a preview buffer."
         expanded (concat "*Org-Babel Preview " (buffer-name) "[ " lang " ]*"))
       expanded)))
 
-(defun org-babel-edit-distance (s1 s2)
-  "Return the edit (levenshtein) distance between strings S1 S2."
-  (let* ((l1 (length s1))
-        (l2 (length s2))
-        (dist (vconcat (mapcar (lambda (_) (make-vector (1+ l2) nil))
-                               (number-sequence 1 (1+ l1)))))
-        (in (lambda (i j) (aref (aref dist i) j))))
-    (setf (aref (aref dist 0) 0) 0)
-    (dolist (j (number-sequence 1 l2))
-      (setf (aref (aref dist 0) j) j))
-    (dolist (i (number-sequence 1 l1))
-      (setf (aref (aref dist i) 0) i)
-      (dolist (j (number-sequence 1 l2))
-       (setf (aref (aref dist i) j)
-             (min
-              (1+ (funcall in (1- i) j))
-              (1+ (funcall in i (1- j)))
-              (+ (if (equal (aref s1 (1- i)) (aref s2 (1- j))) 0 1)
-                 (funcall in (1- i) (1- j)))))))
-    (funcall in l1 l2)))
-
 (defun org-babel-combine-header-arg-lists (original &rest others)
   "Combine a number of lists of header argument names and arguments."
   (let ((results (copy-sequence original)))
@@ -858,7 +837,7 @@ arguments and pop open the results in a preview buffer."
                                   (match-string 4))))))
       (dolist (name names)
        (when (and (not (string= header name))
-                  (<= (org-babel-edit-distance header name) too-close)
+                  (<= (org-string-distance header name) too-close)
                   (not (member header names)))
          (error "Supplied header \"%S\" is suspiciously close to \"%S\""
                 header name))))
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 112aa64..2a3bc65 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -119,6 +119,32 @@ extension beyond end of line was not controllable."
   (when (fboundp 'set-face-extend)
     (mapc (lambda (f) (set-face-extend f extend-p)) faces)))
 
+(if (fboundp 'string-distance)
+    (defalias 'org-string-distance 'string-distance)
+  (defun org-string-distance (s1 s2)
+    "Return the edit (levenshtein) distance between strings S1 S2."
+    (let* ((l1 (length s1))
+          (l2 (length s2))
+          (dist (vconcat (mapcar (lambda (_) (make-vector (1+ l2) nil))
+                                 (number-sequence 1 (1+ l1)))))
+          (in (lambda (i j) (aref (aref dist i) j))))
+      (setf (aref (aref dist 0) 0) 0)
+      (dolist (j (number-sequence 1 l2))
+        (setf (aref (aref dist 0) j) j))
+      (dolist (i (number-sequence 1 l1))
+        (setf (aref (aref dist i) 0) i)
+        (dolist (j (number-sequence 1 l2))
+         (setf (aref (aref dist i) j)
+               (min
+                (1+ (funcall in (1- i) j))
+                (1+ (funcall in i (1- j)))
+                (+ (if (equal (aref s1 (1- i)) (aref s2 (1- j))) 0 1)
+                   (funcall in (1- i) (1- j)))))))
+      (funcall in l1 l2))))
+
+(define-obsolete-function-alias 'org-babel-edit-distance 'org-string-distance
+  "Org 9.5")
+
 
 ;;; Emacs < 26.1 compatibility
 



reply via email to

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