From 430e7297cbfe8c2ef14b5b703fc56c4efce439c0 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 31 Oct 2010 15:25:39 -0400 Subject: * lisp/emacs-lisp/bytecomp.el (byte-recompile-file): New fun. (byte-recompile-directory): * lisp/emacs-lisp/lisp-mode.el (emacs-lisp-byte-compile-and-load): * cedet/ede/proj-elisp.el (project-compile-target): * cedet/semantic/ede-grammar.el (project-compile-target): Use `byte-recompile-file'. Fixes: debbugs:7297 --- lisp/emacs-lisp/bytecomp.el | 75 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 17 deletions(-) (limited to 'lisp/emacs-lisp/bytecomp.el') diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index b3ac7b83d79..5afe49346b5 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -37,6 +37,7 @@ ;; ======================================================================== ;; Entry points: ;; byte-recompile-directory, byte-compile-file, +;; byte-recompile-file, ;; batch-byte-compile, batch-byte-recompile-directory, ;; byte-compile, compile-defun, ;; display-call-tree @@ -1551,23 +1552,10 @@ that already has a `.elc' file." (not (auto-save-file-name-p bytecomp-source)) (not (string-equal dir-locals-file (file-name-nondirectory - bytecomp-source))) - (setq bytecomp-dest - (byte-compile-dest-file bytecomp-source)) - (if (file-exists-p bytecomp-dest) - ;; File was already compiled. - (or bytecomp-force - (file-newer-than-file-p bytecomp-source - bytecomp-dest)) - ;; No compiled file exists yet. - (and bytecomp-arg - (or (eq 0 bytecomp-arg) - (y-or-n-p (concat "Compile " - bytecomp-source "? ")))))) - (progn (if (and noninteractive (not byte-compile-verbose)) - (message "Compiling %s..." bytecomp-source)) - (let ((bytecomp-res (byte-compile-file - bytecomp-source))) + bytecomp-source)))) + (progn (let ((bytecomp-res (byte-recompile-file + bytecomp-source + bytecomp-force bytecomp-arg))) (cond ((eq bytecomp-res 'no-byte-compile) (setq skip-count (1+ skip-count))) ((eq bytecomp-res t) @@ -1595,6 +1583,59 @@ This is normally set in local file variables at the end of the elisp file: ;; Local Variables:\n;; no-byte-compile: t\n;; End: ") ;;;###autoload(put 'no-byte-compile 'safe-local-variable 'booleanp) +(defun byte-recompile-file (bytecomp-filename &optional bytecomp-force bytecomp-arg load) + "Recompile BYTECOMP-FILENAME file if it needs recompilation. +This happens when its `.elc' file is older than itself. + +If the `.elc' file exists and is up-to-date, normally this +function *does not* compile BYTECOMP-FILENAME. However, if the +prefix argument BYTECOMP-FORCE is set, that means do compile +BYTECOMP-FILENAME even if the destination already exists and is +up-to-date. + +If the `.elc' file does not exist, normally this function *does +not* compile BYTECOMP-FILENAME. If BYTECOMP-ARG is 0, that means +compile the file even if it has never been compiled before. +A nonzero BYTECOMP-ARG means ask the user. + +If LOAD is set, `load' the file after compiling. + +The value returned is the value returned by `byte-compile-file', +or 'no-byte-compile if the file did not need recompilation." + (interactive + (let ((bytecomp-file buffer-file-name) + (bytecomp-file-name nil) + (bytecomp-file-dir nil)) + (and bytecomp-file + (eq (cdr (assq 'major-mode (buffer-local-variables))) + 'emacs-lisp-mode) + (setq bytecomp-file-name (file-name-nondirectory bytecomp-file) + bytecomp-file-dir (file-name-directory bytecomp-file))) + (list (read-file-name (if current-prefix-arg + "Byte compile file: " + "Byte recompile file: ") + bytecomp-file-dir bytecomp-file-name nil) + current-prefix-arg))) + (let ((bytecomp-dest + (byte-compile-dest-file bytecomp-filename)) + ;; Expand now so we get the current buffer's defaults + (bytecomp-filename (expand-file-name bytecomp-filename))) + (if (if (file-exists-p bytecomp-dest) + ;; File was already compiled + ;; Compile if forced to, or filename newer + (or bytecomp-force + (file-newer-than-file-p bytecomp-filename + bytecomp-dest)) + (or (eq 0 bytecomp-arg) + (y-or-n-p (concat "Compile " + bytecomp-filename "? ")))) + (progn + (if (and noninteractive (not byte-compile-verbose)) + (message "Compiling %s..." bytecomp-source)) + (byte-compile-file bytecomp-filename load)) + (when load (load bytecomp-filename)) + 'no-byte-compile))) + ;;;###autoload (defun byte-compile-file (bytecomp-filename &optional load) "Compile a file of Lisp code named BYTECOMP-FILENAME into a file of byte code. -- cgit v1.2.3 From feb5e60ae796691a61e9a4078a0dff0111fcae31 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Sun, 31 Oct 2010 19:55:12 -0700 Subject: * lisp/emacs-lisp/bytecomp.el (byte-recompile-file): Fix previous change. --- lisp/ChangeLog | 2 ++ lisp/emacs-lisp/bytecomp.el | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp/emacs-lisp/bytecomp.el') diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 45bee01c97d..6a2df683e40 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,7 @@ 2010-11-01 Glenn Morris + * emacs-lisp/bytecomp.el (byte-recompile-file): Fix previous change. + * startup.el (package-enable-at-startup, package-initialize): Silence compiler. diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 5afe49346b5..952b69f7ce3 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -1631,7 +1631,7 @@ or 'no-byte-compile if the file did not need recompilation." bytecomp-filename "? ")))) (progn (if (and noninteractive (not byte-compile-verbose)) - (message "Compiling %s..." bytecomp-source)) + (message "Compiling %s..." bytecomp-filename)) (byte-compile-file bytecomp-filename load)) (when load (load bytecomp-filename)) 'no-byte-compile))) @@ -4349,5 +4349,4 @@ and corresponding effects." (run-hooks 'bytecomp-load-hook) -;; arch-tag: 9c97b0f0-8745-4571-bfc3-8dceb677292a ;;; bytecomp.el ends here -- cgit v1.2.3 From fa14dc18009a53f217466263d04e53b2be98cbfa Mon Sep 17 00:00:00 2001 From: Noah Friedman Date: Tue, 2 Nov 2010 15:51:25 -0700 Subject: (byte-recompile-file): If bytecomp-arg is nil, do not ask to recompile files that are not already compiled, and do not recompile them. --- lisp/ChangeLog | 6 ++++++ lisp/emacs-lisp/bytecomp.el | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'lisp/emacs-lisp/bytecomp.el') diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 239f50c3c80..c5d8bfae7a7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2010-11-02 Noah Friedman + + * emacs-lisp/bytecomp.el (byte-recompile-file): If bytecomp-arg is + nil, do not ask to recompile files that are not already compiled, + and do not recompile them. + 2010-11-02 Chong Yidong * emacs-lisp/package.el (package-initialize): Ensure that diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 952b69f7ce3..aec6bdb2f35 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -1626,9 +1626,10 @@ or 'no-byte-compile if the file did not need recompilation." (or bytecomp-force (file-newer-than-file-p bytecomp-filename bytecomp-dest)) - (or (eq 0 bytecomp-arg) - (y-or-n-p (concat "Compile " - bytecomp-filename "? ")))) + (and bytecomp-arg + (or (eq 0 bytecomp-arg) + (y-or-n-p (concat "Compile " + bytecomp-filename "? "))))) (progn (if (and noninteractive (not byte-compile-verbose)) (message "Compiling %s..." bytecomp-filename)) -- cgit v1.2.3 From acef0722fc954a88eea588486b478f49b1afdc6a Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 11 Nov 2010 17:19:01 -0500 Subject: * lisp/files.el (safe-local-variable-p): Gracefully handle errors. * lisp/emacs-lisp/bytecomp.el (byte-compile-warnings): Simplify the safety predicate. --- lisp/ChangeLog | 5 +++++ lisp/emacs-lisp/bytecomp.el | 17 ++++------------- lisp/files.el | 5 ++++- 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'lisp/emacs-lisp/bytecomp.el') diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 88dc22a011d..fef5fec5ce9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,10 @@ 2010-11-11 Stefan Monnier + * emacs-lisp/bytecomp.el (byte-compile-warnings): Simplify the + safety predicate. + + * files.el (safe-local-variable-p): Gracefully handle errors. + * emacs-lisp/smie.el (smie-rule-parent, smie-indent--rule): Use smie-indent-virtual when indenting relative to an opener. (smie-rule-separator): Use smie-rule-parent. diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 394169be99d..cdfac80ca78 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -294,21 +294,12 @@ suppress. For example, (not mapcar) will suppress warnings about mapcar." (set :menu-tag "Some" ,@(mapcar (lambda (x) `(const ,x)) byte-compile-warning-types)))) -;;;###autoload(put 'byte-compile-warnings 'safe-local-variable 'byte-compile-warnings-safe-p) ;;;###autoload -(defun byte-compile-warnings-safe-p (x) - "Return non-nil if X is valid as a value of `byte-compile-warnings'." - (or (booleanp x) - (and (listp x) - (if (eq (car x) 'not) (setq x (cdr x)) - t) - (equal (mapcar - (lambda (e) - (when (memq e byte-compile-warning-types) - e)) - x) - x)))) +(put 'byte-compile-warnings 'safe-local-variable + (lambda (v) + (or (symbolp v) + (null (delq nil (mapcar (lambda (x) (not (symbolp x))) v)))))) (defun byte-compile-warning-enabled-p (warning) "Return non-nil if WARNING is enabled, according to `byte-compile-warnings'." diff --git a/lisp/files.el b/lisp/files.el index 0664bfd3844..4901c3872cd 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3134,7 +3134,10 @@ It is safe if any of these conditions are met: evaluates to a non-nil value with VAL as an argument." (or (member (cons sym val) safe-local-variable-values) (let ((safep (get sym 'safe-local-variable))) - (and (functionp safep) (funcall safep val))))) + (and (functionp safep) + ;; If the function signals an error, that means it + ;; can't assure us that the value is safe. + (with-demoted-errors (funcall safep val)))))) (defun risky-local-variable-p (sym &optional ignored) "Non-nil if SYM could be dangerous as a file-local variable. -- cgit v1.2.3 From 7847454adc4388578113b4237e99fae4d0775b43 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Thu, 11 Nov 2010 19:21:38 -0800 Subject: bytecomp trivia. * lisp/emacs-lisp/bytecomp.el (byte-compile-log-buffer): New constant. Use it to replace all instances of "*Compile-Log*" --- lisp/ChangeLog | 5 +++++ lisp/emacs-lisp/bytecomp.el | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'lisp/emacs-lisp/bytecomp.el') diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a66cabab108..9dd1e61de47 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2010-11-12 Glenn Morris + + * emacs-lisp/bytecomp.el (byte-compile-log-buffer): New constant. + Use it to replace all instances of "*Compile-Log*" + 2010-11-12 Stefan Monnier * emacs-lisp/pcase.el (pcase-let*, pcase-let): Add debug and diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index aec6bdb2f35..f1adc5b496c 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -248,10 +248,14 @@ This option is enabled by default because it reduces Emacs memory usage." :type 'boolean) ;;;###autoload(put 'byte-compile-dynamic-docstrings 'safe-local-variable 'booleanp) +(defconst byte-compile-log-buffer "*Compile-Log*" + "Name of the byte-compiler's log buffer.") + (defcustom byte-optimize-log nil - "If true, the byte-compiler will log its optimizations into *Compile-Log*. + "If non-nil, the byte-compiler will log its optimizations. If this is 'source, then only source-level optimizations will be logged. -If it is 'byte, then only byte-level optimizations will be logged." +If it is 'byte, then only byte-level optimizations will be logged. +The information is logged to `byte-compile-log-buffer'." :group 'bytecomp :type '(choice (const :tag "none" nil) (const :tag "all" t) @@ -885,7 +889,7 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'." ;; Log something that isn't a warning. (defun byte-compile-log-1 (string) - (with-current-buffer "*Compile-Log*" + (with-current-buffer byte-compile-log-buffer (let ((inhibit-read-only t)) (goto-char (point-max)) (byte-compile-warning-prefix nil nil) @@ -993,13 +997,13 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'." ;; (compile-mode) will cause this to be loaded. (declare-function compilation-forget-errors "compile" ()) -;; Log the start of a file in *Compile-Log*, and mark it as done. +;; Log the start of a file in `byte-compile-log-buffer', and mark it as done. ;; Return the position of the start of the page in the log buffer. ;; But do nothing in batch mode. (defun byte-compile-log-file () (and (not (equal byte-compile-current-file byte-compile-last-logged-file)) (not noninteractive) - (with-current-buffer (get-buffer-create "*Compile-Log*") + (with-current-buffer (get-buffer-create byte-compile-log-buffer) (goto-char (point-max)) (let* ((inhibit-read-only t) (dir (and byte-compile-current-file @@ -1030,14 +1034,14 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'." (compilation-forget-errors) pt)))) -;; Log a message STRING in *Compile-Log*. +;; Log a message STRING in `byte-compile-log-buffer'. ;; Also log the current function and file if not already done. (defun byte-compile-log-warning (string &optional fill level) (let ((warning-prefix-function 'byte-compile-warning-prefix) (warning-type-format "") (warning-fill-prefix (if fill " ")) (inhibit-read-only t)) - (display-warning 'bytecomp string level "*Compile-Log*"))) + (display-warning 'bytecomp string level byte-compile-log-buffer))) (defun byte-compile-warn (format &rest args) "Issue a byte compiler warning; use (format FORMAT ARGS...) for message." @@ -1453,7 +1457,7 @@ symbol itself." (warning-series-started (and (markerp warning-series) (eq (marker-buffer warning-series) - (get-buffer "*Compile-Log*"))))) + (get-buffer byte-compile-log-buffer))))) (byte-compile-find-cl-functions) (if (or (eq warning-series 'byte-compile-warning-series) warning-series-started) @@ -1515,7 +1519,7 @@ that already has a `.elc' file." nil (save-some-buffers) (force-mode-line-update)) - (with-current-buffer (get-buffer-create "*Compile-Log*") + (with-current-buffer (get-buffer-create byte-compile-log-buffer) (setq default-directory (expand-file-name bytecomp-directory)) ;; compilation-mode copies value of default-directory. (unless (eq major-mode 'compilation-mode) -- cgit v1.2.3