Mercurial > emacs
comparison lisp/emacs-lisp/autoload.el @ 29549:eafd45bcdcc1
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sun, 11 Jun 2000 05:00:35 +0000 |
parents | b82691dc560e |
children | 6144bd28b9b5 |
comparison
equal
deleted
inserted
replaced
29548:71b284c55162 | 29549:eafd45bcdcc1 |
---|---|
60 (defconst generate-autoload-section-continuation ";;;;;; " | 60 (defconst generate-autoload-section-continuation ";;;;;; " |
61 "String to add on each continuation of the section header form.") | 61 "String to add on each continuation of the section header form.") |
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 |
101 ;;; the doc-string in FORM. | 122 ;;; the doc-string in FORM. |
102 ;;; | 123 ;;; |
125 (put 'define-skeleton 'doc-string-elt 2) | 146 (put 'define-skeleton 'doc-string-elt 2) |
126 (put 'define-derived-mode 'doc-string-elt 4) | 147 (put 'define-derived-mode 'doc-string-elt 4) |
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) |
133 ;; Returns a relative pathname of FILE | 156 ;; Returns a relative pathname of FILE |
134 ;; starting from the directory that loaddefs.el is in. | 157 ;; starting from the directory that loaddefs.el is in. |