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))))))
54 (define-compiler-macro mapc (&whole form fn seq &rest rest)
55 (if (and (fboundp 'mapc)
56 (subrp (symbol-function 'mapc)))
61 (args (cons seq ,rest))
62 (m (apply (function min) (mapcar (function length) args)))
65 (apply fn (mapcar (function (lambda (arg) (nth n arg))) args))
72 (define-compiler-macro last (&whole form x &optional n)
73 (if (and (fboundp 'last)
74 (subrp (symbol-function 'last)))
90 (while (consp (cdr x))
94 ;; If we are building w3 in a different directory than the source
95 ;; directory, we must read *.el from source directory and write *.elc
96 ;; into the building directory. For that, we define this function
97 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
98 (defun byte-compile-dest-file (filename)
99 "Convert an Emacs Lisp source file name to a compiled file name.
100 In addition, remove directory name part from FILENAME."
101 (setq filename (byte-compiler-base-file-name filename))
102 (setq filename (file-name-sans-versions filename))
103 (setq filename (file-name-nondirectory filename))
104 (if (memq system-type '(win32 w32 mswindows windows-nt))
105 (setq filename (downcase filename)))
106 (cond ((eq system-type 'vax-vms)
107 (concat (substring filename 0 (string-match ";" filename)) "c"))
108 ((string-match emacs-lisp-file-regexp filename)
109 (concat (substring filename 0 (match-beginning 0)) ".elc"))
110 (t (concat filename ".elc"))))
114 ;; Load `byte-opt' or `byte-optimize'.
115 (byte-optimize-form nil)
117 (setq max-specpdl-size 3000)
119 (defadvice byte-optimize-form-code-walker (around fix-bug-in-and/or-forms
121 "Fix bug in and/or forms."
122 (if (and (ad-get-arg 1)
123 (memq (car-safe (ad-get-arg 0)) '(and or)))
124 (let* ((form (ad-get-arg 0))
126 (let ((backwards (reverse (cdr form))))
127 (while (and backwards
128 (null (setcar backwards
129 (byte-optimize-form (car backwards) t))))
130 (setq backwards (cdr backwards)))
131 (if (and (cdr form) (null backwards))
133 " all subforms of %s called for effect; deleted" form))
134 (setq ad-return-value
136 (let ((head backwards))
137 (while (setq backwards (cdr backwards))
138 (setcar backwards (byte-optimize-form (car backwards)
140 (cons fn (nreverse head)))))))
143 (defvar srcdir (or (getenv "srcdir") "."))
145 ;(push "/usr/share/emacs/site-lisp" load-path)
147 ;; Attempt to pickup the additional load-path(s).
148 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
150 (load "~/.lpath.el" t nil t)
151 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
155 (wrong-number-of-arguments
156 ;; Optimize byte code for `char-after'.
157 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
158 (defun byte-optimize-char-after (form)
159 (if (null (cdr form))
160 '(char-after (point))
166 (wrong-number-of-arguments
167 (define-compiler-macro char-before (&whole form &optional pos)
169 '(char-before (point))
172 ;; `char-after' and `char-before' must be well-behaved before lpath.el
173 ;; is loaded. Because it requires `poe' via `path-util'.
174 (load (expand-file-name "lpath.el" srcdir) nil t t)
176 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
177 ;; Bind defcustom'ed variables.
178 (put 'custom-declare-variable 'byte-hunk-handler
179 'byte-compile-file-form-custom-declare-variable)
180 (defun byte-compile-file-form-custom-declare-variable (form)
181 (if (memq 'free-vars byte-compile-warnings)
182 (setq byte-compile-bound-variables
183 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
186 ;; Bind functions defined by `defun-maybe'.
187 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
188 (defun byte-compile-file-form-defun-maybe (form)
189 (if (and (not (fboundp (nth 1 form)))
190 (memq 'unresolved byte-compile-warnings))
191 (setq byte-compile-function-environment
192 (cons (cons (nth 1 form)
193 (cons 'lambda (cdr (cdr form))))
194 byte-compile-function-environment)))
198 :symbol-for-testing-whether-colon-keyword-is-available-or-not
201 (mapcar (lambda (keyword) (set keyword keyword))
202 '(:button-keymap :data :file :mime-handle))))
204 ;; Unknown variables and functions.
205 (unless (boundp 'buffer-file-coding-system)
206 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
207 (autoload 'font-lock-set-defaults "font-lock")
208 (unless (fboundp 'coding-system-get)
209 (defalias 'coding-system-get 'ignore))
211 (defalias 'find-coding-system 'ignore))
212 (unless (fboundp 'get-charset-property)
213 (defalias 'get-charset-property 'ignore))
214 (unless (featurep 'xemacs)
215 (defalias 'Custom-make-dependencies 'ignore)
216 (defalias 'toolbar-gnus 'ignore)
217 (defalias 'update-autoloads-from-directory 'ignore))
218 (autoload 'texinfo-parse-line-arg "texinfmt")
220 (unless (fboundp 'with-temp-buffer)
221 ;; Pickup some macros.
224 (defalias 'device-sound-enabled-p 'ignore)
225 (defalias 'play-sound-file 'ignore)
226 (defalias 'nndb-request-article 'ignore)
227 (defalias 'efs-re-read-dir 'ignore)
228 (defalias 'ange-ftp-re-read-dir 'ignore)
229 (defalias 'define-mail-user-agent 'ignore)
232 (unless (string-match "XEmacs" emacs-version)
233 (fset 'get-popup-menu-response 'ignore)
234 (fset 'event-object 'ignore)
235 (fset 'x-defined-colors 'ignore)
236 (fset 'read-color 'ignore)))
238 (defun dgnushack-compile (&optional warn)
239 ;;(setq byte-compile-dynamic t)
241 (setq byte-compile-warnings
242 '(free-vars unresolved callargs redefine)))
243 (unless (locate-library "cus-edit")
244 (error "You do not seem to have Custom installed.
245 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
246 You also then need to add the following to the lisp/dgnushack.el file:
248 (push \"~/lisp/custom\" load-path)
250 Modify to suit your needs."))
251 (let ((files (delete "dgnuspath.el"
252 (directory-files srcdir nil "^[^=].*\\.el$")))
253 (xemacs (string-match "XEmacs" emacs-version))
254 ;;(byte-compile-generate-call-tree t)
259 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
260 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
261 (setq files (delete file files)))))
264 (error (setq files (delete "gnus-bbdb.el" files))))
265 (while (setq file (pop files))
266 (unless (or (and (not xemacs)
268 '("gnus-xmas.el" "gnus-picon.el"
269 "messagexmas.el" "nnheaderxm.el"
270 "smiley.el" "x-overlay.el")))
271 (and (string-equal file "md5.el")
272 (not (and (fboundp 'md5)
273 (subrp (symbol-function 'md5))))))
274 (setq file (expand-file-name file srcdir))
275 (when (or (not (file-exists-p (setq elc (concat file "c"))))
276 (file-newer-than-file-p file elc))
278 (byte-compile-file file)))))))
280 (defun dgnushack-recompile ()
282 (byte-recompile-directory "." 0))
285 ;; Avoid byte-compile warnings.
286 (defvar gnus-product-name)
287 (defvar early-package-load-path)
288 (defvar early-packages)
289 (defvar last-package-load-path)
290 (defvar last-packages)
291 (defvar late-package-load-path)
292 (defvar late-packages)
294 (defconst dgnushack-info-file-regexp
295 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
296 "\\.info\\(-[0-9]+\\)?$"))
298 (defconst dgnushack-texi-file-regexp
299 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
301 (defun dgnushack-make-package ()
303 (let* ((product-name (downcase gnus-product-name))
304 (lisp-dir (concat "lisp/" product-name "/"))
307 (message "Updating autoloads for directory %s..." default-directory)
308 (let ((generated-autoload-file "auto-autoloads.el")
310 (omsg (symbol-function 'message)))
311 (defun message (fmt &rest args)
312 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
313 (file-exists-p (file-name-nondirectory (car args))))
314 (funcall omsg fmt (file-name-nondirectory (car args))))
315 ((string-equal "No autoloads found in %s" fmt))
316 ((string-equal "Generating autoloads for %s...done" fmt))
317 (t (apply omsg fmt args))))
319 (update-autoloads-from-directory default-directory)
320 (fset 'message omsg)))
321 (byte-compile-file "auto-autoloads.el")
324 (let ((standard-output (current-buffer)))
325 (Custom-make-dependencies "."))
326 (message (buffer-string)))
328 (byte-compile-file "custom-load.el")
330 (message "Generating MANIFEST.%s for the package..." product-name)
332 (insert "pkginfo/MANIFEST." product-name "\n"
336 (sort (delete "dgnuspath.el"
338 (directory-files "." nil "\\.elc?$")))
340 (concat "\n" lisp-dir))
344 (sort (directory-files "../texi/"
345 nil dgnushack-info-file-regexp)
349 (write-file (concat "../MANIFEST." product-name)))))
351 (defun dgnushack-install-package ()
352 (let ((package-dir (car command-line-args-left))
353 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
355 (when (boundp 'early-packages)
356 (setq dirs (delq nil (append (when early-package-load-path
358 (when late-package-load-path
360 (when last-package-load-path
362 (while (and dirs (not package-dir))
363 (when (file-exists-p (car dirs))
364 (setq package-dir (car dirs)
368 You must specify the name of the package path as follows:
370 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
373 (setq info-dir (expand-file-name "info/" package-dir)
374 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
376 (setq product-name (downcase gnus-product-name)
377 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
379 manifest (concat "MANIFEST." product-name))
381 (unless (file-directory-p lisp-dir)
382 (make-directory lisp-dir t))
383 (unless (file-directory-p info-dir)
384 (make-directory info-dir))
385 (unless (file-directory-p pkginfo-dir)
386 (make-directory pkginfo-dir))
389 (sort (delete "dgnuspath.el"
390 (delete "dgnuspath.elc"
391 (directory-files "." nil "\\.elc?$")))
395 (unless (member file files)
396 (setq file (expand-file-name file lisp-dir))
397 (message "Removing %s..." file)
401 (directory-files lisp-dir nil nil nil t))
404 (message "Copying %s to %s..." file lisp-dir)
405 (copy-file file (expand-file-name file lisp-dir) t t))
410 (message "Copying ../texi/%s to %s..." file info-dir)
411 (copy-file (expand-file-name file "../texi/")
412 (expand-file-name file info-dir)
414 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
417 (message "Copying ../%s to %s..." manifest pkginfo-dir)
418 (copy-file (expand-file-name manifest "../")
419 (expand-file-name manifest pkginfo-dir) t t)
423 (defun dgnushack-texi-add-suffix-and-format ()
424 (dgnushack-texi-format t))
426 (defun dgnushack-texi-format (&optional addsuffix)
427 (if (not noninteractive)
428 (error "batch-texinfo-format may only be used -batch."))
430 (let ((auto-save-default nil)
431 (find-file-run-dired nil)
432 coding-system-for-write)
436 (while command-line-args-left
437 (setq file (expand-file-name (car command-line-args-left)))
438 (cond ((not (file-exists-p file))
439 (message ">> %s does not exist!" file)
441 command-line-args-left (cdr command-line-args-left)))
442 ((file-directory-p file)
443 (setq command-line-args-left
444 (nconc (directory-files file)
445 (cdr command-line-args-left))))
447 (setq files (cons file files)
448 command-line-args-left (cdr command-line-args-left)))))
450 (setq file (car files)
454 (if buffer-file-name (kill-buffer (current-buffer)))
456 (setq coding-system-for-write buffer-file-coding-system)
459 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
460 (not (string-match "\\.info$" (match-string 1))))
462 (buffer-disable-undo (current-buffer))
463 ;; process @include before updating node
464 ;; This might produce some problem if we use @lowersection or
466 (let ((input-directory default-directory)
467 (texinfo-command-end))
468 (while (re-search-forward "^@include" nil t)
469 (setq texinfo-command-end (point))
470 (let ((filename (concat input-directory
471 (texinfo-parse-line-arg))))
472 (re-search-backward "^@include")
473 (delete-region (point) (save-excursion
476 (message "Reading included file: %s" filename)
482 (car (cdr (insert-file-contents filename)))))
483 (goto-char (point-min))
484 ;; Remove `@setfilename' line from included file,
485 ;; if any, so @setfilename command not duplicated.
486 (if (re-search-forward "^@setfilename"
493 (delete-region (point) (save-excursion
497 (texinfo-every-node-update)
498 (set-buffer-modified-p nil)
499 (message "texinfo formatting %s..." file)
500 (texinfo-format-buffer nil)
501 (if (buffer-modified-p)
502 (progn (message "Saving modified %s" (buffer-file-name))
505 (message ">> Error: %s" (prin1-to-string err))
506 (message ">> point at")
507 (let ((s (buffer-substring (point)
511 (while (setq tem (string-match "\n+" s tem))
512 (setq s (concat (substring s 0 (match-beginning 0))
514 (substring s (match-end 0)))
518 (kill-emacs error))))
520 ;;; dgnushack.el ends here