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 (defvar srcdir (or (getenv "srcdir") "."))
116 (push srcdir load-path)
118 ;; Attempt to pickup the additional load-path(s).
119 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
121 (load "~/.lpath.el" t nil t)
122 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
126 (wrong-number-of-arguments
127 ;; Optimize byte code for `char-after'.
128 ;;; (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
129 ;;; (defun byte-optimize-char-after (form)
130 ;;; (if (null (cdr form))
131 ;;; '(char-after (point))
133 (byte-defop-compiler char-after 0-1)))
137 (wrong-number-of-arguments
138 (define-compiler-macro char-before (&whole form &optional pos)
140 '(char-before (point))
143 ;; `char-after' and `char-before' must be well-behaved before lpath.el
144 ;; is loaded. Because it requires `poe' via `path-util'.
145 (load (expand-file-name "lpath.el" srcdir) nil t t)
147 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
148 ;; Bind defcustom'ed variables.
149 (put 'custom-declare-variable 'byte-hunk-handler
150 'byte-compile-file-form-custom-declare-variable)
151 (defun byte-compile-file-form-custom-declare-variable (form)
152 (if (memq 'free-vars byte-compile-warnings)
153 (setq byte-compile-bound-variables
154 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
157 ;; Bind functions defined by `defun-maybe'.
158 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
159 (defun byte-compile-file-form-defun-maybe (form)
160 (if (and (not (fboundp (nth 1 form)))
161 (memq 'unresolved byte-compile-warnings))
162 (setq byte-compile-function-environment
163 (cons (cons (nth 1 form)
164 (cons 'lambda (cdr (cdr form))))
165 byte-compile-function-environment)))
169 :symbol-for-testing-whether-colon-keyword-is-available-or-not
172 (mapcar (lambda (keyword) (set keyword keyword))
173 '(:button-keymap :data :file :mime-handle))))
175 ;; Unknown variables and functions.
176 (unless (boundp 'buffer-file-coding-system)
177 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
178 (autoload 'font-lock-set-defaults "font-lock")
179 (unless (fboundp 'coding-system-get)
180 (defalias 'coding-system-get 'ignore))
182 (defalias 'find-coding-system 'ignore))
183 (unless (fboundp 'get-charset-property)
184 (defalias 'get-charset-property 'ignore))
185 (unless (featurep 'xemacs)
186 (defalias 'Custom-make-dependencies 'ignore)
187 (defalias 'toolbar-gnus 'ignore)
188 (defalias 'update-autoloads-from-directory 'ignore))
189 (autoload 'texinfo-parse-line-arg "texinfmt")
191 (unless (fboundp 'with-temp-buffer)
192 ;; Pickup some macros.
195 (defalias 'device-sound-enabled-p 'ignore)
196 (defalias 'play-sound-file 'ignore)
197 (defalias 'nndb-request-article 'ignore)
198 (defalias 'efs-re-read-dir 'ignore)
199 (defalias 'ange-ftp-re-read-dir 'ignore)
200 (defalias 'define-mail-user-agent 'ignore)
203 (unless (string-match "XEmacs" emacs-version)
204 (fset 'get-popup-menu-response 'ignore)
205 (fset 'event-object 'ignore)
206 (fset 'x-defined-colors 'ignore)
207 (fset 'read-color 'ignore)))
209 (defun dgnushack-compile (&optional warn)
210 ;;(setq byte-compile-dynamic t)
212 (setq byte-compile-warnings
213 '(free-vars unresolved callargs redefine)))
214 (unless (locate-library "cus-edit")
215 (error "You do not seem to have Custom installed.
216 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
217 You also then need to add the following to the lisp/dgnushack.el file:
219 (push \"~/lisp/custom\" load-path)
221 Modify to suit your needs."))
222 (let ((files (delete "dgnuspath.el"
223 (directory-files srcdir nil "^[^=].*\\.el$")))
224 (xemacs (string-match "XEmacs" emacs-version))
225 ;;(byte-compile-generate-call-tree t)
230 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
231 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
232 (setq files (delete file files)))))
235 (error (setq files (delete "gnus-bbdb.el" files))))
236 (while (setq file (pop files))
237 (unless (or (and (not xemacs)
239 '("gnus-xmas.el" "gnus-picon.el"
240 "messagexmas.el" "nnheaderxm.el"
241 "smiley.el" "x-overlay.el")))
242 (and (string-equal file "md5.el")
243 (not (and (fboundp 'md5)
244 (subrp (symbol-function 'md5))))))
245 (setq file (expand-file-name file srcdir))
246 (when (or (not (file-exists-p (setq elc (concat file "c"))))
247 (file-newer-than-file-p file elc))
249 (byte-compile-file file)))))))
251 (defun dgnushack-recompile ()
253 (byte-recompile-directory "." 0))
256 ;; Avoid byte-compile warnings.
257 (defvar gnus-product-name)
258 (defvar early-package-load-path)
259 (defvar early-packages)
260 (defvar last-package-load-path)
261 (defvar last-packages)
262 (defvar late-package-load-path)
263 (defvar late-packages)
265 (defconst dgnushack-info-file-regexp
266 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
267 "\\.info\\(-[0-9]+\\)?$"))
269 (defconst dgnushack-texi-file-regexp
270 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
272 (defun dgnushack-make-package ()
274 (let* ((product-name (downcase gnus-product-name))
275 (lisp-dir (concat "lisp/" product-name "/"))
278 (message "Updating autoloads for directory %s..." default-directory)
279 (let ((generated-autoload-file "auto-autoloads.el")
281 (omsg (symbol-function 'message)))
282 (defun message (fmt &rest args)
283 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
284 (file-exists-p (file-name-nondirectory (car args))))
285 (funcall omsg fmt (file-name-nondirectory (car args))))
286 ((string-equal "No autoloads found in %s" fmt))
287 ((string-equal "Generating autoloads for %s...done" fmt))
288 (t (apply omsg fmt args))))
290 (update-autoloads-from-directory default-directory)
291 (fset 'message omsg)))
292 (byte-compile-file "auto-autoloads.el")
295 (let ((standard-output (current-buffer)))
296 (Custom-make-dependencies "."))
297 (message (buffer-string)))
299 (byte-compile-file "custom-load.el")
301 (message "Generating MANIFEST.%s for the package..." product-name)
303 (insert "pkginfo/MANIFEST." product-name "\n"
307 (sort (delete "dgnuspath.el"
309 (directory-files "." nil "\\.elc?$")))
311 (concat "\n" lisp-dir))
315 (sort (directory-files "../texi/"
316 nil dgnushack-info-file-regexp)
320 (write-file (concat "../MANIFEST." product-name)))))
322 (defun dgnushack-install-package ()
323 (let ((package-dir (car command-line-args-left))
324 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
326 (when (boundp 'early-packages)
327 (setq dirs (delq nil (append (when early-package-load-path
329 (when late-package-load-path
331 (when last-package-load-path
333 (while (and dirs (not package-dir))
334 (when (file-exists-p (car dirs))
335 (setq package-dir (car dirs)
339 You must specify the name of the package path as follows:
341 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
344 (setq info-dir (expand-file-name "info/" package-dir)
345 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
347 (setq product-name (downcase gnus-product-name)
348 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
350 manifest (concat "MANIFEST." product-name))
352 (unless (file-directory-p lisp-dir)
353 (make-directory lisp-dir t))
354 (unless (file-directory-p info-dir)
355 (make-directory info-dir))
356 (unless (file-directory-p pkginfo-dir)
357 (make-directory pkginfo-dir))
360 (sort (delete "dgnuspath.el"
361 (delete "dgnuspath.elc"
362 (directory-files "." nil "\\.elc?$")))
366 (unless (member file files)
367 (setq file (expand-file-name file lisp-dir))
368 (message "Removing %s..." file)
372 (directory-files lisp-dir nil nil nil t))
375 (message "Copying %s to %s..." file lisp-dir)
376 (copy-file file (expand-file-name file lisp-dir) t t))
381 (message "Copying ../texi/%s to %s..." file info-dir)
382 (copy-file (expand-file-name file "../texi/")
383 (expand-file-name file info-dir)
385 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
388 (message "Copying ../%s to %s..." manifest pkginfo-dir)
389 (copy-file (expand-file-name manifest "../")
390 (expand-file-name manifest pkginfo-dir) t t)
394 (defun dgnushack-texi-add-suffix-and-format ()
395 (dgnushack-texi-format t))
397 (defun dgnushack-texi-format (&optional addsuffix)
398 (if (not noninteractive)
399 (error "batch-texinfo-format may only be used -batch."))
401 (let ((auto-save-default nil)
402 (find-file-run-dired nil)
403 coding-system-for-write)
407 (while command-line-args-left
408 (setq file (expand-file-name (car command-line-args-left)))
409 (cond ((not (file-exists-p file))
410 (message ">> %s does not exist!" file)
412 command-line-args-left (cdr command-line-args-left)))
413 ((file-directory-p file)
414 (setq command-line-args-left
415 (nconc (directory-files file)
416 (cdr command-line-args-left))))
418 (setq files (cons file files)
419 command-line-args-left (cdr command-line-args-left)))))
421 (setq file (car files)
425 (if buffer-file-name (kill-buffer (current-buffer)))
427 (setq coding-system-for-write buffer-file-coding-system)
430 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
431 (not (string-match "\\.info$" (match-string 1))))
433 (buffer-disable-undo (current-buffer))
434 ;; process @include before updating node
435 ;; This might produce some problem if we use @lowersection or
437 (let ((input-directory default-directory)
438 (texinfo-command-end))
439 (while (re-search-forward "^@include" nil t)
440 (setq texinfo-command-end (point))
441 (let ((filename (concat input-directory
442 (texinfo-parse-line-arg))))
443 (re-search-backward "^@include")
444 (delete-region (point) (save-excursion
447 (message "Reading included file: %s" filename)
453 (car (cdr (insert-file-contents filename)))))
454 (goto-char (point-min))
455 ;; Remove `@setfilename' line from included file,
456 ;; if any, so @setfilename command not duplicated.
457 (if (re-search-forward "^@setfilename"
464 (delete-region (point) (save-excursion
468 (texinfo-every-node-update)
469 (set-buffer-modified-p nil)
470 (message "texinfo formatting %s..." file)
471 (texinfo-format-buffer nil)
472 (if (buffer-modified-p)
473 (progn (message "Saving modified %s" (buffer-file-name))
476 (message ">> Error: %s" (prin1-to-string err))
477 (message ">> point at")
478 (let ((s (buffer-substring (point)
482 (while (setq tem (string-match "\n+" s tem))
483 (setq s (concat (substring s 0 (match-beginning 0))
485 (substring s (match-end 0)))
489 (kill-emacs error))))
491 ;;; dgnushack.el ends here