1 ;;; cedet-autogen.el --- Generate autoloads for CEDET libraries
3 ;; Copyright (C) 2003, 2004 David Ponce
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Created: 22 Aug 2003
8 ;; X-CVS: $Id: cedet-autogen.el,v 1.6 2005/09/30 20:07:14 zappo Exp $
10 ;; This file is not part of GNU Emacs.
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; This software is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; Automatically generate autoloads for CEDET libraries.
39 (eval-when-compile (require 'cl
))
42 (defun cedet-autogen-noninteractive ()
43 "Return non-nil if running non-interactively."
44 (if (featurep 'xemacs
)
48 (if (fboundp 'keywordp
)
49 (defalias 'cedet-autogen-keywordp
'keywordp
)
50 (defun cedet-autogen-keywordp (object)
51 "Return t if OBJECT is a keyword.
52 This means that it is a symbol with a print name beginning with `:'
53 interned in the initial obarray."
55 (char-equal ?
: (aref 0 (symbol-name object
)))))
58 (when (cedet-autogen-noninteractive)
59 ;; If the user is doing this non-interactively, we need to set up
60 ;; these conveniences.
61 (add-to-list 'load-path nil
)
62 (setq find-file-hooks nil
63 find-file-suppress-same-file-warnings t
)
66 (defadvice make-autoload
(before cedet-make-autoload activate
)
67 "Extend `make-autoload' with support for particular CEDET forms.
68 When a such form, like defclass, defmethod, etc., is recognized, it is
69 replaced with side effect by an equivalent known form before calling
70 the true `make-autoload' function."
71 (if (consp (ad-get-arg 0))
72 (let* ((form (ad-get-arg 0))
77 ((eq car
'define-overload
)
81 (setq name
(nth 1 form
)
83 (if (cedet-autogen-keywordp (car args
))
84 (setq args
(cdr args
)))
85 (setq doc
(nth 1 args
)
88 (setcdr form
(list name args
(if (stringp doc
) doc
)))
91 (setq name
(nth 1 form
)
95 (setcdr form
(list name args
(if (stringp doc
) doc
)))
99 (defconst cedet-autogen-header
100 "Auto-generated CEDET autoloads"
101 "Header of the auto-generated autoloads file.")
103 (defconst cedet-autogen-tagfile
".cedet-lisp"
104 "Dummy file that indicates to scan this directory for autoloads.")
106 (defun cedet-autogen-kill-xemacs-autoloads-feature ()
107 "Remove Xemacs autoloads feature from this buffer."
109 (goto-char (point-min))
110 (while (re-search-forward "(\\(featurep\\|provide\\) '\\sw+-autoloads" nil t
)
112 (while t
(up-list -
1))
114 (kill-region (point) (save-excursion (forward-list) (point)))
117 (defun cedet-autogen-update-header ()
118 "Update header of the auto-generated autoloads file.
119 Run as `write-contents-hooks'."
120 (when (string-equal generated-autoload-file
(buffer-file-name))
121 (let ((tag (format ";;; %s ---" (file-name-nondirectory
122 (buffer-file-name)))))
123 (message "Updating header...")
124 (goto-char (point-min))
126 ;; Replace existing header line
127 ((re-search-forward (concat "^" (regexp-quote tag
)) nil t
)
131 ;; Insert header before first ^L encountered (XEmacs)
132 ((re-search-forward "^\f" nil t
)
135 (insert tag
" " cedet-autogen-header
)
137 (when (featurep 'xemacs
)
138 (cedet-autogen-kill-xemacs-autoloads-feature))
139 (message "Updating header...done")
140 nil
;; Say not already written.
143 (defun cedet-autogen-subdirs (root-dir)
144 "Return autoload candidate sub directories of ROOT-DIR.
145 That is, those where a `cedet-autogen-tagfile' file is found.
146 Return a list of directory names, relative to ROOT-DIR."
148 (dolist (dir (directory-files default-directory
))
149 (and (file-directory-p dir
) (not (string-match dir
"\\`..?\\'"))
150 (let* ((default-directory (expand-file-name dir
))
151 (subdirs (cedet-autogen-subdirs root-dir
)))
152 (when (file-exists-p cedet-autogen-tagfile
)
153 (push (file-relative-name default-directory root-dir
)
155 (setq dirs
(nconc dirs subdirs
)))))
158 (defun cedet-autogen-ensure-default-file (file)
159 "Make sure that the autoload file FILE exists and if not create it."
160 ;; If file don't exist, and is not automatically created...
161 (unless (or (file-exists-p file
)
162 (fboundp 'autoload-ensure-default-file
))
163 ;; Create a file buffer.
165 ;; Use Unix EOLs, so that the file is portable to all platforms.
166 (setq buffer-file-coding-system
'raw-text-unix
)
167 (unless (featurep 'xemacs
)
168 ;; Insert a GNU Emacs loaddefs skeleton.
169 (insert ";;; " (file-name-nondirectory file
)
170 " --- automatically extracted autoloads\n"
173 "\f\n;; Local" " Variables:\n"
174 ";; version-control: never\n"
175 ";; no-byte-compile: t\n"
176 ";; no-update-autoloads: t\n"
178 ";;; " (file-name-nondirectory file
)
180 ;; Insert the header so that the buffer is not empty.
181 (cedet-autogen-update-header))
185 (defun cedet-update-autoloads (loaddefs &optional directory
&rest directories
)
186 "Update autoloads in file LOADDEFS from sources.
187 Optional argument DIRECTORY, specifies the directory to scan for
188 autoloads. It defaults to the current directory.
189 DIRECTORIES is a list of extra directory to scan. Those directory
190 names are relative to DIRECTORY. If DIRECTORIES is nil try to scan
191 sub directories of DIRECTORY where a `cedet-autogen-tagfile' file
193 (interactive "FLoaddefs file: \nDDirectory: ")
194 (let* ((generated-autoload-file (expand-file-name loaddefs
))
196 (file-name-as-directory
197 (expand-file-name (or directory default-directory
))))
198 (extra-dirs (or directories
199 (cedet-autogen-subdirs default-directory
)))
200 (write-contents-hooks '(cedet-autogen-update-header))
201 (command-line-args-left (cons default-directory extra-dirs
))
203 (cedet-autogen-ensure-default-file generated-autoload-file
)
204 (batch-update-autoloads)))
206 (defun cedet-batch-update-autoloads ()
207 "Update autoloads in batch mode.
208 Usage: emacs -batch -f cedet-batch-update-autoloads LOADDEFS [DIRECTORY]
209 See the command `cedet-update-autoloads' for the meaning of the
210 LOADDEFS and DIRECTORY arguments."
211 (unless (cedet-autogen-noninteractive)
213 `cedet-batch-update-autoloads' is to be used only with -batch"))
215 (apply 'cedet-update-autoloads command-line-args-left
)
218 Usage: emacs -batch -f cedet-batch-update-autoloads LOADDEFS [DIRECTORY]"
222 (provide 'cedet-autogen
)
224 ;;; cedet-autogen.el ends here