[Top][All Lists]

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

Re: Moving kbd to subr.el

From: Stefan Kangas
Subject: Re: Moving kbd to subr.el
Date: Thu, 14 Oct 2021 19:07:34 -0700

Lars Ingebrigtsen <larsi@gnus.org> writes:

> No, just have kbd return a string or a vector according to how it
> behaves now, but if edmacro wants to return a vector, then it converts
> the result to a vector (if it got a string).

OK, so looking even closer at this to develop test cases for the above,
in the original code we have this convoluted mess:

(if (and (not need-vector)
         (cl-loop for ch across res
                  always (and (characterp ch)
                              (let ((ch2 (logand ch (lognot ?\M-\^@))))
                                (and (>= ch2 0) (<= ch2 127))))))
    (concat (cl-loop for ch across res
                     collect (if (= (logand ch ?\M-\^@) 0)
                                 ch (+ ch 128))))

Given that characterp comes down to

    return 0 <= c && c <= MAX_CHAR; // MAX_CHAR = 0x3FFFFF

and that ?\M-\^@ is #x8000000, the `and' clause here simplifies to:

    (and (<= 0 ch #x3fffff)
         (<= 0 (logand ch (lognot #x8000000)) 127))

But that is equivalent to:

    (<= 0 ch 127)

Right?  So what is this code actually supposed to do?

Currently, I'm a bit stomped as in any test case I can think of,
including all tests in the test suite, kbd and edmacro-parse-keys
behaves exactly the same in Emacs 27.2.  Can anyone think of a test case
where they won't?

BTW, you can verify the above simplification for yourself using:

(let ((ch 0) accum)
  (while (< ch #xFFFFFFF)
    (when (and (characterp ch)
               (let ((ch2 (logand ch (lognot ?\M-\^@))))
                 (and (>= ch2 0) (<= ch2 127))))
      (push ch accum))
    (setq ch (1+ ch)))
  (let ((standard-output (current-buffer)))
    (princ accum)))

reply via email to

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