[Top][All Lists]

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

Re: Adding String to Beginning of Lines

From: Michael Heerdegen
Subject: Re: Adding String to Beginning of Lines
Date: Tue, 10 Nov 2020 20:42:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis <> writes:

> User can choose to have "" regex as also plain function allows is.
> (string-match "" "something")
> If it is "" it is not nil, it would be chosen.
> If it is nil it would not be chosen.
> Is that right? Do you think it is necessary more than just `or'?

You are right with everything.  But in the meantime I had found out that
the string is actually used as the prefix to prepend to the lines, not
as a regexp.  So an empty string here likely indicates that the user
wants to use the default instead.

> Afterthoughts:
> I do not link that string-empty-p function
> (string-empty-p nil) => nil
> It is not logical to me. I was even surprised to find it just
> yesterday because I had my own function.

If the arguments don't fit the specification anything may happen.  Just
that is the case here I would say.  There is no implicit type check.

If you look at the definition:

(defsubst string-empty-p (string)
  "Check whether STRING is empty."
  (string= string ""))

and check the doc of `string=' you'll see that for symbols (like `nil')
their name is used as string.  This is surely not useful for
`string-empty-p', but thus a symbol which has the empty string as name
(the interned one has a reader syntax "##") fulfills the predicate:

(string-empty-p '##) ==> t

No, that's not useful, just a side effect of the implementation.

| (defun rcd-string-empty-p (s)
|   "Returns T if string is empty or NIL"
|   (let ((s (if (null s) "" s)))
|     (if (stringp s)
|       (if (zerop (length s)) t nil))))

That's more or less the same as

(defun rcd-string-empty-p (s)
  (or (null s) (and (stringp s) (zerop (length s)))))

But why handling an empty list specially, and not other empty sequences,
like the empty vector?  That's what `seq-empty-p' in seq.el does, btw.



reply via email to

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