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 (defvar dgnushack-w3-dir (let ((w3dir (getenv "W3DIR")))
56 (unless (zerop (length w3dir))
57 (file-name-as-directory w3dir))))
58 (when dgnushack-w3-dir
59 (push dgnushack-w3-dir load-path))
61 ;; If we are building w3 in a different directory than the source
62 ;; directory, we must read *.el from source directory and write *.elc
63 ;; into the building directory. For that, we define this function
64 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
65 (defun byte-compile-dest-file (filename)
66 "Convert an Emacs Lisp source file name to a compiled file name.
67 In addition, remove directory name part from FILENAME."
68 (setq filename (byte-compiler-base-file-name filename))
69 (setq filename (file-name-sans-versions filename))
70 (setq filename (file-name-nondirectory filename))
71 (if (memq system-type '(win32 w32 mswindows windows-nt))
72 (setq filename (downcase filename)))
73 (cond ((eq system-type 'vax-vms)
74 (concat (substring filename 0 (string-match ";" filename)) "c"))
75 ((string-match emacs-lisp-file-regexp filename)
76 (concat (substring filename 0 (match-beginning 0)) ".elc"))
77 (t (concat filename ".elc"))))
81 (unless (fboundp 'si:byte-optimize-form-code-walker)
82 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
83 (setq max-specpdl-size 3000)
84 (defalias 'si:byte-optimize-form-code-walker
85 (symbol-function 'byte-optimize-form-code-walker))
86 (defun byte-optimize-form-code-walker (form for-effect)
87 (if (and for-effect (memq (car-safe form) '(and or)))
88 ;; Fix bug in and/or forms.
90 (backwards (reverse (cdr form))))
92 (null (setcar backwards
93 (byte-optimize-form (car backwards) t))))
94 (setq backwards (cdr backwards)))
95 (if (and (cdr form) (null backwards))
97 " all subforms of %s called for effect; deleted" form))
99 (let ((head backwards))
100 (while (setq backwards (cdr backwards))
101 (setcar backwards (byte-optimize-form (car backwards)
103 (cons fn (nreverse head)))))
104 (si:byte-optimize-form-code-walker form for-effect)))
105 (byte-compile 'byte-optimize-form-code-walker))
107 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
111 (wrong-number-of-arguments
112 ;; Optimize byte code for `char-after'.
113 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
114 (defun byte-optimize-char-after (form)
115 (if (null (cdr form))
116 '(char-after (point))
121 (wrong-number-of-arguments
122 ;; Optimize byte code for `char-before'.
123 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
124 (defun byte-optimize-char-before (form)
125 (if (null (cdr form))
126 '(char-before (point))
129 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
132 (load "~/.lpath.el" t nil t)
133 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
135 ;; Don't load path-util until `char-after' and `char-before' have been
136 ;; optimized because it requires `poe' and then modify the functions.
137 (or (featurep 'path-util)
138 (load "apel/path-util"))
141 (unless (module-installed-p 'mel)
142 ;; FLIM 1.14 may have installed in two "flim" subdirectories.
143 (push (expand-file-name "flim"
144 (file-name-directory (get-latest-path "^apel$" t)))
146 (unless (module-installed-p 'mel)
148 FLIM package does not found in %s.
149 Try to re-configure with --with-addpath=FLIM_PATH and run make again.
156 (push srcdir load-path)
157 (load (expand-file-name "lpath.el" srcdir) nil t t)
159 ;; Bind functions defined by `defun-maybe'.
160 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
161 (defun byte-compile-file-form-defun-maybe (form)
162 (if (and (not (fboundp (nth 1 form)))
163 (memq 'unresolved byte-compile-warnings))
164 (setq byte-compile-function-environment
165 (cons (cons (nth 1 form)
166 (cons 'lambda (cdr (cdr form))))
167 byte-compile-function-environment)))
171 :symbol-for-testing-whether-colon-keyword-is-available-or-not
174 (dolist (keyword '(:button-keymap :data :file :mime-handle
175 :key-type :value-type))
176 (set keyword keyword))))
178 ;; If you are using Mule 2.3 based on Emacs 19.34, you may also put the
179 ;; following lines in your .emacs file, before gnus related modules are
180 ;; loaded. It is not always necessary. However if it is done, you will
181 ;; be able to load or evaluate gnus related *.el (not compiled) files.
182 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
185 (setq :version ':version
186 :set-after ':set-after)
188 (defadvice custom-handle-keyword
189 (around dont-signal-an-error-even-if-unsupported-keyword-is-given
191 "Don't signal an error even if unsupported keyword is given."
192 (if (not (memq (ad-get-arg 1) '(:version :set-after)))
194 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
197 (put 'custom-declare-face 'byte-optimizer
198 'byte-optimize-ignore-unsupported-custom-keywords)
199 (put 'custom-declare-group 'byte-optimizer
200 'byte-optimize-ignore-unsupported-custom-keywords)
201 (defun byte-optimize-ignore-unsupported-custom-keywords (form)
202 (if (or (memq ':version (nthcdr 4 form))
203 (memq ':set-after (nthcdr 4 form)))
204 (let ((newform (list (car form) (nth 1 form)
205 (nth 2 form) (nth 3 form)))
206 (args (nthcdr 4 form)))
208 (or (memq (car args) '(:version :set-after))
209 (setq newform (nconc newform (list (car args)
211 (setq args (cdr (cdr args))))
215 (put 'custom-declare-variable 'byte-hunk-handler
216 'byte-compile-file-form-custom-declare-variable)
217 (defun byte-compile-file-form-custom-declare-variable (form)
218 ;; Bind defcustom'ed variables.
219 (if (memq 'free-vars byte-compile-warnings)
220 (setq byte-compile-bound-variables
221 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
222 (if (memq ':version (nthcdr 4 form))
223 ;; Make the variable uncustomizable.
224 `(defvar ,(nth 1 (nth 1 form)) ,(nth 1 (nth 2 form))
225 ,(substring (nth 3 form) (if (string-match "^[\t *]+" (nth 3 form))
228 ;; Ignore unsupported keyword(s).
229 (if (memq ':set-after (nthcdr 4 form))
230 (let ((newform (list (car form) (nth 1 form)
231 (nth 2 form) (nth 3 form)))
232 (args (nthcdr 4 form)))
234 (or (eq (car args) ':set-after)
235 (setq newform (nconc newform (list (car args)
237 (setq args (cdr (cdr args))))
241 ;; Unknown variables and functions.
242 (unless (boundp 'buffer-file-coding-system)
243 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
244 (unless (featurep 'xemacs)
245 (defalias 'Custom-make-dependencies 'ignore)
246 (defalias 'update-autoloads-from-directory 'ignore))
247 (autoload 'texinfo-parse-line-arg "texinfmt")
249 (unless (fboundp 'with-temp-buffer)
250 ;; Pickup some macros.
253 (defalias 'device-sound-enabled-p 'ignore)
254 (defalias 'play-sound-file 'ignore)
255 (defalias 'nndb-request-article 'ignore)
256 (defalias 'efs-re-read-dir 'ignore)
257 (defalias 'ange-ftp-re-read-dir 'ignore)
258 (defalias 'define-mail-user-agent 'ignore)
260 (defconst dgnushack-unexporting-files
261 (append '("dgnushack.el" "dgnuspath.el" "lpath.el" "ptexinfmt.el")
262 (unless (or (condition-case code
265 (message "No w3: %s %s retrying..." code
266 (locate-library "w3-forms"))
268 ;; Maybe mis-configured Makefile is used (e.g.
269 ;; configured for FSFmacs but XEmacs is running).
270 (let ((lp (delete dgnushack-w3-dir
271 (copy-sequence load-path))))
272 (if (let ((load-path lp))
276 ;; If success, fix `load-path' for compiling.
279 (message " => fixed; W3DIR=%s"
281 (locate-library "w3-forms")))
283 (message " => ignored")
285 '("nnweb.el" "nnlistserv.el" "nnultimate.el"
286 "nnslashdot.el" "nnwarchive.el" "webmail.el"
289 (progn (require 'bbdb) nil)
290 (error '("gnus-bbdb.el")))
291 (unless (featurep 'xemacs)
292 '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
293 "nnheaderxm.el" "smiley.el"))
294 (when (or (featurep 'xemacs) (<= emacs-major-version 20))
296 (when (and (fboundp 'base64-decode-string)
297 (subrp (symbol-function 'base64-decode-string)))
299 (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
301 "Files which will not be installed.")
303 (defconst dgnushack-exporting-files
304 (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
305 (dolist (file dgnushack-unexporting-files)
306 (setq files (delete file files)))
307 (sort files 'string-lessp))
308 "Files which will be compiled and installed.")
310 (defun dgnushack-exporting-files ()
311 "Print name of files which will be installed."
312 (princ (mapconcat 'identity dgnushack-exporting-files " ")))
314 (defun dgnushack-compile (&optional warn)
315 ;;(setq byte-compile-dynamic t)
317 (setq byte-compile-warnings
318 '(free-vars unresolved callargs redefine)))
319 (unless (locate-library "cus-edit")
320 (error "You do not seem to have Custom installed.
321 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
322 You also then need to add the following to the lisp/dgnushack.el file:
324 (push \"~/lisp/custom\" load-path)
326 Modify to suit your needs."))
329 (message "load-path=(\"%s\")"
330 (mapconcat 'identity load-path "\"\n \""))
332 (dolist (file dgnushack-exporting-files)
333 (setq file (expand-file-name file srcdir))
334 (when (and (file-exists-p
335 (setq elc (concat (file-name-nondirectory file) "c")))
336 (file-newer-than-file-p file elc))
339 (let ((files dgnushack-exporting-files)
340 ;;(byte-compile-generate-call-tree t)
342 (while (setq file (pop files))
343 (setq file (expand-file-name file srcdir))
344 (when (or (not (file-exists-p
345 (setq elc (concat (file-name-nondirectory file) "c"))))
346 (file-newer-than-file-p file elc))
348 (byte-compile-file file))))))
350 (defun dgnushack-recompile ()
352 (byte-recompile-directory "." 0))
355 (defun dgnushack-texi-add-suffix-and-format ()
356 (dgnushack-texi-format t))
358 (defun dgnushack-texi-format (&optional addsuffix)
359 (if (not noninteractive)
360 (error "batch-texinfo-format may only be used -batch."))
362 (let ((auto-save-default nil)
363 (find-file-run-dired nil)
364 coding-system-for-write
365 output-coding-system)
369 (while command-line-args-left
370 (setq file (expand-file-name (car command-line-args-left)))
371 (cond ((not (file-exists-p file))
372 (message ">> %s does not exist!" file)
374 command-line-args-left (cdr command-line-args-left)))
375 ((file-directory-p file)
376 (setq command-line-args-left
377 (nconc (directory-files file nil nil t)
378 (cdr command-line-args-left))))
380 (setq files (cons file files)
381 command-line-args-left (cdr command-line-args-left)))))
382 (while (setq file (pop files))
385 (if buffer-file-name (kill-buffer (current-buffer)))
387 (buffer-disable-undo (current-buffer))
389 (setq output-coding-system (symbol-value
390 'file-coding-system))
391 (setq coding-system-for-write buffer-file-coding-system))
392 ;; Remove ignored areas first.
393 (while (re-search-forward "^@ignore[\t\r ]*$" nil t)
394 (delete-region (match-beginning 0)
395 (if (re-search-forward
396 "^@end[\t ]+ignore[\t\r ]*$" nil t)
399 (goto-char (point-min))
400 ;; Add suffix if it is needed.
403 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
404 (not (string-match "\\.info$" (match-string 1))))
406 (goto-char (point-min)))
407 ;; process @include before updating node
408 ;; This might produce some problem if we use @lowersection or
410 (let ((input-directory default-directory)
411 (texinfo-command-end))
412 (while (re-search-forward "^@include" nil t)
413 (setq texinfo-command-end (point))
414 (let ((filename (concat input-directory
415 (texinfo-parse-line-arg))))
416 (re-search-backward "^@include")
417 (delete-region (point) (save-excursion
420 (message "Reading included file: %s" filename)
426 (car (cdr (insert-file-contents filename)))))
427 (goto-char (point-min))
428 ;; Remove `@setfilename' line from included file,
429 ;; if any, so @setfilename command not duplicated.
430 (if (re-search-forward "^@setfilename"
437 (delete-region (point) (save-excursion
441 (texinfo-every-node-update)
442 (set-buffer-modified-p nil)
443 (message "texinfo formatting %s..." file)
444 (texinfo-format-buffer nil)
445 (if (buffer-modified-p)
446 (progn (message "Saving modified %s" (buffer-file-name))
449 (message ">> Error: %s" (prin1-to-string err))
450 (message ">> point at")
451 (let ((s (buffer-substring (point)
455 (while (setq tem (string-match "\n+" s tem))
456 (setq s (concat (substring s 0 (match-beginning 0))
458 (substring s (match-end 0)))
462 (kill-emacs error))))
465 (defconst dgnushack-info-file-regexp-en
466 (let ((names '("gnus" "message" "emacs-mime"))
468 (while (setq name (pop names))
469 (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
470 (when names "\\|"))))
472 "Regexp matching English info files.")
474 (defconst dgnushack-info-file-regexp-ja
475 (let ((names '("gnus-ja" "message-ja"))
477 (while (setq name (pop names))
478 (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
479 (when names "\\|"))))
481 "Regexp matching Japanese info files.")
483 (defun dgnushack-make-autoloads ()
484 "Make auto-autoloads.el, custom-load.el and then compile them."
485 (let ((auto-autoloads (expand-file-name "auto-autoloads.el" srcdir))
486 (custom-load (expand-file-name "custom-load.el" srcdir)))
487 (unless (and (file-exists-p auto-autoloads)
488 (file-exists-p (concat auto-autoloads "c"))
489 (file-newer-than-file-p (concat auto-autoloads "c")
491 (file-exists-p custom-load)
492 (file-exists-p (concat custom-load "c"))
493 (file-newer-than-file-p (concat custom-load "c")
495 (let (make-backup-files)
496 (message "Updating autoloads for directory %s..." default-directory)
497 (let ((generated-autoload-file auto-autoloads)
498 (si:message (symbol-function 'message))
500 (defun message (fmt &rest args)
501 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
502 (file-exists-p (file-name-nondirectory (car args))))
504 fmt (file-name-nondirectory (car args))))
505 ((string-equal "No autoloads found in %s" fmt))
506 ((string-equal "Generating autoloads for %s...done" fmt))
507 (t (apply si:message fmt args))))
509 (update-autoloads-from-directory default-directory)
510 (fset 'message si:message)))
511 (byte-compile-file auto-autoloads)
513 (let ((standard-output (current-buffer)))
514 (Custom-make-dependencies "."))
515 (message "%s" (buffer-string)))
517 (byte-compile-file custom-load)))))
519 (defun dgnushack-remove-extra-files-in-package ()
520 "Remove extra files in the lisp directory of the XEmacs package."
521 (let ((lisp-dir (expand-file-name (concat "lisp/"
523 (cadr command-line-args-left)
526 (car command-line-args-left))))
527 (when (file-directory-p lisp-dir)
529 (dolist (file dgnushack-exporting-files)
530 (setq files (nconc files (list file (concat file "c")))))
531 (dolist (file (directory-files lisp-dir nil nil t t))
532 (unless (member file files)
533 (setq file (expand-file-name file lisp-dir))
534 (message "Removing %s..." file)
539 (defun dgnushack-install-package-manifest ()
540 "Install MANIFEST file as an XEmacs package."
541 (let* ((package-dir (car command-line-args-left))
542 (product-name (cadr command-line-args-left))
543 (name (expand-file-name (concat "pkginfo/MANIFEST." product-name)
546 (message "Generating %s..." name)
548 (insert "pkginfo/MANIFEST." product-name "\n")
549 (let ((lisp-dir (concat "lisp/" product-name "/"))
550 (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
552 (while (setq file (pop files))
553 (unless (member file dgnushack-unexporting-files)
554 (insert lisp-dir file "\n")))
556 (sort (directory-files "../texi/" nil
557 (concat dgnushack-info-file-regexp-en
559 dgnushack-info-file-regexp-ja)
562 (while (setq file (pop files))
563 (insert "info/" file "\n"))))))
566 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
567 (if (condition-case nil
569 (describe-key-briefly '((())) nil)
571 (wrong-number-of-arguments nil);; Old Emacsen.
576 (insert (funcall 'describe-key-briefly ,key))
577 (funcall 'describe-key-briefly ,key))
578 `(funcall 'describe-key-briefly ,key))))
580 ;;; dgnushack.el ends here