emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r110851: New property dynamic-docstri


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110851: New property dynamic-docstring-function for docstrings.
Date: Thu, 08 Nov 2012 23:10:16 -0500
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110851
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Thu 2012-11-08 23:10:16 -0500
message:
  New property dynamic-docstring-function for docstrings.
  * src/doc.c (Fdocumentation): Handle new property
  dynamic-docstring-function to replace the old ad-advice-info.
  * lisp/emacs-lisp/advice.el: Use new dynamic docstrings.
  (ad-make-advised-definition-docstring, ad-advised-definition-p):
  Use dynamic-docstring-function instead of ad-advice-info.
  (ad--make-advised-docstring): New function extracted from
  ad-make-advised-docstring.
  (ad-make-advised-docstring): Use it.
  * lisp/progmodes/sql.el (sql--make-help-docstring): New function, extracted
  from sql-help.
  (sql-help): Use it with dynamic-docstring-function.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/emacs-lisp/advice.el
  lisp/progmodes/sql.el
  src/ChangeLog
  src/doc.c
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2012-11-03 19:14:22 +0000
+++ b/etc/NEWS  2012-11-09 04:10:16 +0000
@@ -29,6 +29,10 @@
 * New Modes and Packages in Emacs 24.4
 * Incompatible Lisp Changes in Emacs 24.4
 * Lisp changes in Emacs 24.4
+
+** Docstrings can be made dynamic by adding a `dynamic-docstring-function'
+text-property on the first char.
+
 * Changes in Emacs 24.4 on non-free operating systems
 
 

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-11-09 01:31:54 +0000
+++ b/lisp/ChangeLog    2012-11-09 04:10:16 +0000
@@ -1,5 +1,15 @@
 2012-11-09  Stefan Monnier  <address@hidden>
 
+       * emacs-lisp/advice.el: Use new dynamic docstrings.
+       (ad-make-advised-definition-docstring, ad-advised-definition-p):
+       Use dynamic-docstring-function instead of ad-advice-info.
+       (ad--make-advised-docstring): New function extracted from
+       ad-make-advised-docstring.
+       (ad-make-advised-docstring): Use it.
+       * progmodes/sql.el (sql--make-help-docstring): New function, extracted
+       from sql-help.
+       (sql-help): Use it with dynamic-docstring-function.
+
        * env.el (env--substitute-vars-regexp): Don't use rx (for bootstrap).
 
 2012-11-08  Stefan Monnier  <address@hidden>

=== modified file 'lisp/emacs-lisp/advice.el'
--- a/lisp/emacs-lisp/advice.el 2012-10-26 18:01:30 +0000
+++ b/lisp/emacs-lisp/advice.el 2012-11-09 04:10:16 +0000
@@ -2414,13 +2414,15 @@
                    (if (ad-interactive-form definition) 1 0))
                 (cdr (cdr (ad-lambda-expression definition)))))))
 
-(defun ad-make-advised-definition-docstring (function)
+(defun ad-make-advised-definition-docstring (_function)
   "Make an identifying docstring for the advised definition of FUNCTION.
 Put function name into the documentation string so we can infer
 the name of the advised function from the docstring.  This is needed
 to generate a proper advised docstring even if we are just given a
 definition (see the code for `documentation')."
