emacs-diffs
[Top][All Lists]
Advanced

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

master 8e20da1517a 8/8: Simplify rng-substq with cl-substitute


From: Stefan Kangas
Subject: master 8e20da1517a 8/8: Simplify rng-substq with cl-substitute
Date: Sat, 5 Aug 2023 12:00:12 -0400 (EDT)

branch: master
commit 8e20da1517aa585e6286fa8e439db10fb62aaa57
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>

    Simplify rng-substq with cl-substitute
    
    * lisp/nxml/rng-util.el (rng-substq): Simplify.
    (cl-lib): Require.
---
 lisp/nxml/rng-util.el | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/lisp/nxml/rng-util.el b/lisp/nxml/rng-util.el
index 27c924d960f..4f49885fc45 100644
--- a/lisp/nxml/rng-util.el
+++ b/lisp/nxml/rng-util.el
@@ -24,6 +24,8 @@
 
 ;;; Code:
 
+(require 'cl-lib)
+
 (defun rng-make-datatypes-uri (uri)
   (if (string-equal uri "")
       ;; The spec doesn't say to do this, but it's perfectly conformant
@@ -39,26 +41,7 @@
 (defun rng-substq (new old list)
   "Replace first member of LIST (if any) that is `eq' to OLD by NEW.
 LIST is not modified."
-  (cond ((null list) nil)
-       ((eq (car list) old)
-        (cons new (cdr list)))
-       (t
-        (let ((tail (cons (car list)
-                          nil))
-              (rest (cdr list)))
-          (setq list tail)
-          (while rest
-            (let ((item (car rest)))
-              (setq rest (cdr rest))
-              (cond ((eq item old)
-                     (setcdr tail
-                             (cons new rest))
-                     (setq rest nil))
-                    (t
-                     (setq tail
-                           (setcdr tail
-                                   (cons item nil))))))))
-        list)))
+  (cl-substitute new old list :count 1 :test #'eq))
 
 (defun rng-escape-string (s)
   (replace-regexp-in-string "[&\"<>]"



reply via email to

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