1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
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 (let ((urldir (getenv "URLDIR")))
56 (unless (zerop (length urldir))
57 (push (file-name-as-directory urldir) load-path)))
59 (defvar dgnushack-w3-directory (let ((w3dir (getenv "W3DIR")))
60 (unless (zerop (length w3dir))
61 (file-name-as-directory w3dir))))
62 (when dgnushack-w3-directory
63 (push dgnushack-w3-directory load-path))
65 ;; If we are building w3 in a different directory than the source
66 ;; directory, we must read *.el from source directory and write *.elc
67 ;; into the building directory. For that, we define this function
68 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
69 (defun byte-compile-dest-file (filename)
70 "Convert an Emacs Lisp source file name to a compiled file name.
71 In addition, remove directory name part from FILENAME."
72 (setq filename (byte-compiler-base-file-name filename))
73 (setq filename (file-name-sans-versions filename))
74 (setq filename (file-name-nondirectory filename))
75 (if (memq system-type '(win32 w32 mswindows windows-nt))
76 (setq filename (downcase filename)))
77 (cond ((eq system-type 'vax-vms)
78 (concat (substring filename 0 (string-match ";" filename)) "c"))
79 ((string-match emacs-lisp-file-regexp filename)
80 (concat (substring filename 0 (match-beginning 0)) ".elc"))
81 (t (concat filename ".elc"))))
85 (unless (fboundp 'si:byte-optimize-form-code-walker)
86 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
87 (setq max-specpdl-size 3000)
88 (defalias 'si:byte-optimize-form-code-walker
89 (symbol-function 'byte-optimize-form-code-walker))
90 (defun byte-optimize-form-code-walker (form for-effect)
91 (if (and for-effect (memq (car-safe form) '(and or)))
92 ;; Fix bug in and/or forms.
94 (backwards (reverse (cdr form))))
96 (null (setcar backwards
97 (byte-optimize-form (car backwards) t))))
98 (setq backwards (cdr backwards)))
99 (if (and (cdr form) (null backwards))
101 " all subforms of %s called for effect; deleted" form))
103 (let ((head backwards))
104 (while (setq backwards (cdr backwards))
105 (setcar backwards (byte-optimize-form (car backwards)
107 (cons fn (nreverse head)))))
108 (si:byte-optimize-form-code-walker form for-effect)))
109 (byte-compile 'byte-optimize-form-code-walker))
111 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
115 (wrong-number-of-arguments
116 ;; Optimize byte code for `char-after'.
117 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
118 (defun byte-optimize-char-after (form)
119 (if (null (cdr form))
120 '(char-after (point))
125 (wrong-number-of-arguments
126 ;; Optimize byte code for `char-before'.
127 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
128 (defun byte-optimize-char-before (form)
129 (if (null (cdr form))
130 '(char-before (point))
133 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
136 (load "~/.lpath.el" t nil t)
137 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
139 ;; Don't load path-util until `char-after' and `char-before' have been
140 ;; optimized because it requires `poe' and then modify the functions.
141 (or (featurep 'path-util)
142 (load "apel/path-util"))
145 (unless (module-installed-p 'mel)
146 ;; FLIM 1.14 may have installed in two "flim" subdirectories.
147 (push (expand-file-name "flim"
148 (file-name-directory (get-latest-path "^apel$" t)))
150 (unless (module-installed-p 'mel)
152 FLIM package does not found in %s.
153 Try to re-configure with --with-addpath=FLIM_PATH and run make again.
160 (push srcdir load-path)
161 (load (expand-file-name "lpath.el" srcdir) nil t t)
165 ;; Bind functions defined by `defun-maybe'.
166 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
167 (defun byte-compile-file-form-defun-maybe (form)
168 (if (and (not (fboundp (nth 1 form)))
169 (memq 'unresolved byte-compile-warnings))
170 (setq byte-compile-function-environment
171 (cons (cons (nth 1 form)
172 (cons 'lambda (cdr (cdr form))))
173 byte-compile-function-environment)))
177 :symbol-for-testing-whether-colon-keyword-is-available-or-not
180 (dolist (keyword '(:button-keymap :data :file :mime-handle
181 :key-type :value-type
182 :ascent :foreground :help))
183 (set keyword keyword))))
185 ;; If you are using Mule 2.3 based on Emacs 19.34, you may also put the
186 ;; following lines in your .emacs file, before gnus related modules are
187 ;; loaded. It is not always necessary. However if it is done, you will
188 ;; be able to load or evaluate gnus related *.el (not compiled) files.
189 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
192 (setq :version ':version
193 :set-after ':set-after)
195 (defadvice custom-handle-keyword
196 (around dont-signal-an-error-even-if-unsupported-keyword-is-given
198 "Don't signal an error even if unsupported keyword is given."
199 (if (not (memq (ad-get-arg 1) '(:version :set-after)))
201 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
204 (put 'custom-declare-face 'byte-optimizer
205 'byte-optimize-ignore-unsupported-custom-keywords)
206 (put 'custom-declare-group 'byte-optimizer
207 'byte-optimize-ignore-unsupported-custom-keywords)
208 (defun byte-optimize-ignore-unsupported-custom-keywords (form)
209 (if (or (memq ':version (nthcdr 4 form))
210 (memq ':set-after (nthcdr 4 form)))
211 (let ((newform (list (car form) (nth 1 form)
212 (nth 2 form) (nth 3 form)))
213 (args (nthcdr 4 form)))
215 (or (memq (car args) '(:version :set-after))
216 (setq newform (nconc newform (list (car args)
218 (setq args (cdr (cdr args))))
222 (put 'custom-declare-variable 'byte-hunk-handler
223 'byte-compile-file-form-custom-declare-variable)
224 (defun byte-compile-file-form-custom-declare-variable (form)
225 ;; Bind defcustom'ed variables.
226 (if (memq 'free-vars byte-compile-warnings)
227 (setq byte-compile-bound-variables
228 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
229 (if (memq ':version (nthcdr 4 form))
230 ;; Make the variable uncustomizable.
231 `(defvar ,(nth 1 (nth 1 form)) ,(nth 1 (nth 2 form))
232 ,(substring (nth 3 form) (if (string-match "^[\t *]+" (nth 3 form))
235 ;; Ignore unsupported keyword(s).
236 (if (memq ':set-after (nthcdr 4 form))
237 (let ((newform (list (car form) (nth 1 form)
238 (nth 2 form) (nth 3 form)))
239 (args (nthcdr 4 form)))
241 (or (eq (car args) ':set-after)
242 (setq newform (nconc newform (list (car args)
244 (setq args (cdr (cdr args))))
248 ;; Unknown variables and functions.
249 (unless (boundp 'buffer-file-coding-system)
250 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
251 (unless (featurep 'xemacs)
252 (defalias 'Custom-make-dependencies 'ignore)
253 (defalias 'update-autoloads-from-directory 'ignore))
255 (unless (fboundp 'with-temp-buffer)
256 ;; Pickup some macros.
259 (defalias 'device-sound-enabled-p 'ignore)
260 (defalias 'play-sound-file 'ignore)
261 (defalias 'nndb-request-article 'ignore)
262 (defalias 'efs-re-read-dir 'ignore)
263 (defalias 'ange-ftp-re-read-dir 'ignore)
264 (defalias 'define-mail-user-agent 'ignore)
266 (defconst dgnushack-unexporting-files
267 (append '("dgnushack.el" "dgnuspath.el" "lpath.el")
268 (unless (or (condition-case code
271 (message "No w3: %s %s retrying..." code
272 (locate-library "w3-forms"))
274 ;; Maybe mis-configured Makefile is used (e.g.
275 ;; configured for FSFmacs but XEmacs is running).
276 (let ((lp (delete dgnushack-w3-directory
277 (copy-sequence load-path))))
278 (if (let ((load-path lp))
282 ;; If success, fix `load-path' for compiling.
285 (message " => fixed; W3DIR=%s"
287 (locate-library "w3-forms")))
289 (message " => ignored")
291 '("nnweb.el" "nnlistserv.el" "nnultimate.el"
292 "nnslashdot.el" "nnwarchive.el" "webmail.el"
295 (progn (require 'bbdb) nil)
296 (error '("gnus-bbdb.el")))
297 (unless (featurep 'xemacs)
298 '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
299 "nnheaderxm.el" "smiley.el"))
300 (when (or (featurep 'xemacs) (<= emacs-major-version 20))
302 (when (and (fboundp 'base64-decode-string)
303 (subrp (symbol-function 'base64-decode-string)))
305 (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
307 "Files which will not be installed.")
309 (defconst dgnushack-exporting-files
310 (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
311 (dolist (file dgnushack-unexporting-files)
312 (setq files (delete file files)))
313 (sort files 'string-lessp))
314 "Files which will be compiled and installed.")
316 (defun dgnushack-exporting-files ()
317 "Print name of files which will be installed."
318 (princ (mapconcat 'identity dgnushack-exporting-files " ")))
320 (defun dgnushack-compile (&optional warn)
321 ;;(setq byte-compile-dynamic t)
323 (setq byte-compile-warnings
324 '(free-vars unresolved callargs redefine)))
325 (unless (locate-library "cus-edit")
326 (error "You do not seem to have Custom installed.
327 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
328 You also then need to add the following to the lisp/dgnushack.el file:
330 (push \"~/lisp/custom\" load-path)
332 Modify to suit your needs."))
335 (message "load-path=(\"%s\")"
336 (mapconcat 'identity load-path "\"\n \""))
338 (dolist (file dgnushack-exporting-files)
339 (setq file (expand-file-name file srcdir))
340 (when (and (file-exists-p
341 (setq elc (concat (file-name-nondirectory file) "c")))
342 (file-newer-than-file-p file elc))
345 (let ((files dgnushack-exporting-files)
346 ;;(byte-compile-generate-call-tree t)
348 ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
350 (when (featurep 'xemacs)
351 (setq gnus-xmas-glyph-directory "dummy"))
352 (while (setq file (pop files))
353 (setq file (expand-file-name file srcdir))
354 (when (or (not (file-exists-p
355 (setq elc (concat (file-name-nondirectory file) "c"))))
356 (file-newer-than-file-p file elc))
358 (byte-compile-file file))))))
360 (defun dgnushack-recompile ()
362 (byte-recompile-directory "." 0))
364 (defvar dgnushack-gnus-load-file (expand-file-name "gnus-load.el" srcdir))
365 (defvar dgnushack-cus-load-file (expand-file-name "cus-load.el" srcdir))
366 (defvar dgnushack-auto-load-file (expand-file-name "auto-autoloads.el" srcdir))
368 (defun dgnushack-make-cus-load ()
369 (when (condition-case nil
372 (let ((cusload-base-file dgnushack-cus-load-file))
373 (if (fboundp 'custom-make-dependencies)
374 (custom-make-dependencies)
375 (Custom-make-dependencies)))))
377 (defun dgnushack-make-auto-load ()
379 (let ((generated-autoload-file dgnushack-gnus-load-file)
380 (make-backup-files nil)
381 (autoload-package-name "gnus"))
382 (if (featurep 'xemacs)
384 (if (file-exists-p generated-autoload-file)
385 (delete-file generated-autoload-file))
386 (if (file-exists-p dgnushack-auto-load-file)
387 (delete-file dgnushack-auto-load-file)))
388 (with-temp-file generated-autoload-file
390 (if (featurep 'xemacs)
391 (let ((si:message (symbol-function 'message)))
392 (defun message (fmt &rest args)
393 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
394 (file-exists-p (file-name-nondirectory (car args))))
396 fmt (file-name-nondirectory (car args))))
397 ((string-equal "No autoloads found in %s" fmt))
398 ((string-equal "Generating autoloads for %s...done" fmt))
399 (t (apply si:message fmt args))))
401 (batch-update-autoloads)
402 (fset 'message si:message)))
403 (batch-update-autoloads))))
405 (defun dgnushack-make-load ()
406 (message (format "Generating %s..." dgnushack-gnus-load-file))
407 (with-temp-file dgnushack-gnus-load-file
408 (if (file-exists-p dgnushack-cus-load-file)
410 (insert-file-contents dgnushack-cus-load-file)
411 (delete-file dgnushack-cus-load-file)
412 (goto-char (point-min))
413 (search-forward ";;; Code:")
415 (delete-region (point-min) (point))
417 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
421 (goto-char (point-max))
422 (if (search-backward "custom-versions-load-alist" nil t)
425 (while (eq (char-after) ?\;)
428 (delete-region (point) (point-max))
431 ;;; gnus-load.el --- automatically extracted autoload
435 ;; smiley-* are duplicated. Remove them all.
436 (let ((point (point)))
437 (insert-file-contents dgnushack-gnus-load-file)
439 (while (search-forward "smiley-" nil t)
441 (if (looking-at "(autoload ")
442 (delete-region (point) (progn (forward-sexp) (point)))
445 (goto-char (point-max))
446 (when (search-backward "\n(provide " nil t)
448 (delete-region (point) (point-max)))
451 \(provide 'gnus-load)
454 ;;; version-control: never
455 ;;; no-byte-compile: t
456 ;;; no-update-autoloads: t
458 ;;; gnus-load.el ends here\n"))
459 (message (format "Compiling %s..." dgnushack-gnus-load-file))
460 (byte-compile-file dgnushack-gnus-load-file))
463 (defconst dgnushack-info-file-regexp-en
464 (let ((names '("gnus" "message" "emacs-mime"))
466 (while (setq name (pop names))
467 (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
468 (when names "\\|"))))
470 "Regexp matching English info files.")
472 (defconst dgnushack-info-file-regexp-ja
473 (let ((names '("gnus-ja" "message-ja"))
475 (while (setq name (pop names))
476 (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
477 (when names "\\|"))))
479 "Regexp matching Japanese info files.")
481 (defun dgnushack-remove-extra-files-in-package ()
482 "Remove extra files in the lisp directory of the XEmacs package."
483 (let ((lisp-dir (expand-file-name (concat "lisp/"
485 (cadr command-line-args-left)
488 (car command-line-args-left))))
489 (when (file-directory-p lisp-dir)
491 (dolist (file dgnushack-exporting-files)
492 (setq files (nconc files (list file (concat file "c")))))
493 (dolist (file (directory-files lisp-dir nil nil t t))
494 (unless (member file files)
495 (setq file (expand-file-name file lisp-dir))
496 (message "Removing %s..." file)
501 (defun dgnushack-install-package-manifest ()
502 "Install MANIFEST file as an XEmacs package."
503 (let* ((package-dir (car command-line-args-left))
504 (product-name (cadr command-line-args-left))
505 (name (expand-file-name (concat "pkginfo/MANIFEST." product-name)
508 (message "Generating %s..." name)
510 (insert "pkginfo/MANIFEST." product-name "\n")
511 (let ((lisp-dir (concat "lisp/" product-name "/"))
512 (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
514 (while (setq file (pop files))
515 (unless (member file dgnushack-unexporting-files)
516 (insert lisp-dir file "\n")))
518 (sort (directory-files "../texi/" nil
519 (concat dgnushack-info-file-regexp-en
521 dgnushack-info-file-regexp-ja)
524 (while (setq file (pop files))
525 (insert "info/" file "\n"))))))
528 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
529 (if (condition-case nil
531 (describe-key-briefly '((())) nil)
533 (wrong-number-of-arguments nil);; Old Emacsen.
538 (insert (funcall 'describe-key-briefly ,key))
539 (funcall 'describe-key-briefly ,key))
540 `(funcall 'describe-key-briefly ,key))))
542 ;;; dgnushack.el ends here