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)
52 (unless (dolist (var nil t))
53 ;; Override the macro `dolist' which might be defined in egg.el.
54 (load "cl-macs" nil t))
56 (defvar srcdir (or (getenv "srcdir") "."))
58 (let ((urldir (getenv "URLDIR")))
59 (unless (zerop (length urldir))
60 (push (file-name-as-directory urldir) load-path)))
62 (defvar dgnushack-w3-directory (let ((w3dir (getenv "W3DIR")))
63 (unless (zerop (length w3dir))
64 (file-name-as-directory w3dir))))
65 (when dgnushack-w3-directory
66 (push dgnushack-w3-directory load-path))
68 ;; If we are building w3 in a different directory than the source
69 ;; directory, we must read *.el from source directory and write *.elc
70 ;; into the building directory. For that, we define this function
71 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
72 (defun byte-compile-dest-file (filename)
73 "Convert an Emacs Lisp source file name to a compiled file name.
74 In addition, remove directory name part from FILENAME."
75 (setq filename (byte-compiler-base-file-name filename))
76 (setq filename (file-name-sans-versions filename))
77 (setq filename (file-name-nondirectory filename))
78 (if (memq system-type '(win32 w32 mswindows windows-nt))
79 (setq filename (downcase filename)))
80 (cond ((eq system-type 'vax-vms)
81 (concat (substring filename 0 (string-match ";" filename)) "c"))
82 ((string-match emacs-lisp-file-regexp filename)
83 (concat (substring filename 0 (match-beginning 0)) ".elc"))
84 (t (concat filename ".elc"))))
88 (unless (fboundp 'si:byte-optimize-form-code-walker)
89 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
90 (setq max-specpdl-size 3000)
91 (defalias 'si:byte-optimize-form-code-walker
92 (symbol-function 'byte-optimize-form-code-walker))
93 (defun byte-optimize-form-code-walker (form for-effect)
94 (if (and for-effect (memq (car-safe form) '(and or)))
95 ;; Fix bug in and/or forms.
97 (backwards (reverse (cdr form))))
99 (null (setcar backwards
100 (byte-optimize-form (car backwards) t))))
101 (setq backwards (cdr backwards)))
102 (if (and (cdr form) (null backwards))
104 " all subforms of %s called for effect; deleted" form))
106 (let ((head backwards))
107 (while (setq backwards (cdr backwards))
108 (setcar backwards (byte-optimize-form (car backwards)
110 (cons fn (nreverse head)))))
111 (si:byte-optimize-form-code-walker form for-effect)))
112 (byte-compile 'byte-optimize-form-code-walker))
116 (wrong-number-of-arguments
117 ;; Optimize byte code for `char-after'.
118 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
119 (defun byte-optimize-char-after (form)
120 (if (null (cdr form))
121 '(char-after (point))
126 (wrong-number-of-arguments
127 ;; Optimize byte code for `char-before'.
128 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
129 (defun byte-optimize-char-before (form)
130 (if (null (cdr form))
131 '(char-before (point))
134 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
137 (load "~/.lpath.el" t nil t)
138 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
140 ;; Don't load path-util until `char-after' and `char-before' have been
141 ;; optimized because it requires `poe' and then modify the functions.
142 (or (featurep 'path-util)
143 (load "apel/path-util"))
146 (unless (module-installed-p 'mel)
147 ;; FLIM 1.14 may have installed in two "flim" subdirectories.
148 (push (expand-file-name "flim"
149 (file-name-directory (get-latest-path "^apel$" t)))
151 (unless (module-installed-p 'mel)
153 FLIM package does not found in %s.
154 Try to re-configure with --with-addpath=FLIM_PATH and run make again.
161 (push srcdir load-path)
162 (load (expand-file-name "lpath.el" srcdir) nil t t)
164 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
168 ;; Bind functions defined by `defun-maybe'.
169 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
170 (defun byte-compile-file-form-defun-maybe (form)
171 (if (and (not (fboundp (nth 1 form)))
172 (memq 'unresolved byte-compile-warnings))
173 (setq byte-compile-function-environment
174 (cons (cons (nth 1 form)
175 (cons 'lambda (cdr (cdr form))))
176 byte-compile-function-environment)))
180 :symbol-for-testing-whether-colon-keyword-is-available-or-not
183 (dolist (keyword '(:button-keymap :data :file :mime-handle
184 :key-type :value-type
185 :ascent :foreground :help))
186 (set keyword keyword))))
188 ;; If you are using Mule 2.3 based on Emacs 19.34, you may also put the
189 ;; following lines in your .emacs file, before gnus related modules are
190 ;; loaded. It is not always necessary. However if it is done, you will
191 ;; be able to load or evaluate gnus related *.el (not compiled) files.
192 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
195 (setq :version ':version
196 :set-after ':set-after)
198 (defadvice custom-handle-keyword
199 (around dont-signal-an-error-even-if-unsupported-keyword-is-given
201 "Don't signal an error even if unsupported keyword is given."
202 (if (not (memq (ad-get-arg 1) '(:version :set-after)))
204 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
207 (put 'custom-declare-face 'byte-optimizer
208 'byte-optimize-ignore-unsupported-custom-keywords)
209 (put 'custom-declare-group 'byte-optimizer
210 'byte-optimize-ignore-unsupported-custom-keywords)
211 (defun byte-optimize-ignore-unsupported-custom-keywords (form)
212 (if (or (memq ':version (nthcdr 4 form))
213 (memq ':set-after (nthcdr 4 form)))
214 (let ((newform (list (car form) (nth 1 form)
215 (nth 2 form) (nth 3 form)))
216 (args (nthcdr 4 form)))
218 (or (memq (car args) '(:version :set-after))
219 (setq newform (nconc newform (list (car args)
221 (setq args (cdr (cdr args))))
225 (put 'custom-declare-variable 'byte-hunk-handler
226 'byte-compile-file-form-custom-declare-variable)
227 (defun byte-compile-file-form-custom-declare-variable (form)
228 ;; Bind defcustom'ed variables.
229 (if (memq 'free-vars byte-compile-warnings)
230 (setq byte-compile-bound-variables
231 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
232 (if (memq ':version (nthcdr 4 form))
233 ;; Make the variable uncustomizable.
234 `(defvar ,(nth 1 (nth 1 form)) ,(nth 1 (nth 2 form))
235 ,(substring (nth 3 form) (if (string-match "^[\t *]+" (nth 3 form))
238 ;; Ignore unsupported keyword(s).
239 (if (memq ':set-after (nthcdr 4 form))
240 (let ((newform (list (car form) (nth 1 form)
241 (nth 2 form) (nth 3 form)))
242 (args (nthcdr 4 form)))
244 (or (eq (car args) ':set-after)
245 (setq newform (nconc newform (list (car args)
247 (setq args (cdr (cdr args))))
251 ;; Unknown variables and functions.
252 (unless (boundp 'buffer-file-coding-system)
253 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
254 (unless (featurep 'xemacs)
255 (defalias 'Custom-make-dependencies 'ignore)
256 (defalias 'update-autoloads-from-directory 'ignore))
258 (defalias 'device-sound-enabled-p 'ignore)
259 (defalias 'play-sound-file 'ignore)
260 (defalias 'nndb-request-article 'ignore)
261 (defalias 'efs-re-read-dir 'ignore)
262 (defalias 'ange-ftp-re-read-dir 'ignore)
263 (defalias 'define-mail-user-agent 'ignore)
265 (defconst dgnushack-unexporting-files
266 (append '("dgnushack.el" "dgnuspath.el" "lpath.el")
267 (unless (or (condition-case code
270 (message "No w3: %s %s retrying..." code
271 (locate-library "w3-forms"))
273 ;; Maybe mis-configured Makefile is used (e.g.
274 ;; configured for FSFmacs but XEmacs is running).
275 (let ((lp (delete dgnushack-w3-directory
276 (copy-sequence load-path))))
277 (if (let ((load-path lp))
281 ;; If success, fix `load-path' for compiling.
284 (message " => fixed; W3DIR=%s"
286 (locate-library "w3-forms")))
288 (message " => ignored")
290 '("nnweb.el" "nnlistserv.el" "nnultimate.el"
291 "nnslashdot.el" "nnwarchive.el" "webmail.el"
292 "nnwfm.el" "nnrss.el"))
294 (progn (require 'bbdb) nil)
295 (error '("gnus-bbdb.el")))
296 (unless (featurep 'xemacs)
297 '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
298 "nnheaderxm.el" "smiley.el"))
299 (when (or (featurep 'xemacs) (<= emacs-major-version 20))
301 (when (and (fboundp 'base64-decode-string)
302 (subrp (symbol-function 'base64-decode-string)))
304 (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
306 "Files which will not be installed.")
308 (defconst dgnushack-exporting-files
309 (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
310 (dolist (file dgnushack-unexporting-files)
311 (setq files (delete file files)))
312 (sort files 'string-lessp))
313 "Files which will be compiled and installed.")
315 (defun dgnushack-exporting-files ()
316 "Print name of files which will be installed."
317 (princ (mapconcat 'identity dgnushack-exporting-files " ")))
319 (defun dgnushack-compile (&optional warn)
320 ;;(setq byte-compile-dynamic t)
322 (setq byte-compile-warnings
323 '(free-vars unresolved callargs redefine)))
324 (unless (locate-library "cus-edit")
325 (error "You do not seem to have Custom installed.
326 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
327 You also then need to add the following to the lisp/dgnushack.el file:
329 (push \"~/lisp/custom\" load-path)
331 Modify to suit your needs."))
334 (message "load-path=(\"%s\")"
335 (mapconcat 'identity load-path "\"\n \""))
337 (dolist (file dgnushack-exporting-files)
338 (setq file (expand-file-name file srcdir))
339 (when (and (file-exists-p
340 (setq elc (concat (file-name-nondirectory file) "c")))
341 (file-newer-than-file-p file elc))
344 (let ((files dgnushack-exporting-files)
345 ;;(byte-compile-generate-call-tree t)
347 ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
349 (when (featurep 'xemacs)
350 (setq gnus-xmas-glyph-directory "dummy"))
351 (while (setq file (pop files))
352 (setq file (expand-file-name file srcdir))
353 (when (or (not (file-exists-p
354 (setq elc (concat (file-name-nondirectory file) "c"))))
355 (file-newer-than-file-p file elc))
357 (byte-compile-file file))))))
359 (defun dgnushack-recompile ()
361 (byte-recompile-directory "." 0))
363 (defvar dgnushack-gnus-load-file (expand-file-name "gnus-load.el" srcdir))
364 (defvar dgnushack-cus-load-file (expand-file-name "cus-load.el" srcdir))
365 (defvar dgnushack-auto-load-file (expand-file-name "auto-autoloads.el" srcdir))
367 (defun dgnushack-make-cus-load ()
368 (when (condition-case nil
371 (let ((cusload-base-file dgnushack-cus-load-file))
372 (if (fboundp 'custom-make-dependencies)
373 (custom-make-dependencies)
374 (Custom-make-dependencies)))))
376 (defun dgnushack-make-auto-load ()
378 (let ((generated-autoload-file dgnushack-gnus-load-file)
379 (make-backup-files nil)
380 (autoload-package-name "gnus"))
381 (if (featurep 'xemacs)
383 (if (file-exists-p generated-autoload-file)
384 (delete-file generated-autoload-file))
385 (if (file-exists-p dgnushack-auto-load-file)
386 (delete-file dgnushack-auto-load-file)))
387 (with-temp-file generated-autoload-file
389 (if (featurep 'xemacs)
390 (let ((si:message (symbol-function 'message)))
391 (defun message (fmt &rest args)
392 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
393 (file-exists-p (file-name-nondirectory (car args))))
395 fmt (file-name-nondirectory (car args))))
396 ((string-equal "No autoloads found in %s" fmt))
397 ((string-equal "Generating autoloads for %s...done" fmt))
398 (t (apply si:message fmt args))))
400 (batch-update-autoloads)
401 (fset 'message si:message)))
402 (batch-update-autoloads))))
404 (defun dgnushack-make-load ()
405 (message (format "Generating %s..." dgnushack-gnus-load-file))
406 (with-temp-file dgnushack-gnus-load-file
407 (if (file-exists-p dgnushack-cus-load-file)
409 (insert-file-contents dgnushack-cus-load-file)
410 (delete-file dgnushack-cus-load-file)
411 (goto-char (point-min))
412 (search-forward ";;; Code:")
414 (delete-region (point-min) (point))
416 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
420 (goto-char (point-max))
421 (if (search-backward "custom-versions-load-alist" nil t)
424 (while (eq (char-after) ?\;)
427 (delete-region (point) (point-max))
430 ;;; gnus-load.el --- automatically extracted autoload
434 ;; smiley-* are duplicated. Remove them all.
435 (let ((point (point)))
436 (insert-file-contents dgnushack-gnus-load-file)
438 (while (search-forward "smiley-" nil t)
440 (if (looking-at "(autoload ")
441 (delete-region (point) (progn (forward-sexp) (point)))
444 (goto-char (point-max))
445 (when (search-backward "\n(provide " nil t)
447 (delete-region (point) (point-max)))
450 \(provide 'gnus-load)
453 ;;; version-control: never
454 ;;; no-byte-compile: t
455 ;;; no-update-autoloads: t
457 ;;; gnus-load.el ends here\n"))
458 (message (format "Compiling %s..." dgnushack-gnus-load-file))
459 (byte-compile-file dgnushack-gnus-load-file))
462 (defconst dgnushack-info-file-regexp-en
463 (let ((names '("gnus" "message" "emacs-mime"))
465 (while (setq name (pop names))
466 (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
467 (when names "\\|"))))
469 "Regexp matching English info files.")
471 (defconst dgnushack-info-file-regexp-ja
472 (let ((names '("gnus-ja" "message-ja"))
474 (while (setq name (pop names))
475 (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
476 (when names "\\|"))))
478 "Regexp matching Japanese info files.")
480 (defun dgnushack-remove-extra-files-in-package ()
481 "Remove extra files in the lisp directory of the XEmacs package."
482 (let ((lisp-dir (expand-file-name (concat "lisp/"
484 (cadr command-line-args-left)
487 (car command-line-args-left))))
488 (when (file-directory-p lisp-dir)
490 (dolist (file dgnushack-exporting-files)
491 (setq files (nconc files (list file (concat file "c")))))
492 (dolist (file (directory-files lisp-dir nil nil t t))
493 (unless (member file files)
494 (setq file (expand-file-name file lisp-dir))
495 (message "Removing %s..." file)
500 (defun dgnushack-install-package-manifest ()
501 "Install MANIFEST file as an XEmacs package."
502 (let* ((package-dir (car command-line-args-left))
503 (product-name (cadr command-line-args-left))
504 (name (expand-file-name (concat "pkginfo/MANIFEST." product-name)
507 (message "Generating %s..." name)
509 (insert "pkginfo/MANIFEST." product-name "\n")
510 (let ((lisp-dir (concat "lisp/" product-name "/"))
511 (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
513 (while (setq file (pop files))
514 (unless (member file dgnushack-unexporting-files)
515 (insert lisp-dir file "\n")))
517 (sort (directory-files "../texi/" nil
518 (concat dgnushack-info-file-regexp-en
520 dgnushack-info-file-regexp-ja)
523 (while (setq file (pop files))
524 (insert "info/" file "\n"))))))
527 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
528 (if (condition-case nil
530 (describe-key-briefly '((())) nil)
532 (wrong-number-of-arguments nil);; Old Emacsen.
537 (insert (funcall 'describe-key-briefly ,key))
538 (funcall 'describe-key-briefly ,key))
539 `(funcall 'describe-key-briefly ,key))))
541 ;;; dgnushack.el ends here