summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2016-09-17 12:43:54 +0000
committerAlan Mackenzie <acm@muc.de>2016-09-17 12:43:54 +0000
commit277e7b011d4131a1f0ecde38ecd48429d5fe388c (patch)
tree893a67957d329bd67d022cdf10f0e26a1d6c5003 /lisp/emacs-lisp
parentaab079d1d2d391bd1d6892a6bed0bc98eebce02d (diff)
downloademacs-277e7b011d4131a1f0ecde38ecd48429d5fe388c.tar.gz
Improve accuracy of line/column numbers in byte compiler's warning messages.
* lisp/emacs-lisp/bytecomp.el (byte-compile-set-symbol-position): ensure new value of byte-compile-last-position is not lower than old value. (byte-compile-function-warn): call byte-compile-set-symbol-position.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/bytecomp.el48
1 files changed, 26 insertions, 22 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index b6bb1d6ab90..c34ec5cae0d 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1022,39 +1022,42 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'."
(setcdr list (cddr list)))
total)))
-;; The purpose of this function is to iterate through the
-;; `read-symbol-positions-list'. Each time we process, say, a
-;; function definition (`defun') we remove `defun' from
-;; `read-symbol-positions-list', and set `byte-compile-last-position'
-;; to that symbol's character position. Similarly, if we encounter a
-;; variable reference, like in (1+ foo), we remove `foo' from the
-;; list. If our current position is after the symbol's position, we
-;; assume we've already passed that point, and look for the next
-;; occurrence of the symbol.
+;; The purpose of `byte-compile-set-symbol-position' is to attempt to
+;; set `byte-compile-last-position' to the "current position" in the
+;; raw source code. This is used for warning and error messages.
;;
-;; This function should not be called twice for the same occurrence of
-;; a symbol, and it should not be called for symbols generated by the
-;; byte compiler itself; because rather than just fail looking up the
-;; symbol, we may find an occurrence of the symbol further ahead, and
-;; then `byte-compile-last-position' as advanced too far.
+;; The function should be called for most occurrences of symbols in
+;; the forms being compiled, strictly in the order they occur in the
+;; source code. It should never be called twice for any single
+;; occurrence, and should not be called for symbols generated by the
+;; byte compiler itself.
;;
-;; So your're probably asking yourself: Isn't this function a
-;; gross hack? And the answer, of course, would be yes.
+;; The function works by scanning the elements in the alist
+;; `read-symbol-positions-list' for the next match for the symbol
+;; after the current value of `byte-compile-last-position', setting
+;; that variable to the match's character position, then deleting the
+;; matching element from the list. Thus the new value for
+;; `byte-compile-last-position' is later than the old value unless,
+;; perhaps, ALLOW-PREVIOUS is non-nil.
+;;
+;; So your're probably asking yourself: Isn't this function a gross
+;; hack? And the answer, of course, would be yes.
(defun byte-compile-set-symbol-position (sym &optional allow-previous)
(when byte-compile-read-position
- (let (last entry)
+ (let ((last byte-compile-last-position)
+ entry)
(while (progn
- (setq last byte-compile-last-position
- entry (assq sym read-symbol-positions-list))
+ (setq entry (assq sym read-symbol-positions-list))
(when entry
(setq byte-compile-last-position
(+ byte-compile-read-position (cdr entry))
read-symbol-positions-list
(byte-compile-delete-first
entry read-symbol-positions-list)))
- (or (and allow-previous
- (not (= last byte-compile-last-position)))
- (> last byte-compile-last-position)))))))
+ (and entry
+ (or (and allow-previous
+ (not (= last byte-compile-last-position)))
+ (> last byte-compile-last-position))))))))
(defvar byte-compile-last-warned-form nil)
(defvar byte-compile-last-logged-file nil)
@@ -1284,6 +1287,7 @@ when printing the error message."
(t (format "%d-%d" (car signature) (cdr signature)))))
(defun byte-compile-function-warn (f nargs def)
+ (byte-compile-set-symbol-position f)
(when (get f 'byte-obsolete-info)
(byte-compile-warn-obsolete f))