bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#35018: 26.1; Use diff as en ert-explainer for string=


From: Noam Postavsky
Subject: bug#35018: 26.1; Use diff as en ert-explainer for string=
Date: Mon, 01 Apr 2019 21:05:01 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.91 (gnu/linux)

severity 35018 wishlist
quit

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> I've just committed webfeeder.el to ELPA.  In his review, Stefan Monnier
> suggested we merged the following code snippet upstream:
>
> (defun webfeeder--string=-explainer (string-a string-b)
>   "Return the diff output of STRING-A and STRING-B"
>   (unless (string= string-a string-b)

I guess a diff won't help so much for single line strings, so maybe the
condition should check for that? e.g.

    (or (string= string-a string-b)
        (not (string-match-p "\n" string-a))
        (not (string-match-p "\n" string-b))

>     (let (file-a file-b)
>       (unwind-protect
>           (let (result)
>             (setq file-a (make-temp-file "webfeeder")
>                   file-b (make-temp-file "webfeeder"))
>             (with-temp-file file-a
>               (insert string-a))
>             (with-temp-file file-b
>               (insert string-b))
>             (setq result
>                   (with-temp-buffer
>                     ;; The following generates a *Diff* buffer which is
>                     ;; convenient for coloration.
>                     (diff file-a file-b nil 'no-async)
>                     (diff-no-select file-a file-b nil 'no-async 
> (current-buffer))

Isn't the diff-no-select redudant, since diff already calls it?

>                     (buffer-string)))
>             result)

You don't need the 'result' variable here, just make the
(with-temp-buffer...) the last expression in the let (which could then
be converted to progn).

>         (delete-file file-a)
>         (delete-file file-b)))))

You should check that each of file-a and file-b are non-nil before
trying to delete (in case either make-temp-file signals an error).





reply via email to

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