[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/positioned-lambdas 300d7ff70e8 1/2: Print position info for lamb
From: |
Alan Mackenzie |
Subject: |
feature/positioned-lambdas 300d7ff70e8 1/2: Print position info for lambda functions in C-h v output |
Date: |
Mon, 25 Mar 2024 07:37:11 -0400 (EDT) |
branch: feature/positioned-lambdas
commit 300d7ff70e8bc17579b4df685c4c6606c50b70dc
Author: Alan Mackenzie <acm@muc.de>
Commit: Alan Mackenzie <acm@muc.de>
Print position info for lambda functions in C-h v output
* lisp/custom.el (defcustom): Add a defining-symbol declare
clause so that position info is added to defcustoms.
* lisp/emacs-lisp/cl-print.el (cl-print-pos-info): New
function.
(cl-print-object/cons, cl-print-object/compiled-function): Call
the above new function in place of inline code.
* lisp/help-fns.el (describe-variable): Strip position info
from doc string before printing it.
---
lisp/custom.el | 1 +
lisp/emacs-lisp/cl-print.el | 47 ++++++++++++++++++++++++++++++---------------
lisp/help-fns.el | 3 ++-
3 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/lisp/custom.el b/lisp/custom.el
index a19b14aaf8a..904bd242b1f 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -385,6 +385,7 @@ call that function directly.
See Info node `(elisp) Customization' in the Emacs Lisp manual
for more information."
(declare (doc-string 3) (debug (name body))
+ (defining-symbol symbol doc t)
(indent defun))
;; It is better not to use backquote in this file,
;; because that makes a bootstrapping problem
diff --git a/lisp/emacs-lisp/cl-print.el b/lisp/emacs-lisp/cl-print.el
index bb3ed2c89c1..4c3a89ab791 100644
--- a/lisp/emacs-lisp/cl-print.el
+++ b/lisp/emacs-lisp/cl-print.el
@@ -42,6 +42,33 @@
"Depth of recursion within cl-print functions.
Compared to `print-level' to determine when to stop recursing.")
+(defun cl-print-pos-info (doc-string stream)
+ "Print the position info contained in DOC-STRING.
+STREAM is the output stream to write to.
+
+The info is written enclosed in braces. Currently (2024-03), the
+defining symbol is printed, if present. Otherwise, the buffer name
+together with an offset (the lambda offset, if present) are printed.
+
+If DOC-STRING contains no position info, this fuction does nothing."
+ (let ((pos-info (byte-run-position-vec doc-string)))
+ (when (vectorp pos-info)
+ (let ((defsym (aref pos-info 0))
+ (posbuf (aref pos-info 1))
+ (pos-ds-pos (aref pos-info 2))
+ (pos-lambda-pos (aref pos-info 3)))
+ (princ "{" stream)
+ (if defsym
+ (prin1 defsym stream)
+ (when posbuf
+ (prin1 posbuf stream)
+ (princ " " stream))
+ (cond
+ (pos-lambda-pos
+ (prin1 pos-lambda-pos stream))
+ (pos-ds-pos
+ (prin1 pos-ds-pos stream))))
+ (princ "} " stream)))))
;;;###autoload
(cl-defgeneric cl-print-object (object stream)
@@ -67,14 +94,8 @@ Print the contents hidden by the ellipsis to STREAM."
(cl-defmethod cl-print-object ((object cons) stream)
(when (memq (car object) '(lambda closure))
- (let* ((doc-string (documentation object 'also-pos))
- (pos-info (byte-run-position-vec doc-string))
- (defsym (and (vectorp pos-info)
- (aref pos-info 0))))
- (when defsym
- (princ "{" stream)
- (prin1 defsym stream)
- (princ "} " stream))))
+ (let ((doc-string (documentation object 'also-pos)))
+ (cl-print-pos-info doc-string stream)))
(if (and cl-print--depth (natnump print-level)
(> cl-print--depth print-level))
(cl-print-insert-ellipsis object nil stream)
@@ -193,14 +214,8 @@ into a button whose action shows the function's
disassembly.")
(unless stream (setq stream standard-output))
;; We use "#f(...)" rather than "#<...>" so that pp.el gives better results.
(let* ((args (help-function-arglist object 'preserve-names))
- (doc-string (documentation object 'also-pos))
- (pos-info (byte-run-position-vec doc-string))
- (defsym (and (vectorp pos-info)
- (aref pos-info 0))))
- (when defsym
- (princ "{" stream)
- (prin1 defsym stream)
- (princ "} " stream))
+ (doc-string (documentation object 'also-pos)))
+ (cl-print-pos-info doc-string stream)
(princ "#f(compiled-function " stream)
(if args
(prin1 args stream)
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index a291893e9a2..7f452eab671 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -1462,7 +1462,8 @@ it is displayed along with the global value."
(with-current-buffer standard-output
(help-fns--var-obsolete variable)
- (insert (or doc "Not documented as a variable.")))
+ (insert (or (help-strip-pos-info doc)
+ "Not documented as a variable.")))
;; Output the indented administrative bits.
(with-current-buffer buffer