emacs-devel
[Top][All Lists]
Advanced

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

scratch/substitute-command-keys: C conversion of s-c-k


From: Stefan Kangas
Subject: scratch/substitute-command-keys: C conversion of s-c-k
Date: Thu, 20 Aug 2020 17:27:19 -0700

Stefan Kangas <stefan@marxist.se> writes:

> Please find attached the first in a planned series of patches to replace
> `substitute-command-keys' with a Lisp version.
>
> - The goal is to produce byte-for-byte identical output to the old C
>   version.
>
> - This is a more or less direct translation of the C code, and so is not
>   very elegant Lisp.  It turned out to be easier to just "lift" the code
>   from C before working on any improvements.  (The code is not super
>   involved overall, but some details are a bit finicky.)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Please find attached the first in a planned series of patches to replace
>> `substitute-command-keys' with a Lisp version.
>
> The strategy sounds good (I followed basically the same principles in
> various other rewrites from C to Elisp ;-).
>
> I don't know what Eli wants to do, but I think the better option is to
> push this to a branch where you can have this change followed by a few
> others, and when the patches's sum is clean we can merge it to `master`.

[The above discussion apparently never included emacs-devel.]

I now have a working translation of 'substitute-command-keys' from C to
Lisp on the scratch/substitute-command-keys branch.  For more background
see Bug#8951 and other bugs regarding s-c-k.

I have added some defsubrs that could be removed by writing new Lisp
equivalents.  It would be good if I could get advice on which is better
here:

   1) Just leave the defsubrs as is.
   2) Replace them with defun's in help.el and then either:
       a) Accept duplicate code on the C and Lisp level.
       b) Call the Lisp functions from C code, and remove the C
          functions altogether.

I also made some measurements to confirm that we get insubstantial
performance benefits by keepin 'substitute-command-keys' in C:

    (progn
      (with-temp-buffer (org-mode))
      (let* ((times 1000)
             (new (car (benchmark-run times
                         (substitute-command-keys "\\{org-mode-map}"))))
             (old (car (benchmark-run times
                         (substitute-command-keys-old "\\{org-mode-map}")))))
        (/ (- new old) times)))

    => 0.0010306464810000003

Looking around keymap.c got me thinking that maybe there is more stuff
that could be usefully lifted to Lisp there.  Obviously this would only
apply to functions that are called infrequently.  (Perhaps there is even
a case to be made for a new keymap.el where we could put this logically.)

Or maybe this is exactly the point where I stop, remove the C
implementation of 'substitute-command-keys', do some last cleanups, and
get all this merged.

Comments on all this are more than welcome.  Thanks in advance!

Best regards,
Stefan Kangas



reply via email to

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