-  (propertize "Advice doc string" 'ad-advice-info function))
+  (eval-when-compile
+    (propertize "Advice doc string" 'dynamic-docstring-function
+                #'ad--make-advised-docstring)))
 
 (defun ad-advised-definition-p (definition)
   "Return non-nil if DEFINITION was generated from advice information."
@@ -2429,7 +2431,7 @@
          (ad-compiled-p definition))
       (let ((docstring (ad-docstring definition)))
        (and (stringp docstring)
-            (get-text-property 0 'ad-advice-info docstring)))))
+            (get-text-property 0 'dynamic-docstring-function docstring)))))
 
 (defun ad-definition-type (definition)
   "Return symbol that describes the type of DEFINITION."
@@ -2752,6 +2754,13 @@
 (require 'help-fns)        ;For help-split-fundoc and help-add-fundoc-usage.
 
 (defun ad-make-advised-docstring (function &optional style)
+  (let* ((origdef (ad-real-orig-definition function))
+        (origdoc
+         ;; Retrieve raw doc, key substitution will be taken care of later:
+         (ad-real-documentation origdef t)))
+    (ad--make-advised-docstring origdoc function style)))
+
+(defun ad--make-advised-docstring (origdoc function &optional style)
   "Construct a documentation string for the advised FUNCTION.
 It concatenates the original documentation with the documentation
 strings of the individual pieces of advice which will be formatted
@@ -2761,9 +2770,6 @@
 in any of these classes."
   (let* ((origdef (ad-real-orig-definition function))
         (origtype (symbol-name (ad-definition-type origdef)))
-        (origdoc
-         ;; Retrieve raw doc, key substitution will be taken care of later:
-         (ad-real-documentation origdef t))
         (usage (help-split-fundoc origdoc function))
         paragraphs advice-docstring ad-usage)
     (setq usage (if (null usage) t (setq origdoc (cdr usage)) (car usage)))
@@ -2780,7 +2786,9 @@
                      (propertize
                       ;; separate paragraphs with blank lines:
                       (mapconcat 'identity (nreverse paragraphs) "\n\n")
-                      'ad-advice-info function)))
+                       ;; FIXME: what is this for?
+                      'dynamic-docstring-function
+                       #'ad--make-advised-docstring)))
     (help-add-fundoc-usage origdoc usage)))
 
 (defun ad-make-plain-docstring (function)

=== modified file 'lisp/progmodes/sql.el'
--- a/lisp/progmodes/sql.el     2012-09-17 05:41:04 +0000
+++ b/lisp/progmodes/sql.el     2012-11-09 04:10:16 +0000
@@ -2802,8 +2802,12 @@
     doc))
 
 ;;;###autoload
-(defun sql-help ()
-  "Show short help for the SQL modes.
+(eval
+ ;; FIXME: This dynamic-docstring-function trick doesn't work for byte-compiled
+ ;; functions, because of the lazy-loading of docstrings, which strips away
+ ;; text properties.
+ '(defun sql-help ()
+  #("Show short help for the SQL modes.
 
 Use an entry function to open an interactive SQL buffer.  This buffer is
 usually named `*SQL*'.  The name of the major mode is SQLi.
@@ -2834,32 +2838,23 @@
 In this SQL buffer (SQL mode), you can send the region or the entire
 buffer to the interactive SQL buffer (SQLi mode).  The results are
 appended to the SQLi buffer without disturbing your SQL buffer."
+    0 1 (dynamic-docstring-function sql--make-help-docstring))
   (interactive)
-
-  ;; Insert references to loaded products into the help buffer string
-  (let ((doc (documentation 'sql-help t))
-       changedp)
-    (setq changedp nil)
-
-    ;; Insert FREE software list
-    (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]FREE\\s-*\n" doc 0)
-      (setq doc (replace-match (sql-help-list-products (match-string 1 doc) t)
-                              t t doc 0)
-           changedp t))
-
-    ;; Insert non-FREE software list
-    (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]NONFREE\\s-*\n" doc 0)
-      (setq doc (replace-match (sql-help-list-products (match-string 1 doc) 
nil)
-                              t t doc 0)
-           changedp t))
-
-    ;; If we changed the help text, save the change so that the help
-    ;; sub-system will see it
-    (when changedp
-      (put 'sql-help 'function-documentation doc)))
-
-  ;; Call help on this function
-  (describe-function 'sql-help))
+  (describe-function 'sql-help)))
+
+(defun sql--make-help-docstring (doc _fun)
+  "Insert references to loaded products into the help buffer string."
+
+  ;; Insert FREE software list
+  (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]FREE\\s-*\n" doc 0)
+    (setq doc (replace-match (sql-help-list-products (match-string 1 doc) t)
+                             t t doc 0)))
+
+  ;; Insert non-FREE software list
+  (when (string-match "^\\(\\s-*\\)[\\\\][\\\\]NONFREE\\s-*\n" doc 0)
+    (setq doc (replace-match (sql-help-list-products (match-string 1 doc) nil)
+                             t t doc 0)))
+  doc)
 
 (defun sql-read-passwd (prompt &optional default)
   "Read a password using PROMPT.  Optional DEFAULT is password to start with."

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-11-09 00:08:12 +0000
+++ b/src/ChangeLog     2012-11-09 04:10:16 +0000
@@ -1,3 +1,8 @@
+2012-11-09  Stefan Monnier  <address@hidden>
+
+       * doc.c (Fdocumentation): Handle new property
+       dynamic-docstring-function to replace the old ad-advice-info.
+
 2012-11-09  Paul Eggert  <address@hidden>
 
        * fns.c (Qeql, hashtest_eq): Now static.

=== modified file 'src/doc.c'
--- a/src/doc.c 2012-10-12 20:11:50 +0000
+++ b/src/doc.c 2012-11-09 04:10:16 +0000
@@ -21,7 +21,7 @@
 #include <config.h>
 
 #include <sys/types.h>
-#include <sys/file.h>  /* Must be after sys/types.h for USG*/
+#include <sys/file.h>  /* Must be after sys/types.h for USG.  */
 #include <fcntl.h>
 #include <unistd.h>
 
@@ -42,7 +42,7 @@
 
 static unsigned char *read_bytecode_pointer;
 
-/* readchar in lread.c calls back here to fetch the next byte.
+/* `readchar' in lread.c calls back here to fetch the next byte.
    If UNREADFLAG is 1, we unread a byte.  */
 
 int
@@ -338,15 +338,9 @@
 
   doc = Qnil;
 
-  if (SYMBOLP (function))
-    {
-      Lisp_Object tem = Fget (function, Qfunction_documentation);
-      if (!NILP (tem))
-       return Fdocumentation_property (function, Qfunction_documentation,
-                                       raw);
-    }
-
   fun = Findirect_function (function, Qnil);
+  if (CONSP (fun) && EQ (XCAR (fun), Qmacro))
+    fun = XCDR (fun);
   if (SUBRP (fun))
     {
       if (XSUBR (fun)->doc == 0)
@@ -400,8 +394,6 @@
          else
            return Qnil;
        }
-      else if (EQ (funcar, Qmacro))
-       return Fdocumentation (Fcdr (fun), raw);
       else
        goto oops;
     }
@@ -411,16 +403,19 @@
       xsignal1 (Qinvalid_function, fun);
     }
 
-  /* Check for an advised function.  Its doc string
-     has an `ad-advice-info' text property.  */
+  /* Check for a dynamic docstring.  These come with
+     a dynamic-docstring-function text property.  */
   if (STRINGP (doc))
     {
-      Lisp_Object innerfunc;
-      innerfunc = Fget_text_property (make_number (0),
-                                     intern ("ad-advice-info"),
+      Lisp_Object func
+       = Fget_text_property (make_number (0),
+                             intern ("dynamic-docstring-function"),
                                      doc);
-      if (! NILP (innerfunc))
-       doc = call1 (intern ("ad-make-advised-docstring"), innerfunc);
+      if (!NILP (func))
+       /* Pass both `doc' and `function' since `function' can be needed, and
+          finding `doc' can be annoying: calling `documentation' is not an
+          option because it would infloop.  */
+       doc = call2 (func, doc, function);
     }
 
   /* If DOC is 0, it's typically because of a dumped file missing
@@ -528,6 +523,8 @@
        {
          tem = Fcdr (Fcdr (fun));
          if (CONSP (tem) && INTEGERP (XCAR (tem)))
+           /* FIXME: This modifies typically pure hash-cons'd data, so its
+              correctness is quite delicate.  */
            XSETCAR (tem, make_number (offset));
        }
       else if (EQ (tem, Qmacro))


reply via email to

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