unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: 25461@debbugs.gnu.org
Subject: bug#25461: [Patch]: Missing doc strings for "," and ",@".
Date: Wed, 18 Jan 2017 19:43:20 +0000	[thread overview]
Message-ID: <20170118194320.GB4108@acm.fritz.box> (raw)
In-Reply-To: <handler.25461.B.148460180922707.ack@debbugs.gnu.org>

Hello, Emacs.

On Mon, Jan 16, 2017 at 09:24:02PM +0000, GNU bug Tracking System wrote:
> Thank you for filing a new bug report with debbugs.gnu.org.

[ .... ]

Thanks for the comments, so far.  Here is a patch which gives , and ,@
doc strings.  It also creates a mechanism by which other reader macros
(such as ' and #') can be given doc strings later.

I'll just point out one thing I'm proposing changing.  That is, to use
princ rather than prin1 to print the name of the function.  This causes,
for example, backtick to be printed as

    `

rather than the

    \`

we get at the moment.  This might cause problems for function names
which include backslashes or unprintable characters such as \n.

Are there objections to me installing the patch in master?



diff --git a/lisp/emacs-lisp/backquote.el b/lisp/emacs-lisp/backquote.el
index 94c561c..86ca010 100644
--- a/lisp/emacs-lisp/backquote.el
+++ b/lisp/emacs-lisp/backquote.el
@@ -247,4 +247,33 @@ backquote-listify
 	tail))
      (t (cons 'list heads)))))
 
+\f
+;; Give `,' and `,@' documentation strings which can be examined by C-h f.
+(put '\, 'function-documentation
+     "`,' signals that the next form should be evaluated and inserted.
+It can occur only in `\\=`' constructs.
+
+For example:
+
+b              => (ba bb bc)		; assume b has this value
+\\=`(a ,b c)      => (a (ba bb bc) c)	; insert the value of b
+
+See also `\\=`' and `,@'.
+
+Note that `,' is also used by the macro `pcase' and the like,
+with radically different semantics.")
+(put '\, 'reader-macro t)
+
+(put '\,@ 'function-documentation
+     ",@ signals that the next form should be evaluated and spliced in.
+It can occur only in `\\=`' constructs.
+
+For example:
+
+b              => (ba bb bc)		; assume b has this value
+\\=`(a ,@b c)     => (a ba bb bc c)	; splice in the value of b
+
+See also `\\=`' and `,'.")
+(put '\,@ 'reader-macro t)
+
 ;;; backquote.el ends here
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index fa16fa0..069dc3c 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -115,13 +115,15 @@ describe-function
                 (if fn
                     (format "Describe function (default %s): " fn)
                   "Describe function: ")
-                #'help--symbol-completion-table #'fboundp t nil nil
+                #'help--symbol-completion-table
+                (lambda (f) (or (fboundp f) (get f 'function-documentation)))
+                t nil nil
                 (and fn (symbol-name fn)))))
      (unless (equal val "")
        (setq fn (intern val)))
      (unless (and fn (symbolp fn))
        (user-error "You didn't specify a function symbol"))
-     (unless (fboundp fn)
+     (unless (or (fboundp fn) (get fn 'function-documentation))
        (user-error "Symbol's function definition is void: %s" fn))
      (list fn)))
 
@@ -144,7 +146,7 @@ describe-function
 
     (save-excursion
       (with-help-window (help-buffer)
-        (prin1 function)
+        (princ function)
         ;; Use " is " instead of a colon so that
         ;; it is easier to get out the function name using forward-sexp.
         (princ " is ")
@@ -469,7 +471,8 @@ help-fns--signature
         (let ((fill-begin (point))
               (high-usage (car high))
               (high-doc (cdr high)))
-          (insert high-usage "\n")
+          (unless (get function 'reader-macro)
+            (insert high-usage "\n"))
           (fill-region fill-begin (point))
           high-doc)))))
 
@@ -565,18 +568,23 @@ describe-function-1
 	  (or (and advised
                    (advice--cd*r (advice--symbol-function function)))
 	      function))
-	 ;; Get the real definition.
-	 (def (if (symbolp real-function)
-		  (or (symbol-function real-function)
-		      (signal 'void-function (list real-function)))
-		real-function))
-	 (aliased (or (symbolp def)
-		      ;; Advised & aliased function.
-		      (and advised (symbolp real-function)
-			   (not (eq 'autoload (car-safe def))))
-                      (and (subrp def)
-                           (not (string= (subr-name def)
-                                         (symbol-name function))))))
+	 ;; Get the real definition, if any.
+	 (def (cond ((and (symbolp real-function)
+                          (symbol-function real-function)))
+                    ((and (symbolp real-function)
+                          (get real-function 'function-documentation))
+                     nil)
+                    ((symbolp real-function)
+                     (signal 'void-function (list real-function)))
+                    (t real-function)))
+	 (aliased (and def
+                       (or (symbolp def)
+                           ;; Advised & aliased function.
+                           (and advised (symbolp real-function)
+                                (not (eq 'autoload (car-safe def))))
+                           (and (subrp def)
+                                (not (string= (subr-name def)
+                                              (symbol-name function)))))))
 	 (real-def (cond
                     ((and aliased (not (subrp def)))
                      (let ((f real-function))
@@ -605,6 +613,8 @@ describe-function-1
     ;; Print what kind of function-like object FUNCTION is.
     (princ (cond ((or (stringp def) (vectorp def))
 		  "a keyboard macro")
+		 ((get function 'reader-macro)
+                  "a reader macro")
 		 ;; Aliases are Lisp functions, so we need to check
 		 ;; aliases before functions.
 		 (aliased


-- 
Alan Mackenzie (Nuremberg, Germany).





  parent reply	other threads:[~2017-01-18 19:43 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-16 21:22 bug#25461: Missing doc strings for "," and ",@" Alan Mackenzie
2017-01-17 19:34 ` Glenn Morris
2017-01-17 19:56   ` Alan Mackenzie
2017-01-17 20:36     ` Andreas Schwab
2017-01-17 20:41       ` Alan Mackenzie
2017-01-17 20:53         ` Andreas Schwab
2017-01-18  1:44         ` Michael Heerdegen
2017-01-18 19:28           ` Alan Mackenzie
     [not found] ` <handler.25461.B.148460180922707.ack@debbugs.gnu.org>
2017-01-18 19:43   ` Alan Mackenzie [this message]
2017-01-19  0:16     ` bug#25461: [Patch]: " npostavs
2017-01-19 17:37       ` Alan Mackenzie
2017-01-19 18:10         ` Noam Postavsky
2017-01-19 18:36           ` Alan Mackenzie
2017-01-20  0:24             ` Michael Heerdegen
2017-01-19  2:23     ` Michael Heerdegen
2017-01-19 17:58       ` Alan Mackenzie
2017-01-20  0:12         ` Michael Heerdegen
2017-01-20 16:58           ` Alan Mackenzie
2017-01-21  2:26             ` Michael Heerdegen
2017-01-21 15:56               ` Alan Mackenzie
2017-01-21 20:46                 ` bug#25461: [Patch #2]: " Alan Mackenzie
2017-01-24  1:58                   ` Michael Heerdegen
2017-01-24 19:43                     ` Alan Mackenzie
2017-01-24  4:01                   ` npostavs
2017-01-24 19:39                     ` Alan Mackenzie
2017-01-24 20:00                       ` Noam Postavsky
2017-01-23 19:09               ` bug#25461: [Patch]: " Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170118194320.GB4108@acm.fritz.box \
    --to=acm@muc.de \
    --cc=25461@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).