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 may have been defined in egg.el.
54 (load "cl-macs" nil t))
56 (defvar srcdir (or (getenv "srcdir") "."))
58 (defvar dgnushack-w3-dir (let ((w3dir (getenv "W3DIR")))
59 (unless (zerop (length w3dir))
60 (file-name-as-directory w3dir))))
61 (when dgnushack-w3-dir
62 (push dgnushack-w3-dir load-path))
64 ;; If we are building w3 in a different directory than the source
65 ;; directory, we must read *.el from source directory and write *.elc
66 ;; into the building directory. For that, we define this function
67 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
68 (defun byte-compile-dest-file (filename)
69 "Convert an Emacs Lisp source file name to a compiled file name.
70 In addition, remove directory name part from FILENAME."
71 (setq filename (byte-compiler-base-file-name filename))
72 (setq filename (file-name-sans-versions filename))
73 (setq filename (file-name-nondirectory filename))
74 (if (memq system-type '(win32 w32 mswindows windows-nt))
75 (setq filename (downcase filename)))
76 (cond ((eq system-type 'vax-vms)
77 (concat (substring filename 0 (string-match ";" filename)) "c"))
78 ((string-match emacs-lisp-file-regexp filename)
79 (concat (substring filename 0 (match-beginning 0)) ".elc"))
80 (t (concat filename ".elc"))))
84 (unless (fboundp 'si:byte-optimize-form-code-walker)
85 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
86 (setq max-specpdl-size 3000)
87 (defalias 'si:byte-optimize-form-code-walker
88 (symbol-function 'byte-optimize-form-code-walker))
89 (defun byte-optimize-form-code-walker (form for-effect)
90 (if (and for-effect (memq (car-safe form) '(and or)))
91 ;; Fix bug in and/or forms.
93 (backwards (reverse (cdr form))))
95 (null (setcar backwards
96 (byte-optimize-form (car backwards) t))))
97 (setq backwards (cdr backwards)))
98 (if (and (cdr form) (null backwards))
100 " all subforms of %s called for effect; deleted" form))
102 (let ((head backwards))
103 (while (setq backwards (cdr backwards))
104 (setcar backwards (byte-optimize-form (car backwards)
106 (cons fn (nreverse head)))))
107 (si:byte-optimize-form-code-walker form for-effect)))
108 (byte-compile 'byte-optimize-form-code-walker))
110 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
114 (wrong-number-of-arguments
115 ;; Optimize byte code for `char-after'.
116 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
117 (defun byte-optimize-char-after (form)
118 (if (null (cdr form))
119 '(char-after (point))
124 (wrong-number-of-arguments
125 ;; Optimize byte code for `char-before'.
126 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
127 (defun byte-optimize-char-before (form)
128 (if (null (cdr form))
129 '(char-before (point))
132 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
135 (load "~/.lpath.el" t nil t)
136 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
138 ;; Don't load path-util until `char-after' and `char-before' have been
139 ;; optimized because it requires `poe' and then modify the functions.
140 (or (featurep 'path-util)
141 (load "apel/path-util"))
144 (unless (module-installed-p 'mel)
145 ;; FLIM 1.14 may have installed in two "flim" subdirectories.
146 (push (expand-file-name "flim"
147 (file-name-directory (get-latest-path "^apel$" t)))
149 (unless (module-installed-p 'mel)
151 FLIM package does not found in %s.
152 Try to re-configure with --with-addpath=FLIM_PATH and run make again.
159 (push srcdir load-path)
160 (load (expand-file-name "lpath.el" srcdir) nil t t)
162 ;; Bind functions defined by `defun-maybe'.
163 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
164 (defun byte-compile-file-form-defun-maybe (form)
165 (if (and (not (fboundp (nth 1 form)))
166 (memq 'unresolved byte-compile-warnings))
167 (setq byte-compile-function-environment
168 (cons (cons (nth 1 form)
169 (cons 'lambda (cdr (cdr form))))
170 byte-compile-function-environment)))
174 :symbol-for-testing-whether-colon-keyword-is-available-or-not
177 (dolist (keyword '(:button-keymap :data :file :mime-handle
178 :key-type :value-type))
179 (set keyword keyword))))
181 ;; If you are using Mule 2.3 based on Emacs 19.34, you may also put the
182 ;; following lines in your .emacs file, before gnus related modules are
183 ;; loaded. It is not always necessary. However if it is done, you will
184 ;; be able to load or evaluate gnus related *.el (not compiled) files.
185 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
188 (setq :version ':version
189 :set-after ':set-after)
191 (defadvice custom-handle-keyword
192 (around dont-signal-an-error-even-if-unsupported-keyword-is-given
194 "Don't signal an error even if unsupported keyword is given."
195 (if (not (memq (ad-get-arg 1) '(:version :set-after)))
197 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
200 (put 'custom-declare-face 'byte-optimizer
201 'byte-optimize-ignore-unsupported-custom-keywords)
202 (put 'custom-declare-group 'byte-optimizer
203 'byte-optimize-ignore-unsupported-custom-keywords)
204 (defun byte-optimize-ignore-unsupported-custom-keywords (form)
205 (if (or (memq ':version (nthcdr 4 form))
206 (memq ':set-after (nthcdr 4 form)))
207 (let ((newform (list (car form) (nth 1 form)
208 (nth 2 form) (nth 3 form)))
209 (args (nthcdr 4 form)))
211 (or (memq (car args) '(:version :set-after))
212 (setq newform (nconc newform (list (car args)
214 (setq args (cdr (cdr args))))
218 (put 'custom-declare-variable 'byte-hunk-handler
219 'byte-compile-file-form-custom-declare-variable)
220 (defun byte-compile-file-form-custom-declare-variable (form)
221 ;; Bind defcustom'ed variables.
222 (if (memq 'free-vars byte-compile-warnings)
223 (setq byte-compile-bound-variables
224 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
225 (if (memq ':version (nthcdr 4 form))
226 ;; Make the variable uncustomizable.
227 `(defvar ,(nth 1 (nth 1 form)) ,(nth 1 (nth 2 form))
228 ,(substring (nth 3 form) (if (string-match "^[\t *]+" (nth 3 form))
231 ;; Ignore unsupported keyword(s).
232 (if (memq ':set-after (nthcdr 4 form))
233 (let ((newform (list (car form) (nth 1 form)
234 (nth 2 form) (nth 3 form)))
235 (args (nthcdr 4 form)))
237 (or (eq (car args) ':set-after)
238 (setq newform (nconc newform (list (car args)
240 (setq args (cdr (cdr args))))
244 ;; Unknown variables and functions.
245 (unless (boundp 'buffer-file-coding-system)
246 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
247 (unless (featurep 'xemacs)
248 (defalias 'Custom-make-dependencies 'ignore)
249 (defalias 'update-autoloads-from-directory 'ignore))
250 (autoload 'texinfo-parse-line-arg "texinfmt")
252 (defalias 'device-sound-enabled-p 'ignore)
253 (defalias 'play-sound-file 'ignore)
254 (defalias 'nndb-request-article 'ignore)
255 (defalias 'efs-re-read-dir 'ignore)
256 (defalias 'ange-ftp-re-read-dir 'ignore)
257 (defalias 'define-mail-user-agent 'ignore)
259 (defconst dgnushack-unexporting-files
260 (append '("dgnushack.el" "dgnuspath.el" "lpath.el" "ptexinfmt.el")
261 (unless (or (condition-case code
264 (message "No w3: %s %s retrying..." code
265 (locate-library "w3-forms"))
267 ;; Maybe mis-configured Makefile is used (e.g.
268 ;; configured for FSFmacs but XEmacs is running).
269 (let ((lp (delete dgnushack-w3-dir
270 (copy-sequence load-path))))
271 (if (let ((load-path lp))
275 ;; If success, fix `load-path' for compiling.
278 (message " => fixed; W3DIR=%s"
280 (locate-library "w3-forms")))
282 (message " => ignored")
284 '("nnweb.el" "nnlistserv.el" "nnultimate.el"
285 "nnslashdot.el" "nnwarchive.el" "webmail.el"
288 (progn (require 'bbdb) nil)
289 (error '("gnus-bbdb.el")))
290 (unless (featurep 'xemacs)
291 '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
292 "nnheaderxm.el" "smiley.el"))
293 (when (or (featurep 'xemacs) (<= emacs-major-version 20))
295 (when (and (fboundp 'base64-decode-string)
296 (subrp (symbol-function 'base64-decode-string)))
298 (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
300 "Files which will not be installed.")
302 (defconst dgnushack-exporting-files
303 (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
304 (dolist (file dgnushack-unexporting-files)
305 (setq files (delete file files)))
306 (sort files 'string-lessp))
307 "Files which will be compiled and installed.")
309 (defun dgnushack-exporting-files ()
310 "Print name of files which will be installed."
311 (princ (mapconcat 'identity dgnushack-exporting-files " ")))
313 (defun dgnushack-compile (&optional warn)
314 ;;(setq byte-compile-dynamic t)
316 (setq byte-compile-warnings
317 '(free-vars unresolved callargs redefine)))
318 (unless (locate-library "cus-edit")
319 (error "You do not seem to have Custom installed.
320 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
321 You also then need to add the following to the lisp/dgnushack.el file:
323 (push \"~/lisp/custom\" load-path)
325 Modify to suit your needs."))
328 (message "load-path=(\"%s\")"
329 (mapconcat 'identity load-path "\"\n \""))
331 (dolist (file dgnushack-exporting-files)
332 (setq file (expand-file-name file srcdir))
333 (when (and (file-exists-p
334 (setq elc (concat (file-name-nondirectory file) "c")))
335 (file-newer-than-file-p file elc))
338 (let ((files dgnushack-exporting-files)
339 ;;(byte-compile-generate-call-tree t)
341 (while (setq file (pop files))
342 (setq file (expand-file-name file srcdir))
343 (when (or (not (file-exists-p
344 (setq elc (concat (file-name-nondirectory file) "c"))))
345 (file-newer-than-file-p file elc))
347 (byte-compile-file file))))))
349 (defun dgnushack-recompile ()
351 (byte-recompile-directory "." 0))
354 (defun dgnushack-texi-add-suffix-and-format ()
355 (dgnushack-texi-format t))
357 (defun dgnushack-texi-format (&optional addsuffix)
358 (if (not noninteractive)
359 (error "batch-texinfo-format may only be used -batch."))
361 (let ((auto-save-default nil)
362 (find-file-run-dired nil)
363 coding-system-for-write
364 output-coding-system)
368 (while command-line-args-left
369 (setq file (expand-file-name (car command-line-args-left)))
370 (cond ((not (file-exists-p file))
371 (message ">> %s does not exist!" file)
373 command-line-args-left (cdr command-line-args-left)))
374 ((file-directory-p file)
375 (setq command-line-args-left
376 (nconc (directory-files file nil nil t)
377 (cdr command-line-args-left))))
379 (setq files (cons file files)
380 command-line-args-left (cdr command-line-args-left)))))
381 (while (setq file (pop files))
384 (if buffer-file-name (kill-buffer (current-buffer)))
386 (buffer-disable-undo (current-buffer))
388 (setq output-coding-system (symbol-value
389 'file-coding-system))
390 (setq coding-system-for-write buffer-file-coding-system))
391 ;; Remove ignored areas first.
392 (while (re-search-forward "^@ignore[\t\r ]*$" nil t)
393 (delete-region (match-beginning 0)
394 (if (re-search-forward
395 "^@end[\t ]+ignore[\t\r ]*$" nil t)
398 (goto-char (point-min))
399 ;; formerly EMACSINFOHACK in texi/Makefile.
400 (while (re-search-forward "@\\(end \\)?ifnottex\n*" nil t)
402 (goto-char (point-min))
403 ;; Add suffix if it is needed.
406 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
407 (not (string-match "\\.info$" (match-string 1))))
409 (goto-char (point-min)))
410 ;; process @include before updating node
411 ;; This might produce some problem if we use @lowersection or
413 (let ((input-directory default-directory)
414 (texinfo-command-end))
415 (while (re-search-forward "^@include" nil t)
416 (setq texinfo-command-end (point))
417 (let ((filename (concat input-directory
418 (texinfo-parse-line-arg))))
419 (re-search-backward "^@include")
420 (delete-region (point) (save-excursion
423 (message "Reading included file: %s" filename)
429 (car (cdr (insert-file-contents filename)))))
430 (goto-char (point-min))
431 ;; Remove `@setfilename' line from included file,
432 ;; if any, so @setfilename command not duplicated.
433 (if (re-search-forward "^@setfilename"
440 (delete-region (point) (save-excursion
444 (texinfo-every-node-update)
445 (set-buffer-modified-p nil)
446 (message "texinfo formatting %s..." file)
447 (texinfo-format-buffer nil)
448 (if (buffer-modified-p)
449 (progn (message "Saving modified %s" (buffer-file-name))
452 (message ">> Error: %s" (prin1-to-string err))
453 (message ">> point at")
454 (let ((s (buffer-substring (point)
458 (while (setq tem (string-match "\n+" s tem))
459 (setq s (concat (substring s 0 (match-beginning 0))
461 (substring s (match-end 0)))
465 (kill-emacs error))))
468 (defconst dgnushack-info-file-regexp-en
469 (let ((names '("gnus" "message" "emacs-mime"))
471 (while (setq name (pop names))
472 (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
473 (when names "\\|"))))
475 "Regexp matching English info files.")
477 (defconst dgnushack-info-file-regexp-ja
478 (let ((names '("gnus-ja" "message-ja"))
480 (while (setq name (pop names))
481 (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
482 (when names "\\|"))))
484 "Regexp matching Japanese info files.")
486 (defun dgnushack-make-autoloads ()
487 "Make auto-autoloads.el, custom-load.el and then compile them."
488 (let ((auto-autoloads (expand-file-name "auto-autoloads.el" srcdir))
489 (custom-load (expand-file-name "custom-load.el" srcdir)))
490 (unless (and (file-exists-p auto-autoloads)
491 (file-exists-p (concat auto-autoloads "c"))
492 (file-newer-than-file-p (concat auto-autoloads "c")
494 (file-exists-p custom-load)
495 (file-exists-p (concat custom-load "c"))
496 (file-newer-than-file-p (concat custom-load "c")
498 (let (make-backup-files)
499 (message "Updating autoloads for directory %s..." default-directory)
500 (let ((generated-autoload-file auto-autoloads)
501 (si:message (symbol-function 'message))
503 (defun message (fmt &rest args)
504 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
505 (file-exists-p (file-name-nondirectory (car args))))
507 fmt (file-name-nondirectory (car args))))
508 ((string-equal "No autoloads found in %s" fmt))
509 ((string-equal "Generating autoloads for %s...done" fmt))
510 (t (apply si:message fmt args))))
512 (update-autoloads-from-directory default-directory)
513 (fset 'message si:message)))
514 (byte-compile-file auto-autoloads)
516 (let ((standard-output (current-buffer)))
517 (Custom-make-dependencies "."))
518 (message "%s" (buffer-string)))
520 (byte-compile-file custom-load)))))
522 (defun dgnushack-remove-extra-files-in-package ()
523 "Remove extra files in the lisp directory of the XEmacs package."
524 (let ((lisp-dir (expand-file-name (concat "lisp/"
526 (cadr command-line-args-left)
529 (car command-line-args-left))))
530 (when (file-directory-p lisp-dir)
532 (dolist (file dgnushack-exporting-files)
533 (setq files (nconc files (list file (concat file "c")))))
534 (dolist (file (directory-files lisp-dir nil nil t t))
535 (unless (member file files)
536 (setq file (expand-file-name file lisp-dir))
537 (message "Removing %s..." file)
542 (defun dgnushack-install-package-manifest ()
543 "Install MANIFEST file as an XEmacs package."
544 (let* ((package-dir (car command-line-args-left))
545 (product-name (cadr command-line-args-left))
546 (name (expand-file-name (concat "pkginfo/MANIFEST." product-name)
549 (message "Generating %s..." name)
551 (insert "pkginfo/MANIFEST." product-name "\n")
552 (let ((lisp-dir (concat "lisp/" product-name "/"))
553 (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
555 (while (setq file (pop files))
556 (unless (member file dgnushack-unexporting-files)
557 (insert lisp-dir file "\n")))
559 (sort (directory-files "../texi/" nil
560 (concat dgnushack-info-file-regexp-en
562 dgnushack-info-file-regexp-ja)
565 (while (setq file (pop files))
566 (insert "info/" file "\n"))))))
569 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
570 (if (condition-case nil
572 (describe-key-briefly '((())) nil)
574 (wrong-number-of-arguments nil);; Old Emacsen.
579 (insert (funcall 'describe-key-briefly ,key))
580 (funcall 'describe-key-briefly ,key))
581 `(funcall 'describe-key-briefly ,key))))
583 ;;; dgnushack.el ends here