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 ;; Attempt to pickup the additional load-path(s).
55 (load (expand-file-name "./dgnuspath.el") nil nil t)
57 (load "~/.lpath.el" t nil t)
58 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
64 (wrong-number-of-arguments
65 ;; Optimize byte code for `char-after',
66 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
67 (defun byte-optimize-char-after (form)
74 (wrong-number-of-arguments
75 ;; Optimize byte code for `char-before',
76 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
77 (defun byte-optimize-char-before (form)
79 '(char-before (point))
82 ;; `char-after' and `char-before' must be well-behaved before lpath.el
83 ;; is loaded. Because it requires `poe' via `path-util'.
84 (load "./lpath.el" nil t)
86 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
87 ;; Bind defcustom'ed variables.
88 (put 'custom-declare-variable 'byte-hunk-handler
89 'byte-compile-file-form-custom-declare-variable)
90 (defun byte-compile-file-form-custom-declare-variable (form)
91 (if (memq 'free-vars byte-compile-warnings)
92 (setq byte-compile-bound-variables
93 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
96 ;; Bind functions defined by `defun-maybe'.
97 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
98 (defun byte-compile-file-form-defun-maybe (form)
99 (if (and (not (fboundp (nth 1 form)))
100 (memq 'unresolved byte-compile-warnings))
101 (setq byte-compile-function-environment
102 (cons (cons (nth 1 form)
103 (cons 'lambda (cdr (cdr form))))
104 byte-compile-function-environment)))
108 :symbol-for-testing-whether-colon-keyword-is-available-or-not
111 (mapcar (lambda (keyword) (set keyword keyword))
112 '(:button-keymap :data :file :mime-handle))))
114 ;; Unknown variables and functions.
115 (unless (boundp 'buffer-file-coding-system)
116 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
117 (autoload 'font-lock-set-defaults "font-lock")
118 (unless (fboundp 'coding-system-get)
119 (defalias 'coding-system-get 'ignore))
121 (defalias 'find-coding-system 'ignore))
122 (unless (fboundp 'get-charset-property)
123 (defalias 'get-charset-property 'ignore))
124 (unless (featurep 'xemacs)
125 (defalias 'Custom-make-dependencies 'ignore)
126 (defalias 'toolbar-gnus 'ignore)
127 (defalias 'update-autoloads-from-directory 'ignore))
128 (autoload 'texinfo-parse-line-arg "texinfmt")
130 (unless (fboundp 'with-temp-buffer)
131 ;; Pickup some macros.
134 (defalias 'device-sound-enabled-p 'ignore)
135 (defalias 'play-sound-file 'ignore)
136 (defalias 'nndb-request-article 'ignore)
137 (defalias 'efs-re-read-dir 'ignore)
138 (defalias 'ange-ftp-re-read-dir 'ignore)
139 (defalias 'define-mail-user-agent 'ignore)
142 (unless (string-match "XEmacs" emacs-version)
143 (fset 'get-popup-menu-response 'ignore)
144 (fset 'event-object 'ignore)
145 (fset 'x-defined-colors 'ignore)
146 (fset 'read-color 'ignore)))
148 (defun dgnushack-compile (&optional warn)
149 ;;(setq byte-compile-dynamic t)
151 (setq byte-compile-warnings
152 '(free-vars unresolved callargs redefine)))
153 (unless (locate-library "cus-edit")
154 (error "You do not seem to have Custom installed.
155 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
156 You also then need to add the following to the lisp/dgnushack.el file:
158 (push \"~/lisp/custom\" load-path)
160 Modify to suit your needs."))
161 (let ((files (delete "dgnuspath.el"
162 (directory-files "." nil "^[^=].*\\.el$")))
163 (xemacs (string-match "XEmacs" emacs-version))
164 ;;(byte-compile-generate-call-tree t)
168 (error (setq files (delete "nnweb.el" (delete "nnlistserv.el" files)))))
171 (error (setq files (delete "gnus-bbdb.el" files))))
172 (while (setq file (pop files))
173 (when (or (and (not xemacs)
174 (not (member file '("gnus-xmas.el" "gnus-picon.el"
175 "messagexmas.el" "nnheaderxm.el"
176 "smiley.el" "x-overlay.el"))))
178 (not (member file '("md5.el")))))
179 (when (or (not (file-exists-p (setq elc (concat file "c"))))
180 (file-newer-than-file-p file elc))
182 (byte-compile-file file)))))))
184 (defun dgnushack-recompile ()
186 (byte-recompile-directory "." 0))
189 ;; Avoid byte-compile warnings.
190 (defvar gnus-product-name)
191 (defvar early-package-load-path)
192 (defvar early-packages)
193 (defvar last-package-load-path)
194 (defvar last-packages)
195 (defvar late-package-load-path)
196 (defvar late-packages)
198 (defconst dgnushack-info-file-regexp
199 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
200 "\\.info\\(-[0-9]+\\)?$"))
202 (defconst dgnushack-texi-file-regexp
203 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
205 (defun dgnushack-make-package ()
207 (let* ((product-name (downcase gnus-product-name))
208 (lisp-dir (concat "lisp/" product-name "/"))
211 (message "Updating autoloads for directory %s..." default-directory)
212 (let ((generated-autoload-file "auto-autoloads.el")
214 (omsg (symbol-function 'message)))
215 (defun message (fmt &rest args)
216 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
217 (file-exists-p (file-name-nondirectory (car args))))
218 (funcall omsg fmt (file-name-nondirectory (car args))))
219 ((string-equal "No autoloads found in %s" fmt))
220 ((string-equal "Generating autoloads for %s...done" fmt))
221 (t (apply omsg fmt args))))
223 (update-autoloads-from-directory default-directory)
224 (fset 'message omsg)))
225 (byte-compile-file "auto-autoloads.el")
228 (let ((standard-output (current-buffer)))
229 (Custom-make-dependencies "."))
230 (message (buffer-string)))
232 (byte-compile-file "custom-load.el")
234 (message "Generating MANIFEST.%s for the package..." product-name)
236 (insert "pkginfo/MANIFEST." product-name "\n"
240 (sort (delete "dgnuspath.el"
242 (directory-files "." nil "\\.elc?$")))
244 (concat "\n" lisp-dir))
248 (sort (directory-files "../texi/"
249 nil dgnushack-info-file-regexp)
253 (write-file (concat "../MANIFEST." product-name)))))
255 (defun dgnushack-install-package ()
256 (let ((package-dir (car command-line-args-left))
257 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
259 (when (boundp 'early-packages)
260 (setq dirs (delq nil (append (when early-package-load-path
262 (when late-package-load-path
264 (when last-package-load-path
266 (while (and dirs (not package-dir))
267 (when (file-exists-p (car dirs))
268 (setq package-dir (car dirs)
272 You must specify the name of the package path as follows:
274 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
277 (setq info-dir (expand-file-name "info/" package-dir)
278 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
280 (setq product-name (downcase gnus-product-name)
281 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
283 manifest (concat "MANIFEST." product-name))
285 (unless (file-directory-p lisp-dir)
286 (make-directory lisp-dir t))
287 (unless (file-directory-p info-dir)
288 (make-directory info-dir))
289 (unless (file-directory-p pkginfo-dir)
290 (make-directory pkginfo-dir))
293 (sort (delete "dgnuspath.el"
294 (delete "dgnuspath.elc"
295 (directory-files "." nil "\\.elc?$")))
299 (unless (member file files)
300 (setq file (expand-file-name file lisp-dir))
301 (message "Removing %s..." file)
305 (directory-files lisp-dir nil nil nil t))
308 (message "Copying %s to %s..." file lisp-dir)
309 (copy-file file (expand-file-name file lisp-dir) t t))
314 (message "Copying ../texi/%s to %s..." file info-dir)
315 (copy-file (expand-file-name file "../texi/")
316 (expand-file-name file info-dir)
318 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
321 (message "Copying ../%s to %s..." manifest pkginfo-dir)
322 (copy-file (expand-file-name manifest "../")
323 (expand-file-name manifest pkginfo-dir) t t)
327 (defun dgnushack-texi-add-suffix-and-format ()
328 (dgnushack-texi-format t))
330 (defun dgnushack-texi-format (&optional addsuffix)
331 (if (not noninteractive)
332 (error "batch-texinfo-format may only be used -batch."))
334 (let ((auto-save-default nil)
335 (find-file-run-dired nil)
336 coding-system-for-write)
340 (while command-line-args-left
341 (setq file (expand-file-name (car command-line-args-left)))
342 (cond ((not (file-exists-p file))
343 (message ">> %s does not exist!" file)
345 command-line-args-left (cdr command-line-args-left)))
346 ((file-directory-p file)
347 (setq command-line-args-left
348 (nconc (directory-files file)
349 (cdr command-line-args-left))))
351 (setq files (cons file files)
352 command-line-args-left (cdr command-line-args-left)))))
354 (setq file (car files)
358 (if buffer-file-name (kill-buffer (current-buffer)))
360 (setq coding-system-for-write buffer-file-coding-system)
363 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
364 (not (string-match "\\.info$" (match-string 1))))
366 (buffer-disable-undo (current-buffer))
367 ;; process @include before updating node
368 ;; This might produce some problem if we use @lowersection or
370 (let ((input-directory default-directory)
371 (texinfo-command-end))
372 (while (re-search-forward "^@include" nil t)
373 (setq texinfo-command-end (point))
374 (let ((filename (concat input-directory
375 (texinfo-parse-line-arg))))
376 (re-search-backward "^@include")
377 (delete-region (point) (save-excursion
380 (message "Reading included file: %s" filename)
386 (car (cdr (insert-file-contents filename)))))
387 (goto-char (point-min))
388 ;; Remove `@setfilename' line from included file,
389 ;; if any, so @setfilename command not duplicated.
390 (if (re-search-forward "^@setfilename"
397 (delete-region (point) (save-excursion
401 (texinfo-every-node-update)
402 (set-buffer-modified-p nil)
403 (message "texinfo formatting %s..." file)
404 (texinfo-format-buffer nil)
405 (if (buffer-modified-p)
406 (progn (message "Saving modified %s" (buffer-file-name))
409 (message ">> Error: %s" (prin1-to-string err))
410 (message ">> point at")
411 (let ((s (buffer-substring (point)
415 (while (setq tem (string-match "\n+" s tem))
416 (setq s (concat (substring s 0 (match-beginning 0))
418 (substring s (match-end 0)))
422 (kill-emacs error))))
424 ;;; dgnushack.el ends here