1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: news, path
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs 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 ;; GNU Emacs 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., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 ;; Set coding priority of Shift-JIS to the bottom.
32 (if (featurep 'xemacs)
33 (defalias 'set-coding-priority 'ignore)
34 (defalias 'coding-priority-list 'ignore)
35 (defalias 'set-coding-priority-list 'ignore))
36 (cond ((and (featurep 'xemacs) (featurep 'mule))
37 (if (memq 'shift-jis (coding-priority-list))
38 (set-coding-priority-list
39 (append (delq 'shift-jis (coding-priority-list)) '(shift-jis)))))
41 (put '*coding-category-sjis* 'priority (length *predefined-category*)))
43 (if (memq 'coding-category-sjis coding-category-list)
45 (append (delq 'coding-category-sjis
46 (copy-sequence coding-category-list))
47 '(coding-category-sjis))))))
49 (defalias 'facep 'ignore)
53 (defvar srcdir (or (getenv "srcdir") "."))
55 (push (or (getenv "W3DIR") (expand-file-name "../../w3/lisp/" srcdir))
57 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
59 ;; If we are building w3 in a different directory than the source
60 ;; directory, we must read *.el from source directory and write *.elc
61 ;; into the building directory. For that, we define this function
62 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
63 (defun byte-compile-dest-file (filename)
64 "Convert an Emacs Lisp source file name to a compiled file name.
65 In addition, remove directory name part from FILENAME."
66 (setq filename (byte-compiler-base-file-name filename))
67 (setq filename (file-name-sans-versions filename))
68 (setq filename (file-name-nondirectory filename))
69 (if (memq system-type '(win32 w32 mswindows windows-nt))
70 (setq filename (downcase filename)))
71 (cond ((eq system-type 'vax-vms)
72 (concat (substring filename 0 (string-match ";" filename)) "c"))
73 ((string-match emacs-lisp-file-regexp filename)
74 (concat (substring filename 0 (match-beginning 0)) ".elc"))
75 (t (concat filename ".elc"))))
79 (unless (fboundp 'si:byte-optimize-form-code-walker)
80 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
81 (setq max-specpdl-size 3000)
82 (defalias 'si:byte-optimize-form-code-walker
83 (symbol-function 'byte-optimize-form-code-walker))
84 (defun byte-optimize-form-code-walker (form for-effect)
85 (if (and for-effect (memq (car-safe form) '(and or)))
86 ;; Fix bug in and/or forms.
88 (backwards (reverse (cdr form))))
90 (null (setcar backwards
91 (byte-optimize-form (car backwards) t))))
92 (setq backwards (cdr backwards)))
93 (if (and (cdr form) (null backwards))
95 " all subforms of %s called for effect; deleted" form))
97 (let ((head backwards))
98 (while (setq backwards (cdr backwards))
99 (setcar backwards (byte-optimize-form (car backwards)
101 (cons fn (nreverse head)))))
102 (si:byte-optimize-form-code-walker form for-effect)))
103 (byte-compile 'byte-optimize-form-code-walker))
105 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
108 (load "~/.lpath.el" t nil t)
109 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
113 (wrong-number-of-arguments
114 ;; Optimize byte code for `char-after'.
115 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
116 (defun byte-optimize-char-after (form)
117 (if (null (cdr form))
118 '(char-after (point))
123 (wrong-number-of-arguments
124 ;; Optimize byte code for `char-before'.
125 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
126 (defun byte-optimize-char-before (form)
127 (if (null (cdr form))
128 '(char-before (point))
131 (push srcdir load-path)
133 ;; `char-after' and `char-before' must be well-behaved before lpath.el
134 ;; is loaded. Because it requires `poe' via `path-util'.
135 (load (expand-file-name "lpath.el" srcdir) nil t t)
137 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
138 ;; Bind defcustom'ed variables.
139 (put 'custom-declare-variable 'byte-hunk-handler
140 'byte-compile-file-form-custom-declare-variable)
141 (defun byte-compile-file-form-custom-declare-variable (form)
142 (if (memq 'free-vars byte-compile-warnings)
143 (setq byte-compile-bound-variables
144 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
147 ;; Bind functions defined by `defun-maybe'.
148 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
149 (defun byte-compile-file-form-defun-maybe (form)
150 (if (and (not (fboundp (nth 1 form)))
151 (memq 'unresolved byte-compile-warnings))
152 (setq byte-compile-function-environment
153 (cons (cons (nth 1 form)
154 (cons 'lambda (cdr (cdr form))))
155 byte-compile-function-environment)))
159 :symbol-for-testing-whether-colon-keyword-is-available-or-not
162 (dolist (keyword '(:button-keymap :data :file :mime-handle))
163 (set keyword keyword))))
165 ;; Unknown variables and functions.
166 (unless (boundp 'buffer-file-coding-system)
167 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
168 (unless (featurep 'xemacs)
169 (defalias 'Custom-make-dependencies 'ignore)
170 (defalias 'update-autoloads-from-directory 'ignore))
171 (autoload 'texinfo-parse-line-arg "texinfmt")
173 (unless (fboundp 'with-temp-buffer)
174 ;; Pickup some macros.
177 (defalias 'device-sound-enabled-p 'ignore)
178 (defalias 'play-sound-file 'ignore)
179 (defalias 'nndb-request-article 'ignore)
180 (defalias 'efs-re-read-dir 'ignore)
181 (defalias 'ange-ftp-re-read-dir 'ignore)
182 (defalias 'define-mail-user-agent 'ignore)
184 (defconst dgnushack-tool-files
185 '("dgnushack.el" "dgnuspath.el" "lpath.el" "ptexinfmt.el"))
186 (defconst dgnushack-unexported-files
187 '("dgnuspath.el" "ptexinfmt.el"))
189 (defun dgnushack-compile (&optional warn)
190 ;;(setq byte-compile-dynamic t)
192 (setq byte-compile-warnings
193 '(free-vars unresolved callargs redefine)))
194 (unless (locate-library "cus-edit")
195 (error "You do not seem to have Custom installed.
196 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
197 You also then need to add the following to the lisp/dgnushack.el file:
199 (push \"~/lisp/custom\" load-path)
201 Modify to suit your needs."))
202 (let ((files (directory-files srcdir nil "^[^=].*\\.el$")))
207 (progn (require 'w3-forms) nil)
208 (error '("nnweb.el" "nnlistserv.el" "nnultimate.el"
209 "nnslashdot.el" "nnwarchive.el" "webmail.el")))
211 (progn (require 'bbdb) nil)
212 (error '("gnus-bbdb.el")))
213 (unless (featurep 'xemacs)
214 '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
215 "nnheaderxm.el" "smiley.el"))
216 (when (or (featurep 'xemacs) (<= emacs-major-version 20))
218 (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
220 (setq files (delete file files)))
223 (setq file (expand-file-name file srcdir))
224 (when (and (file-exists-p (setq elc (concat file "c")))
225 (file-newer-than-file-p file elc))
228 (let (;;(byte-compile-generate-call-tree t)
230 (while (setq file (pop files))
231 (setq file (expand-file-name file srcdir))
232 (when (or (not (file-exists-p (setq elc (concat file "c"))))
233 (file-newer-than-file-p file elc))
235 (byte-compile-file file)))))))
237 (defun dgnushack-recompile ()
239 (byte-recompile-directory "." 0))
242 (defconst dgnushack-info-file-regexp
243 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
244 "\\.info\\(-[0-9]+\\)?$"))
246 (defconst dgnushack-texi-file-regexp
247 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
249 (defun dgnushack-make-package ()
250 (let (make-backup-files)
251 (message "Updating autoloads for directory %s..." default-directory)
252 (let ((generated-autoload-file "auto-autoloads.el")
254 (omsg (symbol-function 'message)))
255 (defun message (fmt &rest args)
256 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
257 (file-exists-p (file-name-nondirectory (car args))))
258 (funcall omsg fmt (file-name-nondirectory (car args))))
259 ((string-equal "No autoloads found in %s" fmt))
260 ((string-equal "Generating autoloads for %s...done" fmt))
261 (t (apply omsg fmt args))))
263 (update-autoloads-from-directory default-directory)
264 (fset 'message omsg)))
265 (byte-compile-file "auto-autoloads.el")
268 (let ((standard-output (current-buffer)))
269 (Custom-make-dependencies "."))
270 (message "%s" (buffer-string)))
272 (byte-compile-file "custom-load.el")
275 (let ((product-name (downcase gnus-product-name)))
276 (message "Generating MANIFEST.%s for the package..." product-name)
278 (insert "pkginfo/MANIFEST." product-name "\n")
279 (let ((lisp-dir (concat "lisp/" product-name "/"))
280 (files (sort (directory-files "." nil "\\.elc?$") 'string-lessp))
282 (while (setq file (pop files))
283 (unless (member file dgnushack-unexported-files)
284 (insert lisp-dir file "\n")))
285 (setq files (sort (directory-files "../texi/" nil
286 dgnushack-info-file-regexp)
288 (while (setq file (pop files))
289 (insert lisp-dir file "\n")))
290 (write-file (concat "../MANIFEST." product-name))))))
292 (defun dgnushack-install-package ()
293 (let ((package-dir (car command-line-args-left))
294 (product-name (progn (require 'gnus) (downcase gnus-product-name))))
296 ;; Examine PACKAGEDIR.
299 (when (boundp 'early-packages)
300 (setq dirs (delq nil (append (when early-package-load-path
302 (when late-package-load-path
304 (when last-package-load-path
306 (while (and dirs (not package-dir))
307 (when (file-directory-p (car dirs))
308 (setq package-dir (car dirs)
309 dirs (cdr dirs)))))))
312 You must specify the name of the package path as follows:
314 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages/"))
316 ;; Install lisp files.
317 (let ((lisp-dir (expand-file-name (concat "lisp/" product-name "/")
319 (files (sort (directory-files "." nil "\\.elc?$") 'string-lessp)))
320 (unless (file-directory-p lisp-dir)
321 (make-directory lisp-dir t))
322 (dolist (file dgnushack-unexported-files)
323 (setq files (delete file files)))
324 ;; Remove extra files.
325 (dolist (file (directory-files lisp-dir nil nil nil t))
326 (unless (or (member file files)
327 (not (string-match "\\.elc?$" file)))
328 (setq file (expand-file-name file lisp-dir))
329 (message "Removing %s..." file)
333 (while (setq file (pop files))
334 (message "Copying %s to %s..." file lisp-dir)
335 (copy-file file (expand-file-name file lisp-dir) t t)))
337 ;; Install info files.
338 (let ((files (sort (directory-files "../texi/" nil
339 dgnushack-info-file-regexp)
341 (info-dir (expand-file-name "info/" package-dir)))
342 (unless (file-directory-p info-dir)
343 (make-directory info-dir))
344 (while (setq file (pop files))
345 (message "Copying ../texi/%s to %s..." file info-dir)
346 (copy-file (expand-file-name file "../texi/")
347 (expand-file-name file info-dir)
351 (let ((manifest (concat "MANIFEST." product-name))
352 (pkginfo-dir (expand-file-name "pkginfo/" package-dir)))
353 (unless (file-directory-p pkginfo-dir)
354 (make-directory pkginfo-dir))
355 (message "Copying ../%s to %s..." manifest pkginfo-dir)
356 (copy-file (expand-file-name manifest "../")
357 (expand-file-name manifest pkginfo-dir) t t))
360 (defun dgnushack-texi-add-suffix-and-format ()
361 (dgnushack-texi-format t))
363 (defun dgnushack-texi-format (&optional addsuffix)
364 (if (not noninteractive)
365 (error "batch-texinfo-format may only be used -batch."))
367 (let ((auto-save-default nil)
368 (find-file-run-dired nil)
369 coding-system-for-write
370 output-coding-system)
374 (while command-line-args-left
375 (setq file (expand-file-name (car command-line-args-left)))
376 (cond ((not (file-exists-p file))
377 (message ">> %s does not exist!" file)
379 command-line-args-left (cdr command-line-args-left)))
380 ((file-directory-p file)
381 (setq command-line-args-left
382 (nconc (directory-files file)
383 (cdr command-line-args-left))))
385 (setq files (cons file files)
386 command-line-args-left (cdr command-line-args-left)))))
387 (while (setq file (pop files))
390 (if buffer-file-name (kill-buffer (current-buffer)))
393 (setq output-coding-system (symbol-value
394 'file-coding-system))
395 (setq coding-system-for-write buffer-file-coding-system))
398 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
399 (not (string-match "\\.info$" (match-string 1))))
401 (buffer-disable-undo (current-buffer))
402 ;; process @include before updating node
403 ;; This might produce some problem if we use @lowersection or
405 (let ((input-directory default-directory)
406 (texinfo-command-end))
407 (while (re-search-forward "^@include" nil t)
408 (setq texinfo-command-end (point))
409 (let ((filename (concat input-directory
410 (texinfo-parse-line-arg))))
411 (re-search-backward "^@include")
412 (delete-region (point) (save-excursion
415 (message "Reading included file: %s" filename)
421 (car (cdr (insert-file-contents filename)))))
422 (goto-char (point-min))
423 ;; Remove `@setfilename' line from included file,
424 ;; if any, so @setfilename command not duplicated.
425 (if (re-search-forward "^@setfilename"
432 (delete-region (point) (save-excursion
436 (texinfo-every-node-update)
437 (set-buffer-modified-p nil)
438 (message "texinfo formatting %s..." file)
439 (texinfo-format-buffer nil)
440 (if (buffer-modified-p)
441 (progn (message "Saving modified %s" (buffer-file-name))
444 (message ">> Error: %s" (prin1-to-string err))
445 (message ">> point at")
446 (let ((s (buffer-substring (point)
450 (while (setq tem (string-match "\n+" s tem))
451 (setq s (concat (substring s 0 (match-beginning 0))
453 (substring s (match-end 0)))
457 (kill-emacs error))))
459 ;;; dgnushack.el ends here