diff options
| author | Stefan Monnier | 2011-08-05 12:31:21 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2011-08-05 12:31:21 -0400 |
| commit | 673e08bbd4209cc234c76c4430cc62924ba3ba49 (patch) | |
| tree | 6cc3be9e92ccd04e1da3d7cbea23b5ceb2ee2a97 | |
| parent | 412b635880c2b907a3c4cb340fbb02b4db78b1aa (diff) | |
| download | emacs-673e08bbd4209cc234c76c4430cc62924ba3ba49.tar.gz emacs-673e08bbd4209cc234c76c4430cc62924ba3ba49.zip | |
* lisp/emacs-lisp/cl-macs.el (cl--make-usage-var, cl--make-usage-args):
New functions.
(cl-transform-lambda): Use them.
Fixes: debbugs:9239
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-loaddefs.el | 2 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 38 | ||||
| -rw-r--r-- | lisp/help-fns.el | 11 |
4 files changed, 44 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2e8240b41bb..16ba0d34f02 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2011-08-05 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/cl-macs.el (cl--make-usage-var, cl--make-usage-args): | ||
| 4 | New functions. | ||
| 5 | (cl-transform-lambda): Use them (bug#9239). | ||
| 6 | |||
| 1 | 2011-08-05 Martin Rudalics <rudalics@gmx.at> | 7 | 2011-08-05 Martin Rudalics <rudalics@gmx.at> |
| 2 | 8 | ||
| 3 | * window.el (display-buffer-same-window) | 9 | * window.el (display-buffer-same-window) |
diff --git a/lisp/emacs-lisp/cl-loaddefs.el b/lisp/emacs-lisp/cl-loaddefs.el index 4b9985380c3..7beb4d4b4cc 100644 --- a/lisp/emacs-lisp/cl-loaddefs.el +++ b/lisp/emacs-lisp/cl-loaddefs.el | |||
| @@ -282,7 +282,7 @@ Not documented | |||
| 282 | ;;;;;; flet progv psetq do-all-symbols do-symbols dotimes dolist | 282 | ;;;;;; flet progv psetq do-all-symbols do-symbols dotimes dolist |
| 283 | ;;;;;; do* do loop return-from return block etypecase typecase ecase | 283 | ;;;;;; do* do loop return-from return block etypecase typecase ecase |
| 284 | ;;;;;; case load-time-value eval-when destructuring-bind function* | 284 | ;;;;;; case load-time-value eval-when destructuring-bind function* |
| 285 | ;;;;;; defmacro* defun* gentemp gensym) "cl-macs" "cl-macs.el" "21df83d6106cb0c3d037e75ad79359dc") | 285 | ;;;;;; defmacro* defun* gentemp gensym) "cl-macs" "cl-macs.el" "0907093f7720996444ededb4edfe8072") |
| 286 | ;;; Generated autoloads from cl-macs.el | 286 | ;;; Generated autoloads from cl-macs.el |
| 287 | 287 | ||
| 288 | (autoload 'gensym "cl-macs" "\ | 288 | (autoload 'gensym "cl-macs" "\ |
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 6d242eda3ab..fb19115287c 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el | |||
| @@ -238,6 +238,37 @@ It is a list of elements of the form either: | |||
| 238 | 238 | ||
| 239 | (declare-function help-add-fundoc-usage "help-fns" (docstring arglist)) | 239 | (declare-function help-add-fundoc-usage "help-fns" (docstring arglist)) |
| 240 | 240 | ||
| 241 | (defun cl--make-usage-var (x) | ||
| 242 | "X can be a var or a (destructuring) lambda-list." | ||
| 243 | (cond | ||
| 244 | ((symbolp x) (make-symbol (upcase (symbol-name x)))) | ||
| 245 | ((consp x) (cl--make-usage-args x)) | ||
| 246 | (t x))) | ||
| 247 | |||
| 248 | (defun cl--make-usage-args (arglist) | ||
| 249 | ;; `orig-args' can contain &cl-defs (an internal | ||
| 250 | ;; CL thingy I don't understand), so remove it. | ||
| 251 | (let ((x (memq '&cl-defs arglist))) | ||
| 252 | (when x (setq arglist (delq (car x) (remq (cadr x) arglist))))) | ||
| 253 | (let ((state nil)) | ||
| 254 | (mapcar (lambda (x) | ||
| 255 | (cond | ||
| 256 | ((symbolp x) | ||
| 257 | (if (eq ?\& (aref (symbol-name x) 0)) | ||
| 258 | (setq state x) | ||
| 259 | (make-symbol (upcase (symbol-name x))))) | ||
| 260 | ((not (consp x)) x) | ||
| 261 | ((memq state '(nil &rest)) (cl--make-usage-args x)) | ||
| 262 | (t ;(VAR INITFORM SVAR) or ((KEYWORD VAR) INITFORM SVAR). | ||
| 263 | (list* | ||
| 264 | (if (and (consp (car x)) (eq state '&key)) | ||
| 265 | (list (caar x) (cl--make-usage-var (nth 1 (car x)))) | ||
| 266 | (cl--make-usage-var (car x))) | ||
| 267 | (nth 1 x) ;INITFORM. | ||
| 268 | (cl--make-usage-args (nthcdr 2 x)) ;SVAR. | ||
| 269 | )))) | ||
| 270 | arglist))) | ||
| 271 | |||
| 241 | (defun cl-transform-lambda (form bind-block) | 272 | (defun cl-transform-lambda (form bind-block) |
| 242 | (let* ((args (car form)) (body (cdr form)) (orig-args args) | 273 | (let* ((args (car form)) (body (cdr form)) (orig-args args) |
| 243 | (bind-defs nil) (bind-enquote nil) | 274 | (bind-defs nil) (bind-enquote nil) |
| @@ -282,11 +313,8 @@ It is a list of elements of the form either: | |||
| 282 | (require 'help-fns) | 313 | (require 'help-fns) |
| 283 | (cons (help-add-fundoc-usage | 314 | (cons (help-add-fundoc-usage |
| 284 | (if (stringp (car hdr)) (pop hdr)) | 315 | (if (stringp (car hdr)) (pop hdr)) |
| 285 | ;; orig-args can contain &cl-defs (an internal | 316 | (format "(fn %S)" |
| 286 | ;; CL thingy I don't understand), so remove it. | 317 | (cl--make-usage-args orig-args))) |
| 287 | (let ((x (memq '&cl-defs orig-args))) | ||
| 288 | (if (null x) orig-args | ||
| 289 | (delq (car x) (remq (cadr x) orig-args))))) | ||
| 290 | hdr))) | 318 | hdr))) |
| 291 | (list (nconc (list 'let* bind-lets) | 319 | (list (nconc (list 'let* bind-lets) |
| 292 | (nreverse bind-forms) body))))))) | 320 | (nreverse bind-forms) body))))))) |
diff --git a/lisp/help-fns.el b/lisp/help-fns.el index b13e6a77d5d..5e034b14fde 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el | |||
| @@ -65,7 +65,9 @@ | |||
| 65 | 65 | ||
| 66 | (defun help-split-fundoc (docstring def) | 66 | (defun help-split-fundoc (docstring def) |
| 67 | "Split a function DOCSTRING into the actual doc and the usage info. | 67 | "Split a function DOCSTRING into the actual doc and the usage info. |
| 68 | Return (USAGE . DOC) or nil if there's no usage info. | 68 | Return (USAGE . DOC) or nil if there's no usage info, where USAGE info |
| 69 | is a string describing the argument list of DEF, such as | ||
| 70 | \"(apply FUNCTION &rest ARGUMENTS)\". | ||
| 69 | DEF is the function whose usage we're looking for in DOCSTRING." | 71 | DEF is the function whose usage we're looking for in DOCSTRING." |
| 70 | ;; Functions can get the calling sequence at the end of the doc string. | 72 | ;; Functions can get the calling sequence at the end of the doc string. |
| 71 | ;; In cases where `function' has been fset to a subr we can't search for | 73 | ;; In cases where `function' has been fset to a subr we can't search for |
| @@ -156,12 +158,7 @@ the same names as used in the original source code, when possible." | |||
| 156 | (defun help-make-usage (function arglist) | 158 | (defun help-make-usage (function arglist) |
| 157 | (cons (if (symbolp function) function 'anonymous) | 159 | (cons (if (symbolp function) function 'anonymous) |
| 158 | (mapcar (lambda (arg) | 160 | (mapcar (lambda (arg) |
| 159 | (if (not (symbolp arg)) | 161 | (if (not (symbolp arg)) arg |
| 160 | (if (and (consp arg) (symbolp (car arg))) | ||
| 161 | ;; CL style default values for optional args. | ||
| 162 | (cons (intern (upcase (symbol-name (car arg)))) | ||
| 163 | (cdr arg)) | ||
| 164 | arg) | ||
| 165 | (let ((name (symbol-name arg))) | 162 | (let ((name (symbol-name arg))) |
| 166 | (cond | 163 | (cond |
| 167 | ((string-match "\\`&" name) arg) | 164 | ((string-match "\\`&" name) arg) |