Mercurial > hg > xemacs-beta
comparison lisp/bytecomp.el @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | b8cc9ab3f761 |
children | ebe98a74bd68 |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
1 ;;; bytecomp.el --- compilation of Lisp code into byte code. | 1 ;;; bytecomp.el --- compilation of Lisp code into byte code. |
2 | 2 |
3 ;;; Copyright (C) 1985-1987, 1991-1994 Free Software Foundation, Inc. | 3 ;;; Copyright (C) 1985-1987, 1991-1994 Free Software Foundation, Inc. |
4 ;;; Copyright (C) 1996 Ben Wing. | 4 ;;; Copyright (C) 1996 Ben Wing. |
5 | 5 |
6 ;; Author: Jamie Zawinski <jwz@jwz.org> | 6 ;; Author: Jamie Zawinski <jwz@netscape.com> |
7 ;; Hallvard Furuseth <hbf@ulrik.uio.no> | 7 ;; Hallvard Furuseth <hbf@ulrik.uio.no> |
8 ;; Keywords: internal | 8 ;; Keywords: internal |
9 | 9 |
10 ;; Subsequently modified by RMS and others. | 10 ;; Subsequently modified by RMS and others. |
11 | 11 |
1353 ;;;###autoload | 1353 ;;;###autoload |
1354 (defun byte-force-recompile (directory) | 1354 (defun byte-force-recompile (directory) |
1355 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file. | 1355 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file. |
1356 Files in subdirectories of DIRECTORY are processed also." | 1356 Files in subdirectories of DIRECTORY are processed also." |
1357 (interactive "DByte force recompile (directory): ") | 1357 (interactive "DByte force recompile (directory): ") |
1358 (byte-recompile-directory directory nil nil t)) | 1358 (byte-recompile-directory directory nil t)) |
1359 | 1359 |
1360 ;;;###autoload | 1360 ;;;###autoload |
1361 (defun byte-recompile-directory (directory &optional arg norecursion force) | 1361 (defun byte-recompile-directory (directory &optional arg norecursion force) |
1362 "Recompile every `.el' file in DIRECTORY that needs recompilation. | 1362 "Recompile every `.el' file in DIRECTORY that needs recompilation. |
1363 This is if a `.elc' file exists but is older than the `.el' file. | 1363 This is if a `.elc' file exists but is older than the `.el' file. |
1520 (insert "\n") ; aaah, unix. | 1520 (insert "\n") ; aaah, unix. |
1521 (setq target-file (byte-compile-dest-file filename)) | 1521 (setq target-file (byte-compile-dest-file filename)) |
1522 (unless byte-compile-overwrite-file | 1522 (unless byte-compile-overwrite-file |
1523 (ignore-file-errors (delete-file target-file))) | 1523 (ignore-file-errors (delete-file target-file))) |
1524 (if (file-writable-p target-file) | 1524 (if (file-writable-p target-file) |
1525 (write-region 1 (point-max) target-file) | 1525 (progn |
1526 (when (memq system-type '(ms-dos windows-nt)) | |
1527 (defvar buffer-file-type) | |
1528 (setq buffer-file-type t)) | |
1529 (write-region 1 (point-max) target-file)) | |
1526 ;; This is just to give a better error message than write-region | 1530 ;; This is just to give a better error message than write-region |
1527 (signal 'file-error | 1531 (signal 'file-error |
1528 (list "Opening output file" | 1532 (list "Opening output file" |
1529 (if (file-exists-p target-file) | 1533 (if (file-exists-p target-file) |
1530 "cannot overwrite file" | 1534 "cannot overwrite file" |
1741 | 1745 |
1742 ;; back in the inbuffer; determine and set the coding system for the .elc | 1746 ;; back in the inbuffer; determine and set the coding system for the .elc |
1743 ;; file if under Mule. If there are any extended characters in the | 1747 ;; file if under Mule. If there are any extended characters in the |
1744 ;; input file, use `escape-quoted' to make sure that both binary and | 1748 ;; input file, use `escape-quoted' to make sure that both binary and |
1745 ;; extended characters are output properly and distinguished properly. | 1749 ;; extended characters are output properly and distinguished properly. |
1746 ;; Otherwise, use `raw-text' for maximum portability with non-Mule | 1750 ;; Otherwise, use `no-conversion' for maximum portability with non-Mule |
1747 ;; Emacsen. | 1751 ;; Emacsen. |
1748 (when (featurep '(or mule file-coding)) | 1752 (when (featurep 'mule) |
1749 (defvar buffer-file-coding-system) | 1753 (defvar buffer-file-coding-system) |
1750 (if (or (featurep '(not mule)) ;; Don't scan buffer if we are not muleized | 1754 (if (save-excursion |
1751 (save-excursion | 1755 (set-buffer byte-compile-inbuffer) |
1752 (set-buffer byte-compile-inbuffer) | 1756 (goto-char (point-min)) |
1753 (goto-char (point-min)) | 1757 ;; mrb- There must be a better way than skip-chars-forward |
1754 ;; mrb- There must be a better way than skip-chars-forward | 1758 (skip-chars-forward (concat (char-to-string 0) "-" |
1755 (skip-chars-forward (concat (char-to-string 0) "-" | 1759 (char-to-string 255))) |
1756 (char-to-string 255))) | 1760 (eq (point) (point-max))) |
1757 (eq (point) (point-max)))) | 1761 (setq buffer-file-coding-system 'no-conversion) |
1758 (setq buffer-file-coding-system 'raw-text-unix) | |
1759 (insert "(require 'mule)\n;;;###coding system: escape-quoted\n") | 1762 (insert "(require 'mule)\n;;;###coding system: escape-quoted\n") |
1760 (setq buffer-file-coding-system 'escape-quoted) | 1763 (setq buffer-file-coding-system 'escape-quoted) |
1761 ;; #### Lazy loading not yet implemented for MULE files | 1764 ;; #### Lazy loading not yet implemented for MULE files |
1762 ;; mrb - Fix this someday. | 1765 ;; mrb - Fix this someday. |
1763 (save-excursion | 1766 (save-excursion |
1962 (let ((form form)) | 1965 (let ((form form)) |
1963 ;; all forms are constant | 1966 ;; all forms are constant |
1964 (while (if (setq form (cdr form)) | 1967 (while (if (setq form (cdr form)) |
1965 (byte-compile-constp (car form)))) | 1968 (byte-compile-constp (car form)))) |
1966 (null form))) | 1969 (null form))) |
1967 ;; eval the macro autoload into the compilation environment | 1970 ;; eval the macro autoload into the compilation enviroment |
1968 (eval form)) | 1971 (eval form)) |
1969 | 1972 |
1970 (if name | 1973 (if name |
1971 (let ((old (assq name byte-compile-autoload-environment))) | 1974 (let ((old (assq name byte-compile-autoload-environment))) |
1972 (cond (old | 1975 (cond (old |
4035 (defvar command-line-args-left) ;Avoid 'free variable' warning | 4038 (defvar command-line-args-left) ;Avoid 'free variable' warning |
4036 (if (not noninteractive) | 4039 (if (not noninteractive) |
4037 (error "`batch-byte-compile' is to be used only with -batch")) | 4040 (error "`batch-byte-compile' is to be used only with -batch")) |
4038 (let ((error nil)) | 4041 (let ((error nil)) |
4039 (while command-line-args-left | 4042 (while command-line-args-left |
4040 (if (null (batch-byte-compile-one-file)) | 4043 (if (file-directory-p (expand-file-name (car command-line-args-left))) |
4041 (setq error t))) | 4044 (let ((files (directory-files (car command-line-args-left))) |
4045 source dest) | |
4046 (while files | |
4047 (if (and (string-match emacs-lisp-file-regexp (car files)) | |
4048 (not (auto-save-file-name-p (car files))) | |
4049 (setq source (expand-file-name | |
4050 (car files) | |
4051 (car command-line-args-left))) | |
4052 (setq dest (byte-compile-dest-file source)) | |
4053 (file-exists-p dest) | |
4054 (file-newer-than-file-p source dest)) | |
4055 (if (null (batch-byte-compile-1 source)) | |
4056 (setq error t))) | |
4057 (setq files (cdr files)))) | |
4058 (if (null (batch-byte-compile-1 (car command-line-args-left))) | |
4059 (setq error t))) | |
4060 (setq command-line-args-left (cdr command-line-args-left))) | |
4042 (message "Done") | 4061 (message "Done") |
4043 (kill-emacs (if error 1 0)))) | 4062 (kill-emacs (if error 1 0)))) |
4044 | |
4045 ;;;###autoload | |
4046 (defun batch-byte-compile-one-file () | |
4047 "Run `byte-compile-file' on a single file remaining on the command line. | |
4048 Use this from the command line, with `-batch'; | |
4049 it won't work in an interactive Emacs." | |
4050 ;; command-line-args-left is what is left of the command line (from | |
4051 ;; startup.el) | |
4052 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
4053 (if (not noninteractive) | |
4054 (error "`batch-byte-compile-one-file' is to be used only with -batch")) | |
4055 (let (error | |
4056 (file-to-process (car command-line-args-left))) | |
4057 (setq command-line-args-left (cdr command-line-args-left)) | |
4058 (if (file-directory-p (expand-file-name file-to-process)) | |
4059 (let ((files (directory-files file-to-process)) | |
4060 source dest) | |
4061 (while files | |
4062 (if (and (string-match emacs-lisp-file-regexp (car files)) | |
4063 (not (auto-save-file-name-p (car files))) | |
4064 (setq source (expand-file-name | |
4065 (car files) | |
4066 file-to-process)) | |
4067 (setq dest (byte-compile-dest-file source)) | |
4068 (file-exists-p dest) | |
4069 (file-newer-than-file-p source dest)) | |
4070 (if (null (batch-byte-compile-1 source)) | |
4071 (setq error t))) | |
4072 (setq files (cdr files))) | |
4073 (null error)) | |
4074 (batch-byte-compile-1 file-to-process)))) | |
4075 | 4063 |
4076 (defun batch-byte-compile-1 (file) | 4064 (defun batch-byte-compile-1 (file) |
4077 (condition-case err | 4065 (condition-case err |
4078 (progn (byte-compile-file file) t) | 4066 (progn (byte-compile-file file) t) |
4079 (error | 4067 (error |