diff options
| author | Alan Mackenzie | 2022-01-22 09:59:05 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2022-01-22 09:59:05 +0000 |
| commit | bdd9b5b8a0d37dd09ee530c1dab3a44bee09e0f8 (patch) | |
| tree | 2f8c46b47f3cb6f742a186e50d069b5c1d8fecfa | |
| parent | 3023e7ca3d911d431738551753e4cfb8e3e01ec5 (diff) | |
| download | emacs-bdd9b5b8a0d37dd09ee530c1dab3a44bee09e0f8.tar.gz emacs-bdd9b5b8a0d37dd09ee530c1dab3a44bee09e0f8.zip | |
Miscellaneous amendments to the scratch/correct-warning-pos branch
* lisp/cedet/semantic/fw.el (semantic-alias-obsolete)
(semantic-varalias-obsolete): Replace calls to byte-compile-warn with calls to
byte-compile-warn-x (when it exists).
* lisp/emacs-lisp/bytecomp.el (byte-compile-log-warning-function)
(byte-compile--log-warning-for-byte-compile): Make the POSITION parameter no
longer &optional (for the benefit of flymake on *.el).
(byte-compile-log-warning): Replace a nil POSITION argument with an actual
position.
(byte-compile-file-form-require): Push the required symbol onto
byte-compile-form-stack, for the benefit of `do-after-load-evaluation'.
* lisp/keymap.el (define-keymap--compile): Replace four calls to
byte-compile-warn with byte-compile-warn-x.
* doc/lispref/elisp.texi (master menu): Add entries for Shorthands and Symbols
with position.
* doc/lispref/streams.texi (Input Functions): Document
read-positioning-symbols.
* doc/lispref/symbols.texi (Symbols): Add new menu entry.
(Symbols with Position): New @section.
| -rw-r--r-- | doc/lispref/elisp.texi | 3 | ||||
| -rw-r--r-- | doc/lispref/streams.texi | 10 | ||||
| -rw-r--r-- | doc/lispref/symbols.texi | 82 | ||||
| -rw-r--r-- | lisp/cedet/semantic/fw.el | 32 | ||||
| -rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 18 | ||||
| -rw-r--r-- | lisp/keymap.el | 11 |
6 files changed, 126 insertions, 30 deletions
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index 3254a4dba81..91926e05794 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -448,6 +448,9 @@ Symbols | |||
| 448 | * Creating Symbols:: How symbols are kept unique. | 448 | * Creating Symbols:: How symbols are kept unique. |
| 449 | * Symbol Properties:: Each symbol has a property list | 449 | * Symbol Properties:: Each symbol has a property list |
| 450 | for recording miscellaneous information. | 450 | for recording miscellaneous information. |
| 451 | * Shorthands:: Properly organize your symbol names but | ||
| 452 | type less of them. | ||
| 453 | * Symbols with Position:: Symbol variants containing integer positions | ||
| 451 | 454 | ||
| 452 | Symbol Properties | 455 | Symbol Properties |
| 453 | 456 | ||
diff --git a/doc/lispref/streams.texi b/doc/lispref/streams.texi index c6b3397ae11..4cc8b89234d 100644 --- a/doc/lispref/streams.texi +++ b/doc/lispref/streams.texi | |||
| @@ -326,6 +326,16 @@ For example: | |||
| 326 | @end group | 326 | @end group |
| 327 | @end example | 327 | @end example |
| 328 | @end defun | 328 | @end defun |
| 329 | @end defun | ||
| 330 | |||
| 331 | @defun read-positioning-symbols &optional stream | ||
| 332 | This function reads one textual expression from @var{stream}, like | ||
| 333 | @code{read} does, but additionally positions the read symbols to the | ||
| 334 | positions in @var{stream} where they occurred. Only the symbol | ||
| 335 | @code{nil} is not positioned, this for efficiency reasons. | ||
| 336 | @xref{Symbols with Position}. This function is used by the byte | ||
| 337 | compiler. | ||
| 338 | @end defun | ||
| 329 | 339 | ||
| 330 | @defvar standard-input | 340 | @defvar standard-input |
| 331 | This variable holds the default input stream---the stream that | 341 | This variable holds the default input stream---the stream that |
diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi index a951e9be8ae..f3a9e586e36 100644 --- a/doc/lispref/symbols.texi +++ b/doc/lispref/symbols.texi | |||
| @@ -23,15 +23,15 @@ otherwise. | |||
| 23 | @end defun | 23 | @end defun |
| 24 | 24 | ||
| 25 | @menu | 25 | @menu |
| 26 | * Symbol Components:: Symbols have names, values, function definitions | 26 | * Symbol Components:: Symbols have names, values, function definitions |
| 27 | and property lists. | 27 | and property lists. |
| 28 | * Definitions:: A definition says how a symbol will be used. | 28 | * Definitions:: A definition says how a symbol will be used. |
| 29 | * Creating Symbols:: How symbols are kept unique. | 29 | * Creating Symbols:: How symbols are kept unique. |
| 30 | * Symbol Properties:: Each symbol has a property list | 30 | * Symbol Properties:: Each symbol has a property list |
| 31 | for recording miscellaneous information. | 31 | for recording miscellaneous information. |
| 32 | * Shorthands:: Properly organize your symbol names but | 32 | * Shorthands:: Properly organize your symbol names but |
| 33 | type less of them. | 33 | type less of them. |
| 34 | 34 | * Symbols with Position:: Symbol variants containing integer positions | |
| 35 | @end menu | 35 | @end menu |
| 36 | 36 | ||
| 37 | @node Symbol Components | 37 | @node Symbol Components |
| @@ -432,8 +432,8 @@ symbol's property list cell (@pxref{Symbol Components}), in the form | |||
| 432 | of a property list (@pxref{Property Lists}). | 432 | of a property list (@pxref{Property Lists}). |
| 433 | 433 | ||
| 434 | @menu | 434 | @menu |
| 435 | * Symbol Plists:: Accessing symbol properties. | 435 | * Symbol Plists:: Accessing symbol properties. |
| 436 | * Standard Properties:: Standard meanings of symbol properties. | 436 | * Standard Properties:: Standard meanings of symbol properties. |
| 437 | @end menu | 437 | @end menu |
| 438 | 438 | ||
| 439 | @node Symbol Plists | 439 | @node Symbol Plists |
| @@ -751,3 +751,69 @@ those names. | |||
| 751 | @item | 751 | @item |
| 752 | Symbol forms whose names start with @samp{#_} are not transformed. | 752 | Symbol forms whose names start with @samp{#_} are not transformed. |
| 753 | @end itemize | 753 | @end itemize |
| 754 | |||
| 755 | @node Symbols with Position | ||
| 756 | @section Symbols with Position | ||
| 757 | @cindex symbols with position | ||
| 758 | |||
| 759 | A @dfn{symbol with position} is a symbol, the @dfn{bare symbol}, | ||
| 760 | together with an unsigned integer called the @dfn{position}. These | ||
| 761 | objects are intended for use by the byte compiler, which records in | ||
| 762 | them the position of each symbol occurrence and uses those positions | ||
| 763 | in warning and error messages. | ||
| 764 | |||
| 765 | The printed representation of a symbol with position uses the hash | ||
| 766 | notation outlined in @ref{Printed Representation}. It looks like | ||
| 767 | @samp{#<symbol foo at 12345>}. It has no read syntax. You can cause | ||
| 768 | just the bare symbol to be printed by binding the variable | ||
| 769 | @code{print-symbols-bare} to non-@code{nil} around the print | ||
| 770 | operation. The byte compiler does this before writing its output to | ||
| 771 | the compiled Lisp file. | ||
| 772 | |||
| 773 | For most purposes, when the flag variable | ||
| 774 | @code{symbols-with-pos-enabled} is non-@code{nil}, symbols with | ||
| 775 | positions behave just as bare symbols do. For example, @samp{(eq | ||
| 776 | #<symbol foo at 12345> foo)} has a value @code{t} when that variable | ||
| 777 | is set (but nil when it isn't set). Most of the time in Emacs this | ||
| 778 | variable is @code{nil}, but the byte compiler binds it to @code{t} | ||
| 779 | when it runs. | ||
| 780 | |||
| 781 | Typically, symbols with position are created by the byte compiler | ||
| 782 | calling the reader function @code{read-positioning-symbols} | ||
| 783 | (@pxref{Input Functions}). One can also be created with the function | ||
| 784 | @code{position-symbol}. | ||
| 785 | |||
| 786 | @defvar symbols-with-pos-enabled | ||
| 787 | When this variable is non-@code{nil}, symbols with position behave | ||
| 788 | like the contained bare symbol. Emacs runs a little more slowly in | ||
| 789 | this case. | ||
| 790 | @end defvar | ||
| 791 | |||
| 792 | @defvar print-symbols-bare | ||
| 793 | When bound to non-nil, the Lisp printer prints only the bare symbol of | ||
| 794 | a symbol with position, ignoring the position. | ||
| 795 | @end defvar | ||
| 796 | |||
| 797 | @defun symbol-with-pos-p symbol. | ||
| 798 | This function returns @code{t} if @var{symbol} is a symbol with | ||
| 799 | position, @code{nil} otherwise. | ||
| 800 | @end defun | ||
| 801 | |||
| 802 | @defun bare-symbol symbol | ||
| 803 | This function returns the bare symbol contained in @var{symbol}, or | ||
| 804 | @var{symbol} itself if it is already a bare symbol. For any other | ||
| 805 | type of object, it throws an error. | ||
| 806 | @end defun | ||
| 807 | |||
| 808 | @defun symbol-with-pos-pos symbol | ||
| 809 | This function returns the position, a number, from a symbol with | ||
| 810 | position. For any other type of object, it throws an error. | ||
| 811 | @end defun | ||
| 812 | |||
| 813 | @defun position-symbol sym pos | ||
| 814 | Make a new symbol with position. @var{sym} is either a bare symbol or | ||
| 815 | a symbol with position, and supplies the symbol part of the new | ||
| 816 | object. @var{pos} is either an integer which becomes the number part | ||
| 817 | of the new object, or a symbol with position whose position is used. | ||
| 818 | Emacs throws an error if either argument is invalid. | ||
| 819 | @end defun | ||
diff --git a/lisp/cedet/semantic/fw.el b/lisp/cedet/semantic/fw.el index fd61751cb50..b7c3461a4d7 100644 --- a/lisp/cedet/semantic/fw.el +++ b/lisp/cedet/semantic/fw.el | |||
| @@ -191,12 +191,20 @@ will throw a warning when it encounters this symbol." | |||
| 191 | (not (string-match "cedet" (macroexp-file-name))) | 191 | (not (string-match "cedet" (macroexp-file-name))) |
| 192 | ) | 192 | ) |
| 193 | (make-obsolete-overload oldfnalias newfn when) | 193 | (make-obsolete-overload oldfnalias newfn when) |
| 194 | (byte-compile-warn | 194 | (if (fboundp 'byte-compile-warn-x) |
| 195 | "%s: `%s' obsoletes overload `%s'" | 195 | (byte-compile-warn-x |
| 196 | (macroexp-file-name) | 196 | newfn |
| 197 | newfn | 197 | "%s: `%s' obsoletes overload `%s'" |
| 198 | (with-suppressed-warnings ((obsolete semantic-overload-symbol-from-function)) | 198 | (macroexp-file-name) |
| 199 | (semantic-overload-symbol-from-function oldfnalias))))) | 199 | newfn |
| 200 | (with-suppressed-warnings ((obsolete semantic-overload-symbol-from-function)) | ||
| 201 | (semantic-overload-symbol-from-function oldfnalias))) | ||
| 202 | (byte-compile-warn | ||
| 203 | "%s: `%s' obsoletes overload `%s'" | ||
| 204 | (macroexp-file-name) | ||
| 205 | newfn | ||
| 206 | (with-suppressed-warnings ((obsolete semantic-overload-symbol-from-function)) | ||
| 207 | (semantic-overload-symbol-from-function oldfnalias)))))) | ||
| 200 | 208 | ||
| 201 | (defun semantic-varalias-obsolete (oldvaralias newvar when) | 209 | (defun semantic-varalias-obsolete (oldvaralias newvar when) |
| 202 | "Make OLDVARALIAS an alias for variable NEWVAR. | 210 | "Make OLDVARALIAS an alias for variable NEWVAR. |
| @@ -209,10 +217,14 @@ will throw a warning when it encounters this symbol." | |||
| 209 | (error | 217 | (error |
| 210 | ;; Only throw this warning when byte compiling things. | 218 | ;; Only throw this warning when byte compiling things. |
| 211 | (when (macroexp-compiling-p) | 219 | (when (macroexp-compiling-p) |
| 212 | (byte-compile-warn | 220 | (if (fboundp 'byte-compile-warn-x) |
| 213 | "variable `%s' obsoletes, but isn't alias of `%s'" | 221 | (byte-compile-warn-x |
| 214 | newvar oldvaralias) | 222 | newvar |
| 215 | )))) | 223 | "variable `%s' obsoletes, but isn't alias of `%s'" |
| 224 | newvar oldvaralias) | ||
| 225 | (byte-compile-warn | ||
| 226 | "variable `%s' obsoletes, but isn't alias of `%s'" | ||
| 227 | newvar oldvaralias)))))) | ||
| 216 | 228 | ||
| 217 | ;;; Help debugging | 229 | ;;; Help debugging |
| 218 | ;; | 230 | ;; |
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 41d2126dbcf..587819f36ed 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el | |||
| @@ -1309,20 +1309,21 @@ Called with arguments (STRING POSITION FILL LEVEL). STRING is a | |||
| 1309 | message describing the problem. POSITION is a buffer position | 1309 | message describing the problem. POSITION is a buffer position |
| 1310 | where the problem was detected. FILL is a prefix as in | 1310 | where the problem was detected. FILL is a prefix as in |
| 1311 | `warning-fill-prefix'. LEVEL is the level of the | 1311 | `warning-fill-prefix'. LEVEL is the level of the |
| 1312 | problem (`:warning' or `:error'). POSITION, FILL and LEVEL may be | 1312 | problem (`:warning' or `:error'). FILL and LEVEL may be nil.") |
| 1313 | nil.") | ||
| 1314 | 1313 | ||
| 1315 | (defun byte-compile-log-warning (string &optional fill level) | 1314 | (defun byte-compile-log-warning (string &optional fill level) |
| 1316 | "Log a byte-compilation warning. | 1315 | "Log a byte-compilation warning. |
| 1317 | STRING, FILL and LEVEL are as described in | 1316 | STRING, FILL and LEVEL are as described in |
| 1318 | `byte-compile-log-warning-function', which see." | 1317 | `byte-compile-log-warning-function', which see." |
| 1319 | (funcall byte-compile-log-warning-function | 1318 | (funcall byte-compile-log-warning-function |
| 1320 | string nil | 1319 | string |
| 1320 | (or (byte-compile--warning-source-offset) | ||
| 1321 | (point)) | ||
| 1321 | fill | 1322 | fill |
| 1322 | level)) | 1323 | level)) |
| 1323 | 1324 | ||
| 1324 | (defun byte-compile--log-warning-for-byte-compile (string &optional | 1325 | (defun byte-compile--log-warning-for-byte-compile (string _position |
| 1325 | _position | 1326 | &optional |
| 1326 | fill | 1327 | fill |
| 1327 | level) | 1328 | level) |
| 1328 | "Log a message STRING in `byte-compile-log-buffer'. | 1329 | "Log a message STRING in `byte-compile-log-buffer'. |
| @@ -2653,8 +2654,11 @@ list that represents a doc string reference. | |||
| 2653 | 2654 | ||
| 2654 | (put 'require 'byte-hunk-handler 'byte-compile-file-form-require) | 2655 | (put 'require 'byte-hunk-handler 'byte-compile-file-form-require) |
| 2655 | (defun byte-compile-file-form-require (form) | 2656 | (defun byte-compile-file-form-require (form) |
| 2656 | (let ((args (mapcar 'eval (cdr form))) | 2657 | (let* ((args (mapcar 'eval (cdr form))) |
| 2657 | hist-new prov-cons) | 2658 | ;; The following is for the byte-compile-warn in |
| 2659 | ;; `do-after-load-evaluation' (in subr.el). | ||
| 2660 | (byte-compile-form-stack (cons (car args) byte-compile-form-stack)) | ||
| 2661 | hist-new prov-cons) | ||
| 2658 | (apply 'require args) | 2662 | (apply 'require args) |
| 2659 | 2663 | ||
| 2660 | ;; Record the functions defined by the require in `byte-compile-new-defuns'. | 2664 | ;; Record the functions defined by the require in `byte-compile-new-defuns'. |
diff --git a/lisp/keymap.el b/lisp/keymap.el index 3e9189fba45..ce566fd8afc 100644 --- a/lisp/keymap.el +++ b/lisp/keymap.el | |||
| @@ -462,18 +462,19 @@ If MESSAGE (and interactively), message the result." | |||
| 462 | (keywordp (car args)) | 462 | (keywordp (car args)) |
| 463 | (not (eq (car args) :menu))) | 463 | (not (eq (car args) :menu))) |
| 464 | (unless (memq (car args) '(:full :keymap :parent :suppress :name :prefix)) | 464 | (unless (memq (car args) '(:full :keymap :parent :suppress :name :prefix)) |
| 465 | (byte-compile-warn "Invalid keyword: %s" (car args))) | 465 | (byte-compile-warn-x (car args) "Invalid keyword: %s" (car args))) |
| 466 | (setq args (cdr args)) | 466 | (setq args (cdr args)) |
| 467 | (when (null args) | 467 | (when (null args) |
| 468 | (byte-compile-warn "Uneven number of keywords in %S" form)) | 468 | (byte-compile-warn-x form "Uneven number of keywords in %S" form)) |
| 469 | (setq args (cdr args))) | 469 | (setq args (cdr args))) |
| 470 | ;; Bindings. | 470 | ;; Bindings. |
| 471 | (while args | 471 | (while args |
| 472 | (let ((key (pop args))) | 472 | (let* ((wargs args) |
| 473 | (key (pop args))) | ||
| 473 | (when (and (stringp key) (not (key-valid-p key))) | 474 | (when (and (stringp key) (not (key-valid-p key))) |
| 474 | (byte-compile-warn "Invalid `kbd' syntax: %S" key))) | 475 | (byte-compile-warn-x wargs "Invalid `kbd' syntax: %S" key))) |
| 475 | (when (null args) | 476 | (when (null args) |
| 476 | (byte-compile-warn "Uneven number of key bindings in %S" form)) | 477 | (byte-compile-warn-x form "Uneven number of key bindings in %S" form)) |
| 477 | (setq args (cdr args))) | 478 | (setq args (cdr args))) |
| 478 | form) | 479 | form) |
| 479 | 480 | ||