]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve the *Help* output for compiler macros and the like
authorLars Ingebrigtsen <larsi@gnus.org>
Sat, 14 May 2022 02:06:32 +0000 (04:06 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 14 May 2022 02:13:56 +0000 (04:13 +0200)
* doc/lispref/functions.texi (Advice and Byte Code): New node.

* lisp/help-fns.el (help-fns--compiler-macro): Also output data on
other byte compilation things, and link to the manual (bug#23264).

doc/lispref/elisp.texi
doc/lispref/functions.texi
lisp/help-fns.el

index 426bb6d01760842ee6a32091456e9f87cde02668..968a2790e21aca1004392654539a7d3dd8b9f9ba 100644 (file)
@@ -592,6 +592,7 @@ Advising Emacs Lisp Functions
 * Advising Named Functions::  Advising named functions.
 * Advice Combinators::        Ways to compose advice.
 * Porting Old Advice::        Adapting code using the old defadvice.
+* Advice and Byte Code::      Not all functions can be advised.
 
 Macros
 
index 55bbf8fd5a201bea0703e176a96f3755708f501f..df50a627aa3927ba1651d53d767b0f014ff4bf14 100644 (file)
@@ -1717,6 +1717,7 @@ ways to do it.  The added function is also called a piece of @emph{advice}.
 * Advising Named Functions::    Advising named functions.
 * Advice Combinators::          Ways to compose advice.
 * Porting Old Advice::          Adapting code using the old defadvice.
+* Advice and Byte Code::        Not all functions can be advised.
 @end menu
 
 @node Core Advising Primitives
@@ -2138,6 +2139,38 @@ changing @code{ad-return-value}, whereas new @code{:after} advice cannot, so
 when porting such old @code{after} advice, you'll need to turn it into new
 @code{:around} or @code{:filter-return} advice instead.
 
+@c This is its own node because we link to it from *Help* buffers.
+@node Advice and Byte Code
+@subsection Advice and Byte Code
+@cindex compiler macros, advising
+@cindex @code{byte-compile}, advising
+@cindex @code{byte-optimizer}, advising
+
+  Not all functions can be reliably advised.  The byte compiler may
+choose to replace a call to a function with a sequence of instructions
+that doesn't include the function call to the function you were
+interested in altering.
+
+This usually happens due to one of the three following mechanisms:
+
+@table @dfn
+@item @code{byte-compile} properties
+If function @var{symbol} has a @code{byte-compile} property, that
+property will be used instead of @var{symbol}'s definition.
+@xref{Compilation Functions}.
+
+@item @code{byte-optimize} properties
+If function @var{symbol} has a @code{byte-compile} property, the byte
+compiler may rewrite the function arguments, or decide to use a
+different function altogether.
+
+@item compiler macros
+Compiler macros are defined using a special @code{declare} form.  This
+tells the compiler to use the defined @dfn{expander} as an
+optimization function, and it can return a new expression to use
+instead of the function call.  @xref{Declare Form}.
+@end table
+
 @node Obsolete Functions
 @section Declaring Functions Obsolete
 @cindex obsolete functions
index 927a4f0d2c4250ab2b53a19c9dc0e2d29bcdc71f..d5f6a7b0bec3aafefe29f5bbc6f5905ffaaf95e1 100644 (file)
@@ -614,9 +614,18 @@ the C sources, too."
    menus))
 
 (defun help-fns--compiler-macro (function)
-  (let ((handler (function-get function 'compiler-macro)))
+  (pcase-dolist (`(,type . ,handler)
+                 (list (cons "compiler macro"
+                             (function-get function 'compiler-macro))
+                       (cons "`byte-compile' property"
+                             (function-get function 'byte-compile))
+                       (cons "byte-code optimizer"
+                             (function-get function 'byte-optimizer))))
     (when handler
-      (insert "  This function has a compiler macro")
+      (if (bolp)
+          (insert "  This function has a ")
+        (insert " and a "))
+      (insert type)
       (if (symbolp handler)
           (progn
             (insert (format-message " `%s'" handler))
@@ -631,8 +640,17 @@ the C sources, too."
             (save-excursion
               (re-search-backward (substitute-command-keys "`\\([^`']+\\)'")
                                   nil t)
-              (help-xref-button 1 'help-function-cmacro function lib)))))
-      (insert ".\n"))))
+              (help-xref-button 1 'help-function-cmacro function lib)))))))
+  (unless (bolp)
+    (insert ".  See "
+            (buttonize "the manual"
+                       (lambda (_) (info "(elisp)Advice and Byte Code")))
+            " for details.\n")
+    (save-restriction
+      (let ((fill-prefix "    "))
+        (narrow-to-region (line-beginning-position -1) (point))
+        (fill-region (point-min) (point-max)))
+      (goto-char (point-max)))))
 
 (defun help-fns--signature (function doc real-def real-function buffer)
   "Insert usage at point and return docstring.  With highlighting."