diff options
| author | Richard M. Stallman | 2002-07-20 22:01:19 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-07-20 22:01:19 +0000 |
| commit | 22788fb81788a50f53af2ea991cd0b1b97086d42 (patch) | |
| tree | 152c1316aecc425f80dac4193f1ac1a555d03fac | |
| parent | fa29ef7464c06d51517c754ebc8f53a8d4291086 (diff) | |
| download | emacs-22788fb81788a50f53af2ea991cd0b1b97086d42.tar.gz emacs-22788fb81788a50f53af2ea991cd0b1b97086d42.zip | |
Use warnings.el:
(byte-compile-warning-prefix): New function.
(byte-compile-log-file): Return page start position.
(byte-compile-log-warning): New function.
(byte-compile-warn): Use byte-compile-log-warning.
(byte-compile-report-error): Likewise. Also use error-message-string.
(displaying-byte-compile-warnings): Bind warning-series.
Don't bind or use byte-compile-warnings-point-max.
Don't display the log buffer at the end.
(byte-compile-warnings-point-max): Variable deleted.
(byte-compile-log-1): Rewrite for trace info, not used for warnings.
(byte-compile-last-warned-form, byte-compile-last-logged-file):
Defvars moved.
| -rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 129 |
1 files changed, 59 insertions, 70 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 784eec37a10..1bebfd4a9bf 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | ;;; This version incorporates changes up to version 2.10 of the | 11 | ;;; This version incorporates changes up to version 2.10 of the |
| 12 | ;;; Zawinski-Furuseth compiler. | 12 | ;;; Zawinski-Furuseth compiler. |
| 13 | (defconst byte-compile-version "$Revision: 2.104 $") | 13 | (defconst byte-compile-version "$Revision: 2.102 $") |
| 14 | 14 | ||
| 15 | ;; This file is part of GNU Emacs. | 15 | ;; This file is part of GNU Emacs. |
| 16 | 16 | ||
| @@ -815,6 +815,7 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property." | |||
| 815 | (defvar byte-compile-current-file nil) | 815 | (defvar byte-compile-current-file nil) |
| 816 | (defvar byte-compile-current-buffer nil) | 816 | (defvar byte-compile-current-buffer nil) |
| 817 | 817 | ||
| 818 | ;; Log something that isn't a warning. | ||
| 818 | (defmacro byte-compile-log (format-string &rest args) | 819 | (defmacro byte-compile-log (format-string &rest args) |
| 819 | (list 'and | 820 | (list 'and |
| 820 | 'byte-optimize | 821 | 'byte-optimize |
| @@ -830,8 +831,16 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property." | |||
| 830 | (if (symbolp x) (list 'prin1-to-string x) x)) | 831 | (if (symbolp x) (list 'prin1-to-string x) x)) |
| 831 | args))))))) | 832 | args))))))) |
| 832 | 833 | ||
| 833 | (defvar byte-compile-last-warned-form nil) | 834 | ;; Log something that isn't a warning. |
| 834 | (defvar byte-compile-last-logged-file nil) | 835 | (defun byte-compile-log-1 (string) |
| 836 | (save-excursion | ||
| 837 | (byte-goto-log-buffer) | ||
| 838 | (goto-char (point-max)) | ||
| 839 | (byte-compile-warning-prefix nil nil) | ||
| 840 | (cond (noninteractive | ||
| 841 | (message " %s" string)) | ||
| 842 | (t | ||
| 843 | (insert (format "%s\n" string)))))) | ||
| 835 | 844 | ||
| 836 | (defvar byte-compile-read-position nil | 845 | (defvar byte-compile-read-position nil |
| 837 | "Character position we began the last `read' from.") | 846 | "Character position we began the last `read' from.") |
| @@ -878,6 +887,10 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property." | |||
| 878 | (or (and allow-previous (not (= last byte-compile-last-position))) | 887 | (or (and allow-previous (not (= last byte-compile-last-position))) |
| 879 | (> last byte-compile-last-position))))))) | 888 | (> last byte-compile-last-position))))))) |
| 880 | 889 | ||
| 890 | (defvar byte-compile-last-warned-form nil) | ||
| 891 | (defvar byte-compile-last-logged-file nil) | ||
| 892 | |||
| 893 | ;; Return non-nil if should say what defun we are in. | ||
| 881 | (defun byte-compile-display-log-head-p () | 894 | (defun byte-compile-display-log-head-p () |
| 882 | (and (not (eq byte-compile-current-form :end)) | 895 | (and (not (eq byte-compile-current-form :end)) |
| 883 | (or (and byte-compile-current-file | 896 | (or (and byte-compile-current-file |
| @@ -892,9 +905,10 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property." | |||
| 892 | (unless (eq major-mode 'compilation-mode) | 905 | (unless (eq major-mode 'compilation-mode) |
| 893 | (compilation-mode))) | 906 | (compilation-mode))) |
| 894 | 907 | ||
| 895 | ;; Log a message STRING in *Compile-Log*. | 908 | ;; This is used as warning-prefix for the compiler. |
| 896 | ;; Also log the current function and file if not already done. | 909 | (defun byte-compile-warning-prefix (level entry) |
| 897 | (defun byte-compile-log-1 (string &optional fill) | 910 | (save-current-buffer |
| 911 | (byte-goto-log-buffer)) | ||
| 898 | (let* ((file (cond ((stringp byte-compile-current-file) | 912 | (let* ((file (cond ((stringp byte-compile-current-file) |
| 899 | (format "%s:" byte-compile-current-file)) | 913 | (format "%s:" byte-compile-current-file)) |
| 900 | ((bufferp byte-compile-current-file) | 914 | ((bufferp byte-compile-current-file) |
| @@ -911,24 +925,16 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property." | |||
| 911 | (1+ (current-column))))) | 925 | (1+ (current-column))))) |
| 912 | "")) | 926 | "")) |
| 913 | (form (or byte-compile-current-form "toplevel form"))) | 927 | (form (or byte-compile-current-form "toplevel form"))) |
| 914 | (cond (noninteractive | 928 | (when (byte-compile-display-log-head-p) |
| 915 | (when (byte-compile-display-log-head-p) | 929 | (insert (format "\nIn %s:\n" form))) |
| 916 | (message "%s In %s" file form)) | 930 | (when (and level (not (byte-compile-display-log-head-p))) |
| 917 | (message "%s%s %s" file pos string)) | 931 | (insert (format "\n%s%s\n" file pos)))) |
| 918 | (t | ||
| 919 | (save-excursion | ||
| 920 | (byte-goto-log-buffer) | ||
| 921 | (goto-char (point-max)) | ||
| 922 | (when (byte-compile-display-log-head-p) | ||
| 923 | (insert (format "\nIn %s" form))) | ||
| 924 | (insert (format "\n%s%s\n%s\n" file pos string)) | ||
| 925 | (when (and fill (not (string-match "\n" string))) | ||
| 926 | (let ((fill-prefix " ") (fill-column 78)) | ||
| 927 | (fill-paragraph nil))))))) | ||
| 928 | (setq byte-compile-last-logged-file byte-compile-current-file | 932 | (setq byte-compile-last-logged-file byte-compile-current-file |
| 929 | byte-compile-last-warned-form byte-compile-current-form)) | 933 | byte-compile-last-warned-form byte-compile-current-form) |
| 934 | entry) | ||
| 930 | 935 | ||
| 931 | ;; Log the start of a file in *Compile-Log*, and mark it as done. | 936 | ;; Log the start of a file in *Compile-Log*, and mark it as done. |
| 937 | ;; Return the position of the start of the page in the log buffer. | ||
| 932 | ;; But do nothing in batch mode. | 938 | ;; But do nothing in batch mode. |
| 933 | (defun byte-compile-log-file () | 939 | (defun byte-compile-log-file () |
| 934 | (and byte-compile-current-file | 940 | (and byte-compile-current-file |
| @@ -937,33 +943,36 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property." | |||
| 937 | (save-excursion | 943 | (save-excursion |
| 938 | (byte-goto-log-buffer) | 944 | (byte-goto-log-buffer) |
| 939 | (goto-char (point-max)) | 945 | (goto-char (point-max)) |
| 940 | (insert "\n\^L\nCompiling " | 946 | (insert "\n") |
| 941 | (if (stringp byte-compile-current-file) | 947 | (let ((pt (point))) |
| 942 | (concat "file " byte-compile-current-file) | 948 | (insert "^L\nCompiling " |
| 943 | (concat "buffer " (buffer-name byte-compile-current-file))) | 949 | (if (stringp byte-compile-current-file) |
| 944 | " at " (current-time-string) "\n") | 950 | (concat "file " byte-compile-current-file) |
| 945 | (setq byte-compile-last-logged-file byte-compile-current-file)))) | 951 | (concat "buffer " (buffer-name byte-compile-current-file))) |
| 952 | " at " (current-time-string) "\n") | ||
| 953 | (setq byte-compile-last-logged-file byte-compile-current-file) | ||
| 954 | pt)))) | ||
| 955 | |||
| 956 | ;; Log a message STRING in *Compile-Log*. | ||
| 957 | ;; Also log the current function and file if not already done. | ||
| 958 | (defun byte-compile-log-warning (string &optional fill level) | ||
| 959 | (let ((warning-prefix-function 'byte-compile-warning-prefix) | ||
| 960 | (warning-fill-prefix (if fill " "))) | ||
| 961 | (display-warning 'bytecomp string level "*Compile-Log*"))) | ||
| 946 | 962 | ||
| 947 | (defun byte-compile-warn (format &rest args) | 963 | (defun byte-compile-warn (format &rest args) |
| 964 | "Issue a byte compiler warning; use (format FORMAT ARGS...) for message." | ||
| 948 | (setq format (apply 'format format args)) | 965 | (setq format (apply 'format format args)) |
| 949 | (if byte-compile-error-on-warn | 966 | (if byte-compile-error-on-warn |
| 950 | (error "%s" format) ; byte-compile-file catches and logs it | 967 | (error "%s" format) ; byte-compile-file catches and logs it |
| 951 | (byte-compile-log-1 (concat "warning: " format) t) | 968 | (byte-compile-log-warning format t :warning))) |
| 952 | ;; It is useless to flash warnings too fast to be read. | ||
| 953 | ;; Besides, they will all be shown at the end. | ||
| 954 | ;; (or noninteractive ; already written on stdout. | ||
| 955 | ;; (message "Warning: %s" format)) | ||
| 956 | )) | ||
| 957 | 969 | ||
| 958 | ;;; This function should be used to report errors that have halted | ||
| 959 | ;;; compilation of the current file. | ||
| 960 | (defun byte-compile-report-error (error-info) | 970 | (defun byte-compile-report-error (error-info) |
| 971 | "Report Lisp error in compilation. ERROR-INFO is the error data." | ||
| 961 | (setq byte-compiler-error-flag t) | 972 | (setq byte-compiler-error-flag t) |
| 962 | (byte-compile-log-1 | 973 | (byte-compile-log-warning |
| 963 | (concat "error: " | 974 | (error-message-string error-info) |
| 964 | (format (if (cdr error-info) "%s (%s)" "%s") | 975 | nil :error)) |
| 965 | (downcase (get (car error-info) 'error-message)) | ||
| 966 | (prin1-to-string (cdr error-info)))))) | ||
| 967 | 976 | ||
| 968 | ;;; Used by make-obsolete. | 977 | ;;; Used by make-obsolete. |
| 969 | (defun byte-compile-obsolete (form) | 978 | (defun byte-compile-obsolete (form) |
| @@ -1304,37 +1313,17 @@ Each function's symbol gets marked with the `byte-compile-noruntime' property." | |||
| 1304 | ) | 1313 | ) |
| 1305 | body))) | 1314 | body))) |
| 1306 | 1315 | ||
| 1307 | (defvar byte-compile-warnings-point-max nil) | ||
| 1308 | (defmacro displaying-byte-compile-warnings (&rest body) | 1316 | (defmacro displaying-byte-compile-warnings (&rest body) |
| 1309 | `(let ((byte-compile-warnings-point-max byte-compile-warnings-point-max)) | 1317 | `(let (warning-series) |
| 1310 | ;; Log the file name. | 1318 | ;; Log the file name. Record position of that text. |
| 1311 | (byte-compile-log-file) | 1319 | (setq warning-series (byte-compile-log-file)) |
| 1312 | ;; Record how much is logged now. | 1320 | (let ((--displaying-byte-compile-warnings-fn (lambda () |
| 1313 | ;; We will display the log buffer if anything more is logged | 1321 | ,@body))) |
| 1314 | ;; before the end of BODY. | 1322 | (if byte-compile-debug |
| 1315 | (unless byte-compile-warnings-point-max | 1323 | (funcall --displaying-byte-compile-warnings-fn) |
| 1316 | (save-excursion | 1324 | (condition-case error-info |
| 1317 | (byte-goto-log-buffer) | 1325 | (funcall --displaying-byte-compile-warnings-fn) |
| 1318 | (setq byte-compile-warnings-point-max (point-max)))) | 1326 | (error (byte-compile-report-error error-info))))))) |
| 1319 | (unwind-protect | ||
| 1320 | (let ((--displaying-byte-compile-warnings-fn (lambda () | ||
| 1321 | ,@body))) | ||
| 1322 | (if byte-compile-debug | ||
| 1323 | (funcall --displaying-byte-compile-warnings-fn) | ||
| 1324 | (condition-case error-info | ||
| 1325 | (funcall --displaying-byte-compile-warnings-fn) | ||
| 1326 | (error (byte-compile-report-error error-info))))) | ||
| 1327 | (with-current-buffer "*Compile-Log*" | ||
| 1328 | ;; If there were compilation warnings, display them. | ||
| 1329 | (unless (= byte-compile-warnings-point-max (point-max)) | ||
| 1330 | (select-window | ||
| 1331 | (prog1 (selected-window) | ||
| 1332 | (select-window (display-buffer (current-buffer))) | ||
| 1333 | (goto-char byte-compile-warnings-point-max) | ||
| 1334 | (beginning-of-line) | ||
| 1335 | (forward-line -1) | ||
| 1336 | (recenter 0)))))))) | ||
| 1337 | |||
| 1338 | 1327 | ||
| 1339 | ;;;###autoload | 1328 | ;;;###autoload |
| 1340 | (defun byte-force-recompile (directory) | 1329 | (defun byte-force-recompile (directory) |