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)
71 (byte-defop-compiler char-after 0-1)))
75 (wrong-number-of-arguments
76 ;; Optimize byte code for `char-before'.
77 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
78 (defun byte-optimize-char-before (form)
80 '(char-before (point))
83 ;; `char-after' and `char-before' must be well-behaved before lpath.el
84 ;; is loaded. Because it requires `poe' via `path-util'.
85 (load "./lpath.el" nil t)
87 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
88 ;; Bind defcustom'ed variables.
89 (put 'custom-declare-variable 'byte-hunk-handler
90 'byte-compile-file-form-custom-declare-variable)
91 (defun byte-compile-file-form-custom-declare-variable (form)
92 (if (memq 'free-vars byte-compile-warnings)
93 (setq byte-compile-bound-variables
94 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
97 ;; Bind functions defined by `defun-maybe'.
98 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
99 (defun byte-compile-file-form-defun-maybe (form)
100 (if (and (not (fboundp (nth 1 form)))
101 (memq 'unresolved byte-compile-warnings))
102 (setq byte-compile-function-environment
103 (cons (cons (nth 1 form)
104 (cons 'lambda (cdr (cdr form))))
105 byte-compile-function-environment)))
109 :symbol-for-testing-whether-colon-keyword-is-available-or-not
112 (mapcar (lambda (keyword) (set keyword keyword))
113 '(:button-keymap :data :file :mime-handle))))
115 ;; Unknown variables and functions.
116 (unless (boundp 'buffer-file-coding-system)
117 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
118 (autoload 'font-lock-set-defaults "font-lock")
119 (unless (fboundp 'coding-system-get)
120 (defalias 'coding-system-get 'ignore))
122 (defalias 'find-coding-system 'ignore))
123 (unless (fboundp 'get-charset-property)
124 (defalias 'get-charset-property 'ignore))
125 (unless (featurep 'xemacs)
126 (defalias 'Custom-make-dependencies 'ignore)
127 (defalias 'toolbar-gnus 'ignore)
128 (defalias 'update-autoloads-from-directory 'ignore))
129 (autoload 'texinfo-parse-line-arg "texinfmt")
131 (unless (fboundp 'with-temp-buffer)
132 ;; Pickup some macros.
135 (defalias 'device-sound-enabled-p 'ignore)
136 (defalias 'play-sound-file 'ignore)
137 (defalias 'nndb-request-article 'ignore)
138 (defalias 'efs-re-read-dir 'ignore)
139 (defalias 'ange-ftp-re-read-dir 'ignore)
140 (defalias 'define-mail-user-agent 'ignore)
143 (unless (string-match "XEmacs" emacs-version)
144 (fset 'get-popup-menu-response 'ignore)
145 (fset 'event-object 'ignore)
146 (fset 'x-defined-colors 'ignore)
147 (fset 'read-color 'ignore)))
149 (defun dgnushack-compile (&optional warn)
150 ;;(setq byte-compile-dynamic t)
152 (setq byte-compile-warnings
153 '(free-vars unresolved callargs redefine)))
154 (unless (locate-library "cus-edit")
155 (error "You do not seem to have Custom installed.
156 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
157 You also then need to add the following to the lisp/dgnushack.el file:
159 (push \"~/lisp/custom\" load-path)
161 Modify to suit your needs."))
162 (let ((files (delete "dgnuspath.el"
163 (directory-files "." nil "^[^=].*\\.el$")))
164 (xemacs (string-match "XEmacs" emacs-version))
165 ;;(byte-compile-generate-call-tree t)
169 (error (setq files (delete "nnweb.el" (delete "nnlistserv.el" files)))))
172 (error (setq files (delete "gnus-bbdb.el" files))))
173 (while (setq file (pop files))
174 (when (or (and (not xemacs)
175 (not (member file '("gnus-xmas.el" "gnus-picon.el"
176 "messagexmas.el" "nnheaderxm.el"
177 "smiley.el" "x-overlay.el"))))
179 (not (member file '("md5.el")))))
180 (when (or (not (file-exists-p (setq elc (concat file "c"))))
181 (file-newer-than-file-p file elc))
183 (byte-compile-file file)))))))
185 (defun dgnushack-recompile ()
187 (byte-recompile-directory "." 0))
190 ;; Avoid byte-compile warnings.
191 (defvar gnus-product-name)
192 (defvar early-package-load-path)
193 (defvar early-packages)
194 (defvar last-package-load-path)
195 (defvar last-packages)
196 (defvar late-package-load-path)
197 (defvar late-packages)
199 (defconst dgnushack-info-file-regexp
200 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
201 "\\.info\\(-[0-9]+\\)?$"))
203 (defconst dgnushack-texi-file-regexp
204 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
206 (defun dgnushack-make-package ()
208 (let* ((product-name (downcase gnus-product-name))
209 (lisp-dir (concat "lisp/" product-name "/"))
212 (message "Updating autoloads for directory %s..." default-directory)
213 (let ((generated-autoload-file "auto-autoloads.el")
215 (omsg (symbol-function 'message)))
216 (defun message (fmt &rest args)
217 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
218 (file-exists-p (file-name-nondirectory (car args))))
219 (funcall omsg fmt (file-name-nondirectory (car args))))
220 ((string-equal "No autoloads found in %s" fmt))
221 ((string-equal "Generating autoloads for %s...done" fmt))
222 (t (apply omsg fmt args))))
224 (update-autoloads-from-directory default-directory)
225 (fset 'message omsg)))
226 (byte-compile-file "auto-autoloads.el")
229 (let ((standard-output (current-buffer)))
230 (Custom-make-dependencies "."))
231 (message (buffer-string)))
233 (byte-compile-file "custom-load.el")
235 (message "Generating MANIFEST.%s for the package..." product-name)
237 (insert "pkginfo/MANIFEST." product-name "\n"
241 (sort (delete "dgnuspath.el"
243 (directory-files "." nil "\\.elc?$")))
245 (concat "\n" lisp-dir))
249 (sort (directory-files "../texi/"
250 nil dgnushack-info-file-regexp)
254 (write-file (concat "../MANIFEST." product-name)))))
256 (defun dgnushack-install-package ()
257 (let ((package-dir (car command-line-args-left))
258 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
260 (when (boundp 'early-packages)
261 (setq dirs (delq nil (append (when early-package-load-path
263 (when late-package-load-path
265 (when last-package-load-path
267 (while (and dirs (not package-dir))
268 (when (file-exists-p (car dirs))
269 (setq package-dir (car dirs)
273 You must specify the name of the package path as follows:
275 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
278 (setq info-dir (expand-file-name "info/" package-dir)
279 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
281 (setq product-name (downcase gnus-product-name)
282 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
284 manifest (concat "MANIFEST." product-name))
286 (unless (file-directory-p lisp-dir)
287 (make-directory lisp-dir t))
288 (unless (file-directory-p info-dir)
289 (make-directory info-dir))
290 (unless (file-directory-p pkginfo-dir)
291 (make-directory pkginfo-dir))
294 (sort (delete "dgnuspath.el"
295 (delete "dgnuspath.elc"
296 (directory-files "." nil "\\.elc?$")))
300 (unless (member file files)
301 (setq file (expand-file-name file lisp-dir))
302 (message "Removing %s..." file)
306 (directory-files lisp-dir nil nil nil t))
309 (message "Copying %s to %s..." file lisp-dir)
310 (copy-file file (expand-file-name file lisp-dir) t t))
315 (message "Copying ../texi/%s to %s..." file info-dir)
316 (copy-file (expand-file-name file "../texi/")
317 (expand-file-name file info-dir)
319 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
322 (message "Copying ../%s to %s..." manifest pkginfo-dir)
323 (copy-file (expand-file-name manifest "../")
324 (expand-file-name manifest pkginfo-dir) t t)
328 (defun dgnushack-texi-add-suffix-and-format ()
329 (dgnushack-texi-format t))
331 (defun dgnushack-texi-format (&optional addsuffix)
332 (if (not noninteractive)
333 (error "batch-texinfo-format may only be used -batch."))
335 (let ((auto-save-default nil)
336 (find-file-run-dired nil)
337 coding-system-for-write)
341 (while command-line-args-left
342 (setq file (expand-file-name (car command-line-args-left)))
343 (cond ((not (file-exists-p file))
344 (message ">> %s does not exist!" file)
346 command-line-args-left (cdr command-line-args-left)))
347 ((file-directory-p file)
348 (setq command-line-args-left
349 (nconc (directory-files file)
350 (cdr command-line-args-left))))
352 (setq files (cons file files)
353 command-line-args-left (cdr command-line-args-left)))))
355 (setq file (car files)
359 (if buffer-file-name (kill-buffer (current-buffer)))
361 (setq coding-system-for-write buffer-file-coding-system)
364 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
365 (not (string-match "\\.info$" (match-string 1))))
367 (buffer-disable-undo (current-buffer))
368 ;; process @include before updating node
369 ;; This might produce some problem if we use @lowersection or
371 (let ((input-directory default-directory)
372 (texinfo-command-end))
373 (while (re-search-forward "^@include" nil t)
374 (setq texinfo-command-end (point))
375 (let ((filename (concat input-directory
376 (texinfo-parse-line-arg))))
377 (re-search-backward "^@include")
378 (delete-region (point) (save-excursion
381 (message "Reading included file: %s" filename)
387 (car (cdr (insert-file-contents filename)))))
388 (goto-char (point-min))
389 ;; Remove `@setfilename' line from included file,
390 ;; if any, so @setfilename command not duplicated.
391 (if (re-search-forward "^@setfilename"
398 (delete-region (point) (save-excursion
402 (texinfo-every-node-update)
403 (set-buffer-modified-p nil)
404 (message "texinfo formatting %s..." file)
405 (texinfo-format-buffer nil)
406 (if (buffer-modified-p)
407 (progn (message "Saving modified %s" (buffer-file-name))
410 (message ">> Error: %s" (prin1-to-string err))
411 (message ">> point at")
412 (let ((s (buffer-substring (point)
416 (while (setq tem (string-match "\n+" s tem))
417 (setq s (concat (substring s 0 (match-beginning 0))
419 (substring s (match-end 0)))
423 (kill-emacs error))))
425 ;;; dgnushack.el ends here