diff options
| author | Stefan Monnier | 2000-06-11 05:00:35 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-06-11 05:00:35 +0000 |
| commit | e8139c11fb471e2c1ae0be2a2f59b4e045f0ed63 (patch) | |
| tree | dbc4be5c837f6ea2550b38ba5808569da55120fd | |
| parent | 1328a6dfa20b62cba2f7275e572c9cff700fe2b2 (diff) | |
| download | emacs-e8139c11fb471e2c1ae0be2a2f59b4e045f0ed63.tar.gz emacs-e8139c11fb471e2c1ae0be2a2f59b4e045f0ed63.zip | |
(make-autoload): Use `cond'.
Handle easy-mmode-define-global-mode.
For complex macros like define-minor-mode that can generate
several autoload entries, try to autoload entries in the
macroexpanded code.
| -rw-r--r-- | lisp/emacs-lisp/autoload.el | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el index 3d1833c2fb3..3928ee1a747 100644 --- a/lisp/emacs-lisp/autoload.el +++ b/lisp/emacs-lisp/autoload.el | |||
| @@ -62,39 +62,60 @@ that text will be copied verbatim to `generated-autoload-file'.") | |||
| 62 | 62 | ||
| 63 | (defun make-autoload (form file) | 63 | (defun make-autoload (form file) |
| 64 | "Turn FORM into an autoload or defvar for source file FILE. | 64 | "Turn FORM into an autoload or defvar for source file FILE. |
| 65 | Returns nil if FORM is not a function or variable or macro definition." | 65 | Returns nil if FORM is not a special autoload form (i.e. a function definition |
| 66 | (let ((car (car-safe form))) | 66 | or macro definition or a defcustom)." |
| 67 | (if (memq car '(defun define-skeleton defmacro define-derived-mode | 67 | (let ((car (car-safe form)) expand) |
| 68 | define-generic-mode easy-mmode-define-minor-mode | 68 | (cond |
| 69 | define-minor-mode defun*)) | 69 | ;; For complex cases, try again on the macro-expansion. |
| 70 | (let* ((macrop (eq car 'defmacro)) | 70 | ((and (memq car '(easy-mmode-define-global-mode |
| 71 | (name (nth 1 form)) | 71 | easy-mmode-define-minor-mode define-minor-mode)) |
| 72 | (body (nthcdr (get car 'doc-string-elt) form)) | 72 | (setq expand (let ((load-file-name file)) (macroexpand form))) |
| 73 | (doc (if (stringp (car body)) (pop body)))) | 73 | (eq (car expand) 'progn) |
| 74 | ;; `define-generic-mode' quotes the name, so take care of that | 74 | (memq :autoload-end expand)) |
| 75 | (list 'autoload (if (listp name) name (list 'quote name)) file doc | 75 | (let ((end (memq :autoload-end expand))) |
| 76 | (or (and (memq car '(define-skeleton define-derived-mode | 76 | ;; Cut-off anything after the :autoload-end marker. |
| 77 | define-generic-mode | 77 | (setcdr end nil) |
| 78 | easy-mmode-define-minor-mode | 78 | (cons 'progn |
| 79 | define-minor-mode)) t) | 79 | (mapcar (lambda (form) (make-autoload form file)) |
| 80 | (eq (car-safe (car body)) 'interactive)) | 80 | (cdr expand))))) |
| 81 | (if macrop (list 'quote 'macro) nil))) | 81 | |
| 82 | ;; Convert defcustom to a simpler (and less space-consuming) defvar, | 82 | ;; For special function-like operators, use the `autoload' function. |
| 83 | ;; but add some extra stuff if it uses :require. | 83 | ((memq car '(defun define-skeleton defmacro define-derived-mode |
| 84 | (if (eq car 'defcustom) | 84 | define-generic-mode easy-mmode-define-minor-mode |
| 85 | (let ((varname (car-safe (cdr-safe form))) | 85 | easy-mmode-define-global-mode |
| 86 | (init (car-safe (cdr-safe (cdr-safe form)))) | 86 | define-minor-mode defun*)) |
| 87 | (doc (car-safe (cdr-safe (cdr-safe (cdr-safe form))))) | 87 | (let* ((macrop (eq car 'defmacro)) |
| 88 | (rest (cdr-safe (cdr-safe (cdr-safe (cdr-safe form)))))) | 88 | (name (nth 1 form)) |
| 89 | (if (not (plist-get rest :require)) | 89 | (body (nthcdr (get car 'doc-string-elt) form)) |
| 90 | `(defvar ,varname ,init ,doc) | 90 | (doc (if (stringp (car body)) (pop body)))) |
| 91 | `(progn | 91 | ;; `define-generic-mode' quotes the name, so take care of that |
| 92 | (defvar ,varname ,init ,doc) | 92 | (list 'autoload (if (listp name) name (list 'quote name)) file doc |
| 93 | (custom-add-to-group ,(plist-get rest :group) | 93 | (or (and (memq car '(define-skeleton define-derived-mode |
| 94 | ',varname 'custom-variable) | 94 | define-generic-mode |
| 95 | (custom-add-load ',varname | 95 | easy-mmode-define-global-mode |
| 96 | ,(plist-get rest :require))))) | 96 | easy-mmode-define-minor-mode |
| 97 | nil)))) | 97 | define-minor-mode)) t) |
| 98 | (eq (car-safe (car body)) 'interactive)) | ||
| 99 | (if macrop (list 'quote 'macro) nil)))) | ||
| 100 | |||
| 101 | ;; Convert defcustom to a simpler (and less space-consuming) defvar, | ||
| 102 | ;; but add some extra stuff if it uses :require. | ||
| 103 | ((eq car 'defcustom) | ||
| 104 | (let ((varname (car-safe (cdr-safe form))) | ||
| 105 | (init (car-safe (cdr-safe (cdr-safe form)))) | ||
| 106 | (doc (car-safe (cdr-safe (cdr-safe (cdr-safe form))))) | ||
| 107 | (rest (cdr-safe (cdr-safe (cdr-safe (cdr-safe form)))))) | ||
| 108 | (if (not (plist-get rest :require)) | ||
| 109 | `(defvar ,varname ,init ,doc) | ||
| 110 | `(progn | ||
| 111 | (defvar ,varname ,init ,doc) | ||
| 112 | (custom-add-to-group ,(plist-get rest :group) | ||
| 113 | ',varname 'custom-variable) | ||
| 114 | (custom-add-load ',varname | ||
| 115 | ,(plist-get rest :require)))))) | ||
| 116 | |||
| 117 | ;; nil here indicates that this is not a special autoload form. | ||
| 118 | (t nil)))) | ||
| 98 | 119 | ||
| 99 | ;;; Forms which have doc-strings which should be printed specially. | 120 | ;;; Forms which have doc-strings which should be printed specially. |
| 100 | ;;; A doc-string-elt property of ELT says that (nth ELT FORM) is | 121 | ;;; A doc-string-elt property of ELT says that (nth ELT FORM) is |
| @@ -127,6 +148,8 @@ Returns nil if FORM is not a function or variable or macro definition." | |||
| 127 | (put 'easy-mmode-define-minor-mode 'doc-string-elt 2) | 148 | (put 'easy-mmode-define-minor-mode 'doc-string-elt 2) |
| 128 | (put 'define-minor-mode 'doc-string-elt 2) | 149 | (put 'define-minor-mode 'doc-string-elt 2) |
| 129 | (put 'define-generic-mode 'doc-string-elt 7) | 150 | (put 'define-generic-mode 'doc-string-elt 7) |
| 151 | ;; defin-global-mode has no explicit docstring. | ||
| 152 | (put 'easy-mmode-define-global-mode 'doc-string-elt 1000) | ||
| 130 | 153 | ||
| 131 | 154 | ||
| 132 | (defun autoload-trim-file-name (file) | 155 | (defun autoload-trim-file-name (file) |