From: Mattias EngdegÄrd Date: Fri, 13 Oct 2023 13:21:26 +0000 (+0200) Subject: Add convenience wrapper for regexp disassembly X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=77daafbb3657d301f864b969cdfe8da17ab5a62d;p=emacs.git Add convenience wrapper for regexp disassembly * lisp/emacs-lisp/disass.el (re-disassemble): New. * etc/NEWS: Describe the new function instead of the internal `re--describe-compiled`. --- diff --git a/etc/NEWS b/etc/NEWS index 0e93faebb84..0f9b5f98ebf 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1018,7 +1018,7 @@ Use 'define-minor-mode' and 'define-globalized-minor-mode' instead. * Lisp Changes in Emacs 30.1 -** New function 're--describe-compiled' to see the innards of a regexp. +** New function 're-disassemble' to see the innards of a regexp. If you compiled with '--enable-checking', you can use this to help debug either your regexp performance problems or the regexp engine. diff --git a/lisp/emacs-lisp/disass.el b/lisp/emacs-lisp/disass.el index 73777d7e701..d9295686e9f 100644 --- a/lisp/emacs-lisp/disass.el +++ b/lisp/emacs-lisp/disass.el @@ -301,6 +301,23 @@ OBJ should be a call to BYTE-CODE generated by the byte compiler." (insert "\n"))))) nil) +(defun re-disassemble (regexp &optional case-table) + "Describe the compiled form of REGEXP in a separate window. +If CASE-TABLE is non-nil, use it as translation table for case-folding. + +This function is mainly intended for maintenance of Emacs itself +and may change at any time. It requires Emacs to be built with +`--enable-checking'." + (interactive "XRegexp (Lisp expression): ") + (let ((desc (with-temp-buffer + (when case-table + (set-case-table case-table)) + (let ((case-fold-search (and case-table t))) + (re--describe-compiled regexp))))) + (with-output-to-temp-buffer "*Regexp-disassemble*" + (with-current-buffer standard-output + (insert desc))))) + (provide 'disass) ;;; disass.el ends here