1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994,95,96,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: news, path
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 ;; Set coding priority of Shift-JIS to the bottom.
31 (defvar *predefined-category*)
32 (defvar coding-category-list)
33 (if (featurep 'xemacs)
34 (fset 'set-coding-priority 'ignore)
35 (fset 'coding-priority-list 'ignore)
36 (fset 'set-coding-priority-list 'ignore))
37 (cond ((and (featurep 'xemacs) (featurep 'mule))
38 (if (memq 'shift-jis (coding-priority-list))
39 (set-coding-priority-list
40 (nconc (delq 'shift-jis (coding-priority-list)) '(shift-jis)))))
42 (put '*coding-category-sjis* 'priority (length *predefined-category*)))
44 (if (memq 'coding-category-sjis coding-category-list)
46 (nconc (delq 'coding-category-sjis coding-category-list)
47 '(coding-category-sjis))))))
53 ;; If we are building w3 in a different directory than the source
54 ;; directory, we must read *.el from source directory and write *.elc
55 ;; into the building directory. For that, we define this function
56 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
57 (defun byte-compile-dest-file (filename)
58 "Convert an Emacs Lisp source file name to a compiled file name.
59 In addition, remove directory name part from FILENAME."
60 (setq filename (byte-compiler-base-file-name filename))
61 (setq filename (file-name-sans-versions filename))
62 (setq filename (file-name-nondirectory filename))
63 (if (memq system-type '(win32 w32 mswindows windows-nt))
64 (setq filename (downcase filename)))
65 (cond ((eq system-type 'vax-vms)
66 (concat (substring filename 0 (string-match ";" filename)) "c"))
67 ((string-match emacs-lisp-file-regexp filename)
68 (concat (substring filename 0 (match-beginning 0)) ".elc"))
69 (t (concat filename ".elc"))))
73 (unless (fboundp 'si:byte-optimize-form-code-walker)
74 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
75 (setq max-specpdl-size 3000)
76 (fset 'si:byte-optimize-form-code-walker
77 (symbol-function 'byte-optimize-form-code-walker))
78 (defun byte-optimize-form-code-walker (form for-effect)
79 (if (and for-effect (memq (car-safe form) '(and or)))
80 ;; Fix bug in and/or forms.
82 (backwards (reverse (cdr form))))
84 (null (setcar backwards
85 (byte-optimize-form (car backwards) t))))
86 (setq backwards (cdr backwards)))
87 (if (and (cdr form) (null backwards))
89 " all subforms of %s called for effect; deleted" form))
91 (let ((head backwards))
92 (while (setq backwards (cdr backwards))
93 (setcar backwards (byte-optimize-form (car backwards)
95 (cons fn (nreverse head)))))
96 (si:byte-optimize-form-code-walker form for-effect)))
97 (byte-compile 'byte-optimize-form-code-walker))
99 (defvar srcdir (or (getenv "srcdir") "."))
101 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
103 ;(push "/usr/share/emacs/site-lisp" load-path)
105 ;; Attempt to pickup the additional load-path(s).
106 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
108 (load "~/.lpath.el" t nil t)
109 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
113 (wrong-number-of-arguments
114 ;; Optimize byte code for `char-after'.
115 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
116 (defun byte-optimize-char-after (form)
117 (if (null (cdr form))
118 '(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))
133 ;; `char-after' and `char-before' must be well-behaved before lpath.el
134 ;; is loaded. Because it requires `poe' via `path-util'.
135 (load (expand-file-name "lpath.el" srcdir) nil t t)
137 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
138 ;; Bind defcustom'ed variables.
139 (put 'custom-declare-variable 'byte-hunk-handler
140 'byte-compile-file-form-custom-declare-variable)
141 (defun byte-compile-file-form-custom-declare-variable (form)
142 (if (memq 'free-vars byte-compile-warnings)
143 (setq byte-compile-bound-variables
144 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
147 ;; Bind functions defined by `defun-maybe'.
148 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
149 (defun byte-compile-file-form-defun-maybe (form)
150 (if (and (not (fboundp (nth 1 form)))
151 (memq 'unresolved byte-compile-warnings))
152 (setq byte-compile-function-environment
153 (cons (cons (nth 1 form)
154 (cons 'lambda (cdr (cdr form))))
155 byte-compile-function-environment)))
159 :symbol-for-testing-whether-colon-keyword-is-available-or-not
162 (mapcar (lambda (keyword) (set keyword keyword))
163 '(:button-keymap :data :file :mime-handle))))
165 ;; Unknown variables and functions.
166 (unless (boundp 'buffer-file-coding-system)
167 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
168 (unless (featurep 'xemacs)
169 (defalias 'Custom-make-dependencies 'ignore)
170 (defalias 'update-autoloads-from-directory 'ignore))
171 (autoload 'texinfo-parse-line-arg "texinfmt")
173 (unless (fboundp 'with-temp-buffer)
174 ;; Pickup some macros.
177 (defalias 'device-sound-enabled-p 'ignore)
178 (defalias 'play-sound-file 'ignore)
179 (defalias 'nndb-request-article 'ignore)
180 (defalias 'efs-re-read-dir 'ignore)
181 (defalias 'ange-ftp-re-read-dir 'ignore)
182 (defalias 'define-mail-user-agent 'ignore)
184 (defun dgnushack-compile (&optional warn)
185 ;;(setq byte-compile-dynamic t)
187 (setq byte-compile-warnings
188 '(free-vars unresolved callargs redefine)))
189 (unless (locate-library "cus-edit")
190 (error "You do not seem to have Custom installed.
191 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
192 You also then need to add the following to the lisp/dgnushack.el file:
194 (push \"~/lisp/custom\" load-path)
196 Modify to suit your needs."))
197 (let ((files (delete "dgnuspath.el"
198 (directory-files srcdir nil "^[^=].*\\.el$")))
199 (xemacs (string-match "XEmacs" emacs-version))
200 ;;(byte-compile-generate-call-tree t)
205 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
206 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
207 (setq files (delete file files)))))
210 (error (setq files (delete "gnus-bbdb.el" files))))
211 (while (setq file (pop files))
212 (unless (or (and (not xemacs)
214 '("gnus-xmas.el" "gnus-picon.el"
215 "messagexmas.el" "nnheaderxm.el"
216 "smiley.el" "x-overlay.el")))
217 (and (string-equal file "md5.el")
218 (not (and (fboundp 'md5)
219 (subrp (symbol-function 'md5))))))
220 (setq file (expand-file-name file srcdir))
221 (when (or (not (file-exists-p (setq elc (concat file "c"))))
222 (file-newer-than-file-p file elc))
224 (byte-compile-file file)))))))
226 (defun dgnushack-recompile ()
228 (byte-recompile-directory "." 0))
231 ;; Avoid byte-compile warnings.
232 (defvar gnus-product-name)
233 (defvar early-package-load-path)
234 (defvar early-packages)
235 (defvar last-package-load-path)
236 (defvar last-packages)
237 (defvar late-package-load-path)
238 (defvar late-packages)
240 (defconst dgnushack-info-file-regexp
241 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
242 "\\.info\\(-[0-9]+\\)?$"))
244 (defconst dgnushack-texi-file-regexp
245 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
247 (defun dgnushack-make-package ()
249 (let* ((product-name (downcase gnus-product-name))
250 (lisp-dir (concat "lisp/" product-name "/"))
253 (message "Updating autoloads for directory %s..." default-directory)
254 (let ((generated-autoload-file "auto-autoloads.el")
256 (omsg (symbol-function 'message)))
257 (defun message (fmt &rest args)
258 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
259 (file-exists-p (file-name-nondirectory (car args))))
260 (funcall omsg fmt (file-name-nondirectory (car args))))
261 ((string-equal "No autoloads found in %s" fmt))
262 ((string-equal "Generating autoloads for %s...done" fmt))
263 (t (apply omsg fmt args))))
265 (update-autoloads-from-directory default-directory)
266 (fset 'message omsg)))
267 (byte-compile-file "auto-autoloads.el")
270 (let ((standard-output (current-buffer)))
271 (Custom-make-dependencies "."))
272 (message (buffer-string)))
274 (byte-compile-file "custom-load.el")
276 (message "Generating MANIFEST.%s for the package..." product-name)
278 (insert "pkginfo/MANIFEST." product-name "\n"
282 (sort (delete "dgnuspath.el"
284 (directory-files "." nil "\\.elc?$")))
286 (concat "\n" lisp-dir))
290 (sort (directory-files "../texi/"
291 nil dgnushack-info-file-regexp)
295 (write-file (concat "../MANIFEST." product-name)))))
297 (defun dgnushack-install-package ()
298 (let ((package-dir (car command-line-args-left))
299 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
301 (when (boundp 'early-packages)
302 (setq dirs (delq nil (append (when early-package-load-path
304 (when late-package-load-path
306 (when last-package-load-path
308 (while (and dirs (not package-dir))
309 (when (file-exists-p (car dirs))
310 (setq package-dir (car dirs)
314 You must specify the name of the package path as follows:
316 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
319 (setq info-dir (expand-file-name "info/" package-dir)
320 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
322 (setq product-name (downcase gnus-product-name)
323 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
325 manifest (concat "MANIFEST." product-name))
327 (unless (file-directory-p lisp-dir)
328 (make-directory lisp-dir t))
329 (unless (file-directory-p info-dir)
330 (make-directory info-dir))
331 (unless (file-directory-p pkginfo-dir)
332 (make-directory pkginfo-dir))
335 (sort (delete "dgnuspath.el"
336 (delete "dgnuspath.elc"
337 (directory-files "." nil "\\.elc?$")))
341 (unless (or (member file files)
342 (not (string-match "\\.elc?$" file)))
343 (setq file (expand-file-name file lisp-dir))
344 (message "Removing %s..." file)
348 (directory-files lisp-dir nil nil nil t))
351 (message "Copying %s to %s..." file lisp-dir)
352 (copy-file file (expand-file-name file lisp-dir) t t))
357 (message "Copying ../texi/%s to %s..." file info-dir)
358 (copy-file (expand-file-name file "../texi/")
359 (expand-file-name file info-dir)
361 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
364 (message "Copying ../%s to %s..." manifest pkginfo-dir)
365 (copy-file (expand-file-name manifest "../")
366 (expand-file-name manifest pkginfo-dir) t t)
370 (defun dgnushack-texi-add-suffix-and-format ()
371 (dgnushack-texi-format t))
373 (defun dgnushack-texi-format (&optional addsuffix)
374 (if (not noninteractive)
375 (error "batch-texinfo-format may only be used -batch."))
377 (let ((auto-save-default nil)
378 (find-file-run-dired nil)
379 coding-system-for-write)
383 (while command-line-args-left
384 (setq file (expand-file-name (car command-line-args-left)))
385 (cond ((not (file-exists-p file))
386 (message ">> %s does not exist!" file)
388 command-line-args-left (cdr command-line-args-left)))
389 ((file-directory-p file)
390 (setq command-line-args-left
391 (nconc (directory-files file)
392 (cdr command-line-args-left))))
394 (setq files (cons file files)
395 command-line-args-left (cdr command-line-args-left)))))
397 (setq file (car files)
401 (if buffer-file-name (kill-buffer (current-buffer)))
403 (setq coding-system-for-write buffer-file-coding-system)
406 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
407 (not (string-match "\\.info$" (match-string 1))))
409 (buffer-disable-undo (current-buffer))
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))))
467 ;;; dgnushack.el ends here