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 (defvar *predefined-category*)
33 (defvar coding-category-list)
34 (if (featurep 'xemacs)
35 (fset 'set-coding-priority 'ignore)
36 (fset 'coding-priority-list 'ignore)
37 (fset 'set-coding-priority-list 'ignore))
38 (cond ((and (featurep 'xemacs) (featurep 'mule))
39 (if (memq 'shift-jis (coding-priority-list))
40 (set-coding-priority-list
41 (nconc (delq 'shift-jis (coding-priority-list)) '(shift-jis)))))
43 (put '*coding-category-sjis* 'priority (length *predefined-category*)))
45 (if (memq 'coding-category-sjis coding-category-list)
47 (nconc (delq 'coding-category-sjis coding-category-list)
48 '(coding-category-sjis))))))
54 (defvar srcdir (or (getenv "srcdir") "."))
56 (push (or (getenv "W3DIR") (expand-file-name "../../w3/lisp/" srcdir))
58 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
60 ;; If we are building w3 in a different directory than the source
61 ;; directory, we must read *.el from source directory and write *.elc
62 ;; into the building directory. For that, we define this function
63 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
64 (defun byte-compile-dest-file (filename)
65 "Convert an Emacs Lisp source file name to a compiled file name.
66 In addition, remove directory name part from FILENAME."
67 (setq filename (byte-compiler-base-file-name filename))
68 (setq filename (file-name-sans-versions filename))
69 (setq filename (file-name-nondirectory filename))
70 (if (memq system-type '(win32 w32 mswindows windows-nt))
71 (setq filename (downcase filename)))
72 (cond ((eq system-type 'vax-vms)
73 (concat (substring filename 0 (string-match ";" filename)) "c"))
74 ((string-match emacs-lisp-file-regexp filename)
75 (concat (substring filename 0 (match-beginning 0)) ".elc"))
76 (t (concat filename ".elc"))))
80 (unless (fboundp 'si:byte-optimize-form-code-walker)
81 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
82 (setq max-specpdl-size 3000)
83 (fset 'si:byte-optimize-form-code-walker
84 (symbol-function 'byte-optimize-form-code-walker))
85 (defun byte-optimize-form-code-walker (form for-effect)
86 (if (and for-effect (memq (car-safe form) '(and or)))
87 ;; Fix bug in and/or forms.
89 (backwards (reverse (cdr form))))
91 (null (setcar backwards
92 (byte-optimize-form (car backwards) t))))
93 (setq backwards (cdr backwards)))
94 (if (and (cdr form) (null backwards))
96 " all subforms of %s called for effect; deleted" form))
98 (let ((head backwards))
99 (while (setq backwards (cdr backwards))
100 (setcar backwards (byte-optimize-form (car backwards)
102 (cons fn (nreverse head)))))
103 (si:byte-optimize-form-code-walker form for-effect)))
104 (byte-compile 'byte-optimize-form-code-walker))
106 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
109 (load "~/.lpath.el" t nil t)
110 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
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))
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))
134 ;; `char-after' and `char-before' must be well-behaved before lpath.el
135 ;; is loaded. Because it requires `poe' via `path-util'.
136 (load (expand-file-name "lpath.el" srcdir) nil t t)
138 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
139 ;; Bind defcustom'ed variables.
140 (put 'custom-declare-variable 'byte-hunk-handler
141 'byte-compile-file-form-custom-declare-variable)
142 (defun byte-compile-file-form-custom-declare-variable (form)
143 (if (memq 'free-vars byte-compile-warnings)
144 (setq byte-compile-bound-variables
145 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
148 ;; Bind functions defined by `defun-maybe'.
149 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
150 (defun byte-compile-file-form-defun-maybe (form)
151 (if (and (not (fboundp (nth 1 form)))
152 (memq 'unresolved byte-compile-warnings))
153 (setq byte-compile-function-environment
154 (cons (cons (nth 1 form)
155 (cons 'lambda (cdr (cdr form))))
156 byte-compile-function-environment)))
160 :symbol-for-testing-whether-colon-keyword-is-available-or-not
163 (mapcar (lambda (keyword) (set keyword keyword))
164 '(:button-keymap :data :file :mime-handle))))
166 ;; Unknown variables and functions.
167 (unless (boundp 'buffer-file-coding-system)
168 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
169 (unless (featurep 'xemacs)
170 (defalias 'Custom-make-dependencies 'ignore)
171 (defalias 'update-autoloads-from-directory 'ignore))
172 (autoload 'texinfo-parse-line-arg "texinfmt")
174 (unless (fboundp 'with-temp-buffer)
175 ;; Pickup some macros.
178 (defalias 'device-sound-enabled-p 'ignore)
179 (defalias 'play-sound-file 'ignore)
180 (defalias 'nndb-request-article 'ignore)
181 (defalias 'efs-re-read-dir 'ignore)
182 (defalias 'ange-ftp-re-read-dir 'ignore)
183 (defalias 'define-mail-user-agent 'ignore)
185 (defconst dgnushack-tool-files
186 '("dgnushack.el" "dgnuspath.el" "ptexinfmt.el"))
187 (defconst dgnushack-unexported-files
188 '("dgnuspath.el" "ptexinfmt.el"))
190 (defun dgnushack-compile (&optional warn)
191 ;;(setq byte-compile-dynamic t)
193 (setq byte-compile-warnings
194 '(free-vars unresolved callargs redefine)))
195 (unless (locate-library "cus-edit")
196 (error "You do not seem to have Custom installed.
197 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
198 You also then need to add the following to the lisp/dgnushack.el file:
200 (push \"~/lisp/custom\" load-path)
202 Modify to suit your needs."))
203 (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
204 ;;(byte-compile-generate-call-tree t)
207 (lambda (el) (setq files (delete el files)))
211 (progn (require 'w3-forms) nil)
212 (error '("nnweb.el" "nnlistserv.el" "nnultimate.el"
213 "nnslashdot.el" "nnwarchive.el" "webmail.el")))
215 (progn (require 'bbdb) nil)
216 (error '("gnus-bbdb.el")))
217 (unless (featurep 'xemacs)
218 '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
219 "nnheaderxm.el" "smiley.el"))
220 (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
222 (while (setq file (pop files))
223 (setq file (expand-file-name file srcdir))
224 (when (or (not (file-exists-p (setq elc (concat file "c"))))
225 (file-newer-than-file-p file elc))
227 (byte-compile-file file))))))
229 (defun dgnushack-recompile ()
231 (byte-recompile-directory "." 0))
234 ;; Avoid byte-compile warnings.
235 (defvar gnus-product-name)
236 (defvar early-package-load-path)
237 (defvar early-packages)
238 (defvar last-package-load-path)
239 (defvar last-packages)
240 (defvar late-package-load-path)
241 (defvar late-packages)
243 (defconst dgnushack-info-file-regexp
244 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
245 "\\.info\\(-[0-9]+\\)?$"))
247 (defconst dgnushack-texi-file-regexp
248 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
250 (defun dgnushack-make-package ()
252 (let* ((product-name (downcase gnus-product-name))
253 (lisp-dir (concat "lisp/" product-name "/"))
256 (message "Updating autoloads for directory %s..." default-directory)
257 (let ((generated-autoload-file "auto-autoloads.el")
259 (omsg (symbol-function 'message)))
260 (defun message (fmt &rest args)
261 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
262 (file-exists-p (file-name-nondirectory (car args))))
263 (funcall omsg fmt (file-name-nondirectory (car args))))
264 ((string-equal "No autoloads found in %s" fmt))
265 ((string-equal "Generating autoloads for %s...done" fmt))
266 (t (apply omsg fmt args))))
268 (update-autoloads-from-directory default-directory)
269 (fset 'message omsg)))
270 (byte-compile-file "auto-autoloads.el")
273 (let ((standard-output (current-buffer)))
274 (Custom-make-dependencies "."))
275 (message "%s" (buffer-string)))
277 (byte-compile-file "custom-load.el")
279 (message "Generating MANIFEST.%s for the package..." product-name)
281 (insert "pkginfo/MANIFEST." product-name "\n")
284 (unless (member file dgnushack-unexported-files)
285 (insert lisp-dir file "\n")))
286 (sort (directory-files "." nil "\\.elc?$") 'string-lessp))
288 (lambda (file) (insert "info/" file "\n"))
289 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
291 (write-file (concat "../MANIFEST." product-name)))))
293 (defun dgnushack-install-package ()
294 (let ((package-dir (car command-line-args-left))
295 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
297 (when (boundp 'early-packages)
298 (setq dirs (delq nil (append (when early-package-load-path
300 (when late-package-load-path
302 (when last-package-load-path
304 (while (and dirs (not package-dir))
305 (when (file-exists-p (car dirs))
306 (setq package-dir (car dirs)
310 You must specify the name of the package path as follows:
312 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
315 (setq info-dir (expand-file-name "info/" package-dir)
316 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
318 (setq product-name (downcase gnus-product-name)
319 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
321 manifest (concat "MANIFEST." product-name))
323 (unless (file-directory-p lisp-dir)
324 (make-directory lisp-dir t))
325 (unless (file-directory-p info-dir)
326 (make-directory info-dir))
327 (unless (file-directory-p pkginfo-dir)
328 (make-directory pkginfo-dir))
330 (setq files (sort (directory-files "." nil "\\.elc?$") 'string-lessp))
331 (mapcar (lambda (el) (setq files (delete el files)))
332 dgnushack-unexported-files)
335 (unless (or (member file files)
336 (not (string-match "\\.elc?$" file)))
337 (setq file (expand-file-name file lisp-dir))
338 (message "Removing %s..." file)
342 (directory-files lisp-dir nil nil nil t))
345 (message "Copying %s to %s..." file lisp-dir)
346 (copy-file file (expand-file-name file lisp-dir) t t))
351 (message "Copying ../texi/%s to %s..." file info-dir)
352 (copy-file (expand-file-name file "../texi/")
353 (expand-file-name file info-dir)
355 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
358 (message "Copying ../%s to %s..." manifest pkginfo-dir)
359 (copy-file (expand-file-name manifest "../")
360 (expand-file-name manifest pkginfo-dir) t t)
364 (defun dgnushack-texi-add-suffix-and-format ()
365 (dgnushack-texi-format t))
367 (defun dgnushack-texi-format (&optional addsuffix)
368 (if (not noninteractive)
369 (error "batch-texinfo-format may only be used -batch."))
371 (let ((auto-save-default nil)
372 (find-file-run-dired nil)
373 coding-system-for-write
374 output-coding-system)
378 (while command-line-args-left
379 (setq file (expand-file-name (car command-line-args-left)))
380 (cond ((not (file-exists-p file))
381 (message ">> %s does not exist!" file)
383 command-line-args-left (cdr command-line-args-left)))
384 ((file-directory-p file)
385 (setq command-line-args-left
386 (nconc (directory-files file)
387 (cdr command-line-args-left))))
389 (setq files (cons file files)
390 command-line-args-left (cdr command-line-args-left)))))
392 (setq file (car files)
396 (if buffer-file-name (kill-buffer (current-buffer)))
399 (setq output-coding-system (symbol-value
400 'file-coding-system))
401 (setq coding-system-for-write buffer-file-coding-system))
404 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
405 (not (string-match "\\.info$" (match-string 1))))
407 (buffer-disable-undo (current-buffer))
408 ;; process @include before updating node
409 ;; This might produce some problem if we use @lowersection or
411 (let ((input-directory default-directory)
412 (texinfo-command-end))
413 (while (re-search-forward "^@include" nil t)
414 (setq texinfo-command-end (point))
415 (let ((filename (concat input-directory
416 (texinfo-parse-line-arg))))
417 (re-search-backward "^@include")
418 (delete-region (point) (save-excursion
421 (message "Reading included file: %s" filename)
427 (car (cdr (insert-file-contents filename)))))
428 (goto-char (point-min))
429 ;; Remove `@setfilename' line from included file,
430 ;; if any, so @setfilename command not duplicated.
431 (if (re-search-forward "^@setfilename"
438 (delete-region (point) (save-excursion
442 (texinfo-every-node-update)
443 (set-buffer-modified-p nil)
444 (message "texinfo formatting %s..." file)
445 (texinfo-format-buffer nil)
446 (if (buffer-modified-p)
447 (progn (message "Saving modified %s" (buffer-file-name))
450 (message ">> Error: %s" (prin1-to-string err))
451 (message ">> point at")
452 (let ((s (buffer-substring (point)
456 (while (setq tem (string-match "\n+" s tem))
457 (setq s (concat (substring s 0 (match-beginning 0))
459 (substring s (match-end 0)))
463 (kill-emacs error))))
465 ;;; dgnushack.el ends here