commit e021c2dc2279e0fd3a5331f9ea661e4d39c2e840 (HEAD, refs/remotes/origin/master) Author: Paul Eggert Date: Sat May 23 12:55:13 2020 -0700 Port etags FALLTHROUGH to C2X Problem reported by Ashish SHUKLA in: https://lists.gnu.org/r/emacs-devel/2020-05/msg03013.html * lib-src/etags.c (C_entries): Move label so that FALLTHROUGH precedes a case label, as draft C2X specifies. diff --git a/lib-src/etags.c b/lib-src/etags.c index eee2c59626..4672e3491d 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -4197,9 +4197,9 @@ C_entries (int c_ext, FILE *inf) break; } FALLTHROUGH; - resetfvdef: case '#': case '~': case '&': case '%': case '/': case '|': case '^': case '!': case '.': case '?': + resetfvdef: if (definedef != dnone) break; /* These surely cannot follow a function tag in C. */ commit 9e977c497257ff13bfb2579f8a14ca9b43791115 Author: Paul Eggert Date: Sat May 23 10:38:53 2020 -0700 Restore check for Emacs 20.2 bytecodes * src/eval.c (Ffetch_bytecode): Check for multibyte bytecodes here too. Problem reported by Stefan Monnier in: https://lists.gnu.org/r/emacs-devel/2020-05/msg02876.html diff --git a/src/eval.c b/src/eval.c index be2af2d041..959adea646 100644 --- a/src/eval.c +++ b/src/eval.c @@ -3202,7 +3202,19 @@ DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode, else error ("Invalid byte code"); } - ASET (object, COMPILED_BYTECODE, XCAR (tem)); + + Lisp_Object bytecode = XCAR (tem); + if (STRING_MULTIBYTE (bytecode)) + { + /* BYTECODE must have been produced by Emacs 20.2 or earlier + because it produced a raw 8-bit string for byte-code and now + such a byte-code string is loaded as multibyte with raw 8-bit + characters converted to multibyte form. Convert them back to + the original unibyte form. */ + bytecode = Fstring_as_unibyte (bytecode); + } + + ASET (object, COMPILED_BYTECODE, bytecode); ASET (object, COMPILED_CONSTANTS, XCDR (tem)); } } commit d436e4840a2a99e9717497a7d7dc7a36dbd0ecc9 Merge: 294495de8e d6a0b66a0c Author: Glenn Morris Date: Sat May 23 07:50:30 2020 -0700 Merge from origin/emacs-27 d6a0b66a0c (origin/emacs-27) * lisp/subr.el (save-match-data): Clarif... 1a6d59eeba Improve the documentation of setting up fontsets c7737d40f2 ; * etc/TODO (Ligatures): Update the entry based on recent... fb2e34cd21 ; * etc/TODO (Ligatures): Update the entry based on recent... 13b6dfd4f7 * doc/emacs/killing.texi (Rectangles): Improve indexing. a10254dd46 Fix accessing files on networked drives on MS-Windows commit 294495de8e93c094aa25df55905dac61975643b9 Merge: ce70cfb1b1 c0aa2f2abf Author: Glenn Morris Date: Sat May 23 07:50:30 2020 -0700 ; Merge from origin/emacs-27 The following commits were skipped: c0aa2f2abf CC Mode: Fix bug #39972, by fixing c-display-defun-name fo... 62a5e890d7 Redo RCS Id for pdumper commit ce70cfb1b184a57b16cc5a259ee43b317c4b76c0 Merge: bd5c3d10b1 8cc453d788 Author: Glenn Morris Date: Sat May 23 07:50:30 2020 -0700 Merge from origin/emacs-27 8cc453d788 Second attempt at improving indexing in control.texi commit bd5c3d10b140c0f0ee28659d4349c759196240a8 Merge: fabcc1ee13 0eeeedf195 Author: Glenn Morris Date: Sat May 23 07:50:30 2020 -0700 ; Merge from origin/emacs-27 The following commit was skipped: 0eeeedf195 ; * etc/PROBLEMS: Add note about color list issues on macOS. commit fabcc1ee13f82297d0f5e41f58fb1774840ebd45 Merge: f8581bcf6a 4b9fbdb5a7 Author: Glenn Morris Date: Sat May 23 07:50:29 2020 -0700 Merge from origin/emacs-27 4b9fbdb5a7 ; Update TODO item about ligature support 03d44acfdd * doc/lispref/control.texi (Processing of Errors): Improve... b48ab743a8 Minor fixups for mutability doc 6ac2326e5b Don’t use “constant” for values you shouldn’t change commit d6a0b66a0cf44389c7474a60dd23cbf666e78537 (refs/remotes/origin/emacs-27) Author: Stefan Monnier Date: Sat May 23 09:33:41 2020 -0400 * lisp/subr.el (save-match-data): Clarify use in docstring diff --git a/lisp/subr.el b/lisp/subr.el index 33194e4ffa..2b3231b879 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4088,7 +4088,11 @@ MODES is as for `set-default-file-modes'." ;; now, but it generates slower code. (defmacro save-match-data (&rest body) "Execute the BODY forms, restoring the global value of the match data. -The value returned is the value of the last form in BODY." +The value returned is the value of the last form in BODY. +NOTE: The convention in Elisp is that any function, except for a few +exceptions like car/assoc/+/goto-char, can clobber the match data, +so `save-match-data' should normally be used to save *your* match data +rather than your caller's match data." ;; It is better not to use backquote here, ;; because that makes a bootstrapping problem ;; if you need to recompile all the Lisp files using interpreted code. commit 1a6d59eebaff919b38792450edfae7912f6639b3 Author: Eli Zaretskii Date: Sat May 23 15:14:27 2020 +0300 Improve the documentation of setting up fontsets * doc/lispref/display.texi (Fontsets): Improve the accuracy of a cross-reference to "Character Properties". * doc/emacs/mule.texi (Fontsets, Modifying Fontsets): Improve the documentation of fontsets and how to modify them. diff --git a/doc/emacs/mule.texi b/doc/emacs/mule.texi index e3fe20c76f..373c7b5581 100644 --- a/doc/emacs/mule.texi +++ b/doc/emacs/mule.texi @@ -1326,16 +1326,17 @@ stored in the system and the available font names are defined by the system, fontsets are defined within Emacs itself. Once you have defined a fontset, you can use it within Emacs by specifying its name, anywhere that you could use a single font. Of course, Emacs fontsets -can use only the fonts that the system supports. If some characters +can use only the fonts that your system supports. If some characters appear on the screen as empty boxes or hex codes, this means that the fontset in use for them has no font for those characters. In this case, or if the characters are shown, but not as well as you would -like, you may need to install extra fonts. Your operating system may -have optional fonts that you can install; or you can install the GNU -Intlfonts package, which includes fonts for most supported -scripts.@footnote{If you run Emacs on X, you may need to inform the X -server about the location of the newly installed fonts with commands -such as: +like, you may need to install extra fonts or modify the fontset to use +specific fonts already installed on your system (see below). Your +operating system may have optional fonts that you can install; or you +can install the GNU Intlfonts package, which includes fonts for most +supported scripts.@footnote{If you run Emacs on X, you may need to +inform the X server about the location of the newly installed fonts +with commands such as: @c FIXME? I feel like this may be out of date. @c E.g., the intlfonts tarfile is ~ 10 years old. @@ -1376,14 +1377,20 @@ explicitly requested, despite its name. @w{@kbd{M-x describe-fontset}} command. It prompts for a fontset name, defaulting to the one used by the current frame, and then displays all the subranges of characters and the fonts assigned to -them in that fontset. +them in that fontset. To see which fonts Emacs is using in a session +started without a specific fontset (which is what happens normally), +type @kbd{fontset-default @key{RET}} at the prompt, or just +@kbd{@key{RET}} to describe the fontset used by the current frame. A fontset does not necessarily specify a font for every character code. If a fontset specifies no font for a certain character, or if it specifies a font that does not exist on your system, then it cannot display that character properly. It will display that character as a -hex code or thin space or an empty box instead. (@xref{Text Display, , -glyphless characters}, for details.) +hex code or thin space or an empty box instead. (@xref{Text Display, +, glyphless characters}, for details.) Or a fontset might specify a +font for some range of characters, but you may not like their visual +appearance. If this happens, you may wish to modify your fontset; see +@ref{Modifying Fontsets}, for how to do that. @node Defining Fontsets @section Defining Fontsets @@ -1542,10 +1549,10 @@ call this function explicitly to create a fontset. Fontsets do not always have to be created from scratch. If only minor changes are required it may be easier to modify an existing -fontset. Modifying @samp{fontset-default} will also affect other -fontsets that use it as a fallback, so can be an effective way of -fixing problems with the fonts that Emacs chooses for a particular -script. +fontset, usually @samp{fontset-default}. Modifying +@samp{fontset-default} will also affect other fontsets that use it as +a fallback, so can be an effective way of fixing problems with the +fonts that Emacs chooses for a particular script. Fontsets can be modified using the function @code{set-fontset-font}, specifying a character, a charset, a script, or a range of characters @@ -1553,26 +1560,61 @@ to modify the font for, and a font specification for the font to be used. Some examples are: @example -;; Use Liberation Mono for latin-3 charset. -(set-fontset-font "fontset-default" 'iso-8859-3 - "Liberation Mono") - ;; Prefer a big5 font for han characters. (set-fontset-font "fontset-default" 'han (font-spec :registry "big5") nil 'prepend) +;; Use MyPrivateFont for the Unicode private use area. +(set-fontset-font "fontset-default" '(#xe000 . #xf8ff) + "MyPrivateFont") + +;; Use Liberation Mono for latin-3 charset. +(set-fontset-font "fontset-default" 'iso-8859-3 + "Liberation Mono") + ;; Use DejaVu Sans Mono as a fallback in fontset-startup ;; before resorting to fontset-default. (set-fontset-font "fontset-startup" nil "DejaVu Sans Mono" nil 'append) +@end example -;; Use MyPrivateFont for the Unicode private use area. -(set-fontset-font "fontset-default" '(#xe000 . #xf8ff) - "MyPrivateFont") +@noindent +@xref{Fontsets, , , elisp, GNU Emacs Lisp Reference Manual}, for more +details about using the @code{set-fontset-font} function. + +@cindex script of a character +@cindex codepoint of a character +If you don't know the character's codepoint or the script to which it +belongs, you can ask Emacs. With point at the character, type +@w{@kbd{C-u C-x =}} (@code{what-cursor-position}), and this +information, together with much more, will be displayed in the +@file{*Help*} buffer that Emacs pops up. @xref{Position Info}. For +example, Japanese characters belong to the @samp{kana} script, but +Japanese text also mixes them with Chinese characters so the following +uses the @samp{han} script to set up Emacs to use the @samp{Kochi +Gothic} font for Japanese text: +@example +(set-fontset-font "fontset-default" 'han "Kochi Gothic") @end example +@noindent +@cindex CKJ characters +(For convenience, the @samp{han} script in Emacs is set up to support +all of the Chinese, Japanese, and Korean, a.k.a.@: @acronym{CJK}, +characters, not just Chinese characters.) + +@vindex script-representative-chars +For the list of known scripts, see the variable +@code{script-representative-chars}. + +Fontset settings like those above only affect characters that the +default font doesn't support, so if the @samp{Kochi Gothic} font +covers Latin characters, it will not be used for displaying Latin +scripts, since the default font used by Emacs usually covers Basic +Latin. + @cindex ignore font @cindex fonts, how to ignore @vindex face-ignored-fonts diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index e655f2f0ca..588e2217b9 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -3600,9 +3600,9 @@ characters in the range @var{from} and @var{to} (inclusive). @var{character} may be a charset (@pxref{Character Sets}). In that case, use @var{font-spec} for all the characters in the charset. -@var{character} may be a script name (@pxref{Character Properties}). -In that case, use @var{font-spec} for all the characters belonging to -the script. +@var{character} may be a script name (@pxref{Character Properties, +char-script-table}). In that case, use @var{font-spec} for all the +characters belonging to the script. @var{character} may be @code{nil}, which means to use @var{font-spec} for any character which no font-spec is specified. commit f8581bcf6a1942ebd331cae20e32945a3a86a3d1 Author: Philipp Stephani Date: Sat May 23 13:56:09 2020 +0200 Reject invalid characters in XML strings (Bug#41094). * lisp/xml.el (xml-escape-string): Search for invalid characters. (xml-invalid-character): New error symbol. * test/lisp/xml-tests.el (xml-print-invalid-cdata): New unit test. * etc/NEWS: Document new behavior. diff --git a/etc/NEWS b/etc/NEWS index 32b59cb76f..efad273da6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -393,6 +393,13 @@ component are now rejected by 'json-read' and friends. This makes them more compliant with the JSON specification and consistent with the native JSON parsing functions. +** xml.el + +*** XML serialization functions now reject invalid characters. +Previously 'xml-print' would produce invalid XML when given a string +with characters that are not valid in XML (see +https://www.w3.org/TR/xml/#charsets). Now it rejects such strings. + * New Modes and Packages in Emacs 28.1 diff --git a/lisp/xml.el b/lisp/xml.el index dc774a202c..767cf04284 100644 --- a/lisp/xml.el +++ b/lisp/xml.el @@ -1023,9 +1023,17 @@ entity references (e.g., replace each & with &). XML character data must not contain & or < characters, nor the > character under some circumstances. The XML spec does not impose restriction on \" or \\=', but we just substitute for these too -\(as is permitted by the spec)." +\(as is permitted by the spec). + +If STRING contains characters that are invalid in XML (as defined +by https://www.w3.org/TR/xml/#charsets), signal an error of type +`xml-invalid-character'." (with-temp-buffer (insert string) + (goto-char (point-min)) + (when (re-search-forward + "[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\U00010000-\U0010FFFF]") + (signal 'xml-invalid-character (list (char-before) (match-beginning 0)))) (dolist (substitution '(("&" . "&") ("<" . "<") (">" . ">") @@ -1036,6 +1044,9 @@ restriction on \" or \\=', but we just substitute for these too (replace-match (cdr substitution) t t nil))) (buffer-string))) +(define-error 'xml-invalid-character "Invalid XML character" + 'wrong-type-argument) + (defun xml-debug-print-internal (xml indent-string) "Outputs the XML tree in the current buffer. The first line is indented with INDENT-STRING." diff --git a/test/lisp/xml-tests.el b/test/lisp/xml-tests.el index 57e685cd34..72c78d00e3 100644 --- a/test/lisp/xml-tests.el +++ b/test/lisp/xml-tests.el @@ -164,6 +164,16 @@ Parser is called with and without 'symbol-qnames argument.") (should (equal (cdr xml-parse-test--namespace-attribute-qnames) (xml-parse-region nil nil nil nil 'symbol-qnames))))) +(ert-deftest xml-print-invalid-cdata () + "Check that Bug#41094 is fixed." + (with-temp-buffer + (should (equal (should-error (xml-print '((foo () "\0"))) + :type 'xml-invalid-character) + '(xml-invalid-character 0 1))) + (should (equal (should-error (xml-print '((foo () "\u00FF \xFF"))) + :type 'xml-invalid-character) + '(xml-invalid-character #x3FFFFF 3))))) + ;; Local Variables: ;; no-byte-compile: t ;; End: commit c7737d40f2ae9f8459508e9d07cd7aa5f1ea78b6 Author: Eli Zaretskii Date: Sat May 23 11:01:09 2020 +0300 ; * etc/TODO (Ligatures): Update the entry based on recent discussions. diff --git a/etc/TODO b/etc/TODO index c11848e0c5..0f908def76 100644 --- a/etc/TODO +++ b/etc/TODO @@ -233,7 +233,7 @@ font glyphs to display that text. However, doing this is impossible with the current design of the Emacs display engine, since it examines buffer text one character at a time, and implements character composition by calls to Lisp, which makes doing this for every -character impractically slow. therefore, the rest of this item +character impractically slow. Therefore, the rest of this item describes a limited form of ligature support which is compatible with the current display engine design and uses automatic compositions.) commit fb2e34cd2155cbaaf945d8cd167b600b55b9edff Author: Eli Zaretskii Date: Sat May 23 10:59:39 2020 +0300 ; * etc/TODO (Ligatures): Update the entry based on recent discussions. diff --git a/etc/TODO b/etc/TODO index f983fa27d3..c11848e0c5 100644 --- a/etc/TODO +++ b/etc/TODO @@ -220,10 +220,23 @@ https://lists.gnu.org/r/emacs-devel/2013-11/msg00515.html width fonts. However, more features are still needed to achieve this. ** Support ligatures out of the box -For the list of typographical ligatures, see +For the list of frequently-used typographical ligatures, see https://en.wikipedia.org/wiki/Orthographic_ligature#Ligatures_in_Unicode_(Latin_alphabets) +(Note that in general, the number of possible ligatures can be much +larger, and there's no way, in principle, to specify the superset of +all the ligatures that could exist. Each font can support different +ligatures. The reliable way of supporting any and all ligatures is to +hand all text to be displayed to the shaping engine and get back the +font glyphs to display that text. However, doing this is impossible +with the current design of the Emacs display engine, since it examines +buffer text one character at a time, and implements character +composition by calls to Lisp, which makes doing this for every +character impractically slow. therefore, the rest of this item +describes a limited form of ligature support which is compatible with +the current display engine design and uses automatic compositions.) + For Text and derived modes, the job is to figure out which ligatures we want to support, how to let the user customize that, and probably define a minor mode for automatic ligation (as some contexts might not @@ -237,12 +250,12 @@ prettify-symbols-mode. We need to figure out which ligatures are needed for each programming language, and provide user options to turn this on and off. -The implementation should use the infrastructure for character -compositions, i.e., we should define appropriate regexp-based rules -for character sequences that need to be composed into ligatures, and -populate composition-function-table with those rules. See -composite.el for examples of this, and also grep lisp/language/*.el -for references to composition-function-table. +The implementation should use the infrastructure for automatic +character compositions, i.e., we should define appropriate +regexp-based rules for character sequences that need to be composed +into ligatures, and populate composition-function-table with those +rules. See composite.el for examples of this, and also grep +lisp/language/*.el for references to composition-function-table. One problem with character compositions that will need to be solved is that composition-function-table, the char-table which holds the @@ -259,7 +272,11 @@ way of preventing the ligation from happening. One possibility is to have a ZWNJ character separate these ASCII characters; another possibility is to introduce a special text property that prevents character composition, and place that property on the relevant parts -of the mode line. +of the mode line. Yet another possibility would be to write a +specialized composition function, which would detect that it is called +on mode-line strings, and return nil to signal that composition is not +possible in this case; then use that function in the rules for +ligatures stored in composition-function-table. The prettify-symbols-mode should be deprecated once ligature support is in place. commit 13b6dfd4f767a6ce2b01a519fe412dbf80f4921e Author: Eli Zaretskii Date: Sat May 23 10:33:35 2020 +0300 * doc/emacs/killing.texi (Rectangles): Improve indexing. diff --git a/doc/emacs/killing.texi b/doc/emacs/killing.texi index 834a5c6159..6b1f35e615 100644 --- a/doc/emacs/killing.texi +++ b/doc/emacs/killing.texi @@ -727,6 +727,8 @@ them. Rectangle commands are useful with text in multicolumn formats, and for changing text into or out of such formats. @cindex mark rectangle +@cindex region-rectangle +@cindex rectangular region To specify a rectangle for a command to work on, set the mark at one corner and point at the opposite corner. The rectangle thus specified is called the @dfn{region-rectangle}. If point and the mark are in commit a10254dd46da920d14dd990714d0f21fd508d07d Author: Eli Zaretskii Date: Sat May 23 08:50:22 2020 +0300 Fix accessing files on networked drives on MS-Windows * src/w32.c (acl_get_file): Set errno to ENOTSUP if get_file_security returns ERROR_NOT_SUPPORTED. (Bug#41463) diff --git a/src/w32.c b/src/w32.c index 62c53fd771..78e75f0937 100644 --- a/src/w32.c +++ b/src/w32.c @@ -6398,7 +6398,15 @@ acl_get_file (const char *fname, acl_type_t type) if (!get_file_security (fname, si, psd, sd_len, &sd_len)) { xfree (psd); - errno = EIO; + err = GetLastError (); + if (err == ERROR_NOT_SUPPORTED) + errno = ENOTSUP; + else if (err == ERROR_FILE_NOT_FOUND + || err == ERROR_PATH_NOT_FOUND + || err == ERROR_INVALID_NAME) + errno = ENOENT; + else + errno = EIO; psd = NULL; } } @@ -6409,6 +6417,8 @@ acl_get_file (const char *fname, acl_type_t type) be encoded in the current ANSI codepage. */ || err == ERROR_INVALID_NAME) errno = ENOENT; + else if (err == ERROR_NOT_SUPPORTED) + errno = ENOTSUP; else errno = EIO; } commit c0aa2f2abf732ddb9d1f393c5989b14e047d63d7 Author: Alan Mackenzie Date: Wed May 20 19:02:26 2020 +0000 CC Mode: Fix bug #39972, by fixing c-display-defun-name for nested defuns * lisp/progmodes/cc-mode.el (c-common-init): Build add-log-current-defun-function out of c-defun-name-and-limits instead of the former c-defun-name. diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index fd7750b0d8..066bec6009 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -770,7 +770,7 @@ compatible with old code; callers should always specify it." (set (make-local-variable 'outline-level) 'c-outline-level) (set (make-local-variable 'add-log-current-defun-function) (lambda () - (or (c-cpp-define-name) (c-defun-name)))) + (or (c-cpp-define-name) (car (c-defun-name-and-limits nil))))) (let ((rfn (assq mode c-require-final-newline))) (when rfn (if (boundp 'mode-require-final-newline) commit 62a5e890d72de11263996b25c1a7256423d22a7b Author: Paul Eggert Date: Mon May 18 15:19:49 2020 -0700 Redo RCS Id for pdumper * lisp/version.el: Don’t put an RCS Id style string into the executable via purecopy, as this does not work with the pdumper. * src/emacs.c (RCS_Id): New constant, for 'ident'. (cherry picked from commit 3d1bcfba5e21b29be8669aa2a8f27b344c9e02fd) diff --git a/lisp/version.el b/lisp/version.el index 012cb2175e..bf666cbff9 100644 --- a/lisp/version.el +++ b/lisp/version.el @@ -163,8 +163,4 @@ correspond to the running Emacs. Optional argument DIR is a directory to use instead of `source-directory'." (emacs-repository-branch-git (or dir source-directory))) -;; We put version info into the executable in the form that `ident' uses. -(purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version)) - " $\n")) - ;;; version.el ends here diff --git a/src/emacs.c b/src/emacs.c index c5a760d29f..db3e92a477 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -124,6 +124,11 @@ static const char emacs_version[] = PACKAGE_VERSION; static const char emacs_copyright[] = COPYRIGHT; static const char emacs_bugreport[] = PACKAGE_BUGREPORT; +/* Put version info into the executable in the form that 'ident' uses. */ +char const EXTERNALLY_VISIBLE RCS_Id[] + = "$Id" ": GNU Emacs " PACKAGE_VERSION + " (" EMACS_CONFIGURATION " " EMACS_CONFIG_FEATURES ") $"; + /* Empty lisp strings. To avoid having to build any others. */ Lisp_Object empty_unibyte_string, empty_multibyte_string; commit 8cc453d788883bccc2d86d5bc89e644ecd48eb9a Author: Stefan Kangas Date: Wed May 20 00:43:40 2020 +0200 Second attempt at improving indexing in control.texi * doc/lispref/control.texi (Processing of Errors): Improve indexing by adding the word form "handle" in addition to "handling". With thanks to Eli Zaretskii. diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 7755cbb5f2..58f93366fe 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi @@ -1867,7 +1867,6 @@ concept of continuable errors. @node Processing of Errors @subsubsection How Emacs Processes Errors @cindex processing of errors -@cindex handle errors When an error is signaled, @code{signal} searches for an active @dfn{handler} for the error. A handler is a sequence of Lisp @@ -1906,6 +1905,7 @@ variables precisely as they were at the time of the error. @subsubsection Writing Code to Handle Errors @cindex error handler @cindex handling errors +@cindex handle Lisp errors @cindex forms for handling errors The usual effect of signaling an error is to terminate the command commit 0eeeedf19574d4370b3bf9e1f751a14e8911f300 Author: Alan Third Date: Wed May 20 21:23:01 2020 +0100 ; * etc/PROBLEMS: Add note about color list issues on macOS. ; Do not merge to master. diff --git a/etc/PROBLEMS b/etc/PROBLEMS index 9e4a631c72..12cfbd0de2 100644 --- a/etc/PROBLEMS +++ b/etc/PROBLEMS @@ -2647,6 +2647,15 @@ If you do, please send it to bug-gnu-emacs@gnu.org so we can list it here. Libxpm is available for macOS as part of the XQuartz project. +** The color list can become corrupt. + +This can be seen when Emacs is run from the command line and produces +output containing the text: + + non-keyed archive cannot be decoded by NSKeyedUnarchiver + +The solution is to delete '$HOME/Library/Colors/Emacs.clr'. + * Build-time problems commit 4b9fbdb5a713745dfdb13042e33ba2345e6860e1 Author: Eli Zaretskii Date: Tue May 19 18:46:27 2020 +0300 ; Update TODO item about ligature support * etc/TODO: Add the todo item for moving cursor "inside" a ligature. diff --git a/etc/TODO b/etc/TODO index 20262a77e9..f983fa27d3 100644 --- a/etc/TODO +++ b/etc/TODO @@ -264,6 +264,37 @@ of the mode line. The prettify-symbols-mode should be deprecated once ligature support is in place. +A related, but somewhat independent, feature is being able to move the +cursor "into a ligature", whereby cursor motion commands shows some +pseudo-cursor on some part of a ligature. For example, if "ffi" is +displayed as a ligature, then moving by one buffer position should +show the middle part of the ligature's glyph similar to the cursor +display: some special background and perhaps also a special +foreground. There are two possible ways of figuring out the offset at +which to display the pseudo-cursor: + + . Arbitrarily divide the ligature's glyph width W into N parts, + where N is the number of codepoints composed into the ligature, then + move that pseudo-cursor by W/N pixels each time a cursor-motion + command is invoked; + . Use the font information. For example, HarfBuzz has the + hb_ot_layout_get_ligature_carets API for that purpose. However, + it could be that few fonts actually have that information recorded + in them, in which case the previous heuristics will be needed as + fallback. + +One subtle issue needs to be resolved to have this feature of +"sub-glyph" cursor movement inside composed characters. The way Emacs +currently displays the default block cursor is by simply redrawing the +glyph at point in reverse video. So Emacs currently doesn't have a +way of displaying a cursor that "covers" only part of a glyph. To +make this happen, the display code will probably need to be changed to +draw the cursor as part of drawing the foreground and/or background of +the corresponding glyph, which is against the current flow of the +display code: it generally first completely draws the background and +foreground of the entire text that needs to be redrawn, and only then +draws the cursor where it should be placed. + ** Support for Stylistic Sets This will allow using "alternate glyphs" supported by modern fonts. For an overview of this feature, see commit 03d44acfdda30cf355736de7442cdf2f1a1ba97e Author: Stefan Kangas Date: Tue May 19 02:33:57 2020 +0200 * doc/lispref/control.texi (Processing of Errors): Improve indexing. diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index c601e3af9b..7755cbb5f2 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi @@ -1867,6 +1867,7 @@ concept of continuable errors. @node Processing of Errors @subsubsection How Emacs Processes Errors @cindex processing of errors +@cindex handle errors When an error is signaled, @code{signal} searches for an active @dfn{handler} for the error. A handler is a sequence of Lisp commit b48ab743a861b8041518ce7459bde51c3dd02ee0 Author: Paul Eggert Date: Sat May 16 18:16:23 2020 -0700 Minor fixups for mutability doc * doc/lispref/objects.texi (Mutability): Minor fixups in response to a comment by Dmitry Gutov (Bug#40671#477). diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index 136213ad66..5c5f89eb43 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi @@ -2381,7 +2381,7 @@ that for two strings to be equal, they have the same text properties. Some Lisp objects should never change. For example, the Lisp expression @code{"aaa"} yields a string, but you should not change -its contents. Indeed, some objects cannot be changed; for example, +its contents. And some objects cannot be changed; for example, although you can create a new number by calculating one, Lisp provides no operation to change the value of an existing number. @@ -2393,11 +2393,10 @@ point to somewhere else. Although numbers never change and all markers are mutable, some types have members some of which are mutable and others not. These types include conses, vectors, and strings. For example, -although @code{"aaa"} yields a string that should not be changed, -@code{(make-string 3 ?a)} yields a mutable string that can be -changed via later calls to @code{aset}. Another example: -@code{(symbol-name 'cons)} yields a string @code{"cons"} that should -not be changed. +although @code{"cons"} and @code{(symbol-name 'cons)} both yield +strings that should not be changed, @code{(copy-sequence "cons")} and +@code{(make-string 3 ?a)} both yield mutable strings that can be +changed via later calls to @code{aset}. A mutable object stops being mutable if it is part of an expression that is evaluated. For example: @@ -2419,9 +2418,9 @@ becomes mutable afterwards. changed, the resulting behavior is undefined: the Lisp interpreter might signal an error, or it might crash or behave unpredictably in other ways.@footnote{This is the behavior specified for languages like -Common Lisp and C, and it differs from the behavior of languages like +Common Lisp and C for constants, and this differs from languages like JavaScript and Python where an interpreter is required to signal an -error if a program attempts to change a constant. Ideally the Emacs +error if a program attempts to change an immutable object. Ideally the Emacs Lisp interpreter will evolve in latter direction.} When similar constants occur as parts of a program, the Lisp commit 6ac2326e5bc4796087910eb429e0cb4384e0e0cf Author: Paul Eggert Date: Sat May 16 17:17:00 2020 -0700 Don’t use “constant” for values you shouldn’t change Inspired by patch proposed by Dmitry Gutov (Bug#40671#393) and by further comments by him and by Michael Heerdegen in the same bug report. * doc/lispintro/emacs-lisp-intro.texi (setcar): Don’t push mutability here. * doc/lispref/eval.texi (Self-Evaluating Forms, Quoting) (Backquote): * doc/lispref/lists.texi (Modifying Lists): * doc/lispref/objects.texi (Lisp Data Types, Mutability): * doc/lispref/sequences.texi (Array Functions, Vectors): * doc/lispref/strings.texi (String Basics, Modifying Strings): Don’t use the word “constant” to describe all values that a program should not change. * doc/lispref/objects.texi (Mutability): Rename from “Constants and Mutability”. All uses changed. In a footnote, contrast the Emacs behavior with that of Common Lisp, Python, etc. for clarity, and say the goal is to be nicer. diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi index ea16d9ef15..46462162ca 100644 --- a/doc/lispintro/emacs-lisp-intro.texi +++ b/doc/lispintro/emacs-lisp-intro.texi @@ -7317,8 +7317,6 @@ which leave the original list as it was. One way to find out how this works is to experiment. We will start with the @code{setcar} function. @need 1200 -@cindex constant lists -@cindex mutable lists First, we can make a list and then set the value of a variable to the list, using the @code{setq} special form. Because we intend to use @code{setcar} to change the list, this @code{setq} should not use the @@ -7327,8 +7325,7 @@ a list that is part of the program and bad things could happen if we tried to change part of the program while running it. Generally speaking an Emacs Lisp program's components should be constant (or unchanged) while the program is running. So we instead construct an -animal list that is @dfn{mutable} (or changeable) by using the -@code{list} function, as follows: +animal list by using the @code{list} function, as follows: @smallexample (setq animals (list 'antelope 'giraffe 'lion 'tiger)) diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index bba1b63115..9a6796790c 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi @@ -297,7 +297,7 @@ Lisp Data Types * Circular Objects:: Read syntax for circular structure. * Type Predicates:: Tests related to types. * Equality Predicates:: Tests of equality between any two objects. -* Constants and Mutability:: Whether an object's value can change. +* Mutability:: Some objects should not be modified. Programming Types diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi index baddce4d9c..39f342a798 100644 --- a/doc/lispref/eval.texi +++ b/doc/lispref/eval.texi @@ -158,11 +158,11 @@ contents unchanged. @end group @end example - A self-evaluating form yields constant conses, vectors and strings, and you -should not attempt to modify their contents via @code{setcar}, @code{aset} or + A self-evaluating form yields a value that becomes part of the program, +and you should not try to modify it via @code{setcar}, @code{aset} or similar operations. The Lisp interpreter might unify the constants yielded by your program's self-evaluating forms, so that these -constants might share structure. @xref{Constants and Mutability}. +constants might share structure. @xref{Mutability}. It is common to write numbers, characters, strings, and even vectors in Lisp code, taking advantage of the fact that they self-evaluate. @@ -564,8 +564,8 @@ and vectors.) @defspec quote object This special form returns @var{object}, without evaluating it. -The returned value is a constant, and should not be modified. -@xref{Constants and Mutability}. +The returned value might be shared and should not be modified. +@xref{Self-Evaluating Forms}. @end defspec @cindex @samp{'} for quoting @@ -608,9 +608,9 @@ Here are some examples of expressions that use @code{quote}: Although the expressions @code{(list '+ 1 2)} and @code{'(+ 1 2)} both yield lists equal to @code{(+ 1 2)}, the former yields a -freshly-minted mutable list whereas the latter yields a constant list -built from conses that may be shared with other constants. -@xref{Constants and Mutability}. +freshly-minted mutable list whereas the latter yields a list +built from conses that might be shared and should not be modified. +@xref{Self-Evaluating Forms}. Other quoting constructs include @code{function} (@pxref{Anonymous Functions}), which causes an anonymous lambda expression written in Lisp @@ -710,8 +710,9 @@ Here are some examples: @end example If a subexpression of a backquote construct has no substitutions or -splices, it acts like @code{quote} in that it yields constant conses, -vectors and strings that should not be modified. +splices, it acts like @code{quote} in that it yields conses, +vectors and strings that might be shared and should not be modified. +@xref{Self-Evaluating Forms}. @node Eval @section Eval diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index fcaf4386b1..ae793d5e15 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -873,8 +873,8 @@ primitives @code{setcar} and @code{setcdr}. These are destructive operations because they change existing list structure. Destructive operations should be applied only to mutable lists, that is, lists constructed via @code{cons}, @code{list} or similar -operations. Lists created by quoting are constants and should not be -changed by destructive operations. @xref{Constants and Mutability}. +operations. Lists created by quoting are part of the program and +should not be changed by destructive operations. @xref{Mutability}. @cindex CL note---@code{rplaca} vs @code{setcar} @quotation @@ -911,7 +911,7 @@ value @var{object}. For example: @example @group -(setq x (list 1 2)) ; @r{Create a mutable list.} +(setq x (list 1 2)) @result{} (1 2) @end group @group @@ -931,7 +931,7 @@ these lists. Here is an example: @example @group -;; @r{Create two mutable lists that are partly shared.} +;; @r{Create two lists that are partly shared.} (setq x1 (list 'a 'b 'c)) @result{} (a b c) (setq x2 (cons 'z (cdr x1))) @@ -1022,11 +1022,11 @@ reached via the @sc{cdr}. @example @group -(setq x (list 1 2 3)) ; @r{Create a mutable list.} +(setq x (list 1 2 3)) @result{} (1 2 3) @end group @group -(setcdr x '(4)) ; @r{Modify the list's tail to be a constant list.} +(setcdr x '(4)) @result{} (4) @end group @group @@ -1135,11 +1135,11 @@ Unlike @code{append} (@pxref{Building Lists}), the @var{lists} are @example @group -(setq x (list 1 2 3)) ; @r{Create a mutable list.} +(setq x (list 1 2 3)) @result{} (1 2 3) @end group @group -(nconc x '(4 5)) ; @r{Modify the list's tail to be a constant list.} +(nconc x '(4 5)) @result{} (1 2 3 4 5) @end group @group diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index 1d5b2c690f..136213ad66 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi @@ -46,10 +46,6 @@ you store in it, type and all. (Actually, a small number of Emacs Lisp variables can only take on values of a certain type. @xref{Variables with Restricted Values}.) - Some Lisp objects are @dfn{constant}: their values should never change. -Others are @dfn{mutable}: their values can be changed via destructive -operations that involve side effects. - This chapter describes the purpose, printed representation, and read syntax of each of the standard types in GNU Emacs Lisp. Details on how to use these types can be found in later chapters. @@ -63,7 +59,7 @@ to use these types can be found in later chapters. * Circular Objects:: Read syntax for circular structure. * Type Predicates:: Tests related to types. * Equality Predicates:: Tests of equality between any two objects. -* Constants and Mutability:: Whether an object's value can change. +* Mutability:: Some objects should not be modified. @end menu @node Printed Representation @@ -2379,51 +2375,59 @@ that for two strings to be equal, they have the same text properties. @end example @end defun -@node Constants and Mutability -@section Constants and Mutability -@cindex constants +@node Mutability +@section Mutability @cindex mutable objects - Some Lisp objects are constant: their values should never change -during a single execution of Emacs running well-behaved Lisp code. -For example, you can create a new integer by calculating one, but you -cannot modify the value of an existing integer. - - Other Lisp objects are mutable: it is safe to change their values -via destructive operations involving side effects. For example, an -existing marker can be changed by moving the marker to point to -somewhere else. - - Although all numbers are constants and all markers are -mutable, some types contain both constant and mutable members. These -types include conses, vectors, strings, and symbols. For example, the string -literal @code{"aaa"} yields a constant string, whereas the function -call @code{(make-string 3 ?a)} yields a mutable string that can be -changed via later calls to @code{aset}. - - A mutable object can become constant if it is part of an expression -that is evaluated. The reverse does not occur: constant objects -should stay constant. - - Trying to modify a constant variable signals an error -(@pxref{Constant Variables}). -A program should not attempt to modify other types of constants because the -resulting behavior is undefined: the Lisp interpreter might or might -not detect the error, and if it does not detect the error the -interpreter can behave unpredictably thereafter. Another way to put -this is that although mutable objects are safe to change and constant -variables reliably prevent attempts to change them, other constants -are not safely mutable: if a misbehaving program tries to change such a -constant then the constant's value might actually change, or the -program might crash or worse. This problem occurs -with types that have both constant and mutable members, and that have -mutators like @code{setcar} and @code{aset} that are valid on mutable -objects but hazardous on constants. - - When the same constant occurs multiple times in a program, the Lisp + Some Lisp objects should never change. For example, the Lisp +expression @code{"aaa"} yields a string, but you should not change +its contents. Indeed, some objects cannot be changed; for example, +although you can create a new number by calculating one, Lisp provides +no operation to change the value of an existing number. + + Other Lisp objects are @dfn{mutable}: it is safe to change their +values via destructive operations involving side effects. For +example, an existing marker can be changed by moving the marker to +point to somewhere else. + + Although numbers never change and all markers are mutable, +some types have members some of which are mutable and others not. These +types include conses, vectors, and strings. For example, +although @code{"aaa"} yields a string that should not be changed, +@code{(make-string 3 ?a)} yields a mutable string that can be +changed via later calls to @code{aset}. Another example: +@code{(symbol-name 'cons)} yields a string @code{"cons"} that should +not be changed. + + A mutable object stops being mutable if it is part of an expression +that is evaluated. For example: + +@example +(let* ((x (list 0.5)) + (y (eval (list 'quote x)))) + (setcar x 1.5) ;; The program should not do this. + y) +@end example + +@noindent +Although the list @code{(0.5)} was mutable when it was created, it should not +have been changed via @code{setcar} because it given to @code{eval}. The +reverse does not occur: an object that should not be changed never +becomes mutable afterwards. + + If a program attempts to change objects that should not be +changed, the resulting behavior is undefined: the Lisp interpreter +might signal an error, or it might crash or behave unpredictably in +other ways.@footnote{This is the behavior specified for languages like +Common Lisp and C, and it differs from the behavior of languages like +JavaScript and Python where an interpreter is required to signal an +error if a program attempts to change a constant. Ideally the Emacs +Lisp interpreter will evolve in latter direction.} + + When similar constants occur as parts of a program, the Lisp interpreter might save time or space by reusing existing constants or -constant components. For example, @code{(eq "abc" "abc")} returns +their components. For example, @code{(eq "abc" "abc")} returns @code{t} if the interpreter creates only one instance of the string -constant @code{"abc"}, and returns @code{nil} if it creates two +literal @code{"abc"}, and returns @code{nil} if it creates two instances. Lisp programs should be written so that they work regardless of whether this optimization is in use. diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 1cb0d05cc7..91c3049f87 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -183,11 +183,11 @@ for other ways to copy sequences. @example @group -(setq bar (list 1 2)) ; @r{Create a mutable list.} +(setq bar (list 1 2)) @result{} (1 2) @end group @group -(setq x (vector 'foo bar)) ; @r{Create a mutable vector.} +(setq x (vector 'foo bar)) @result{} [foo (1 2)] @end group @group @@ -278,7 +278,7 @@ Unlike @code{reverse} the original @var{sequence} may be modified. @example @group -(setq x (list 'a 'b 'c)) ; @r{Create a mutable list.} +(setq x (list 'a 'b 'c)) @result{} (a b c) @end group @group @@ -320,7 +320,7 @@ presented graphically: For the vector, it is even simpler because you don't need setq: @example -(setq x (copy-sequence [1 2 3 4])) ; @r{Create a mutable vector.} +(setq x (copy-sequence [1 2 3 4])) @result{} [1 2 3 4] (nreverse x) @result{} [4 3 2 1] @@ -331,6 +331,7 @@ x Note that unlike @code{reverse}, this function doesn't work with strings. Although you can alter string data by using @code{aset}, it is strongly encouraged to treat strings as immutable even when they are mutable. +@xref{Mutability}. @end defun @@ -374,7 +375,7 @@ appears in a different position in the list due to the change of @example @group -(setq nums (list 1 3 2 6 5 4 0)) ; @r{Create a mutable list.} +(setq nums (list 1 3 2 6 5 4 0)) @result{} (1 3 2 6 5 4 0) @end group @group @@ -1228,7 +1229,7 @@ This function sets the @var{index}th element of @var{array} to be @example @group -(setq w (vector 'foo 'bar 'baz)) ; @r{Create a mutable vector.} +(setq w (vector 'foo 'bar 'baz)) @result{} [foo bar baz] (aset w 0 'fu) @result{} fu @@ -1237,7 +1238,7 @@ w @end group @group -;; @r{@code{copy-sequence} creates a mutable string.} +;; @r{@code{copy-sequence} copies the string to be modified later.} (setq x (copy-sequence "asdfasfd")) @result{} "asdfasfd" (aset x 3 ?Z) @@ -1247,9 +1248,7 @@ x @end group @end example -The @var{array} should be mutable; that is, it should not be a constant, -such as the constants created via quoting or via self-evaluating forms. -@xref{Constants and Mutability}. +The @var{array} should be mutable. @xref{Mutability}. If @var{array} is a string and @var{object} is not a character, a @code{wrong-type-argument} error results. The function converts a @@ -1262,7 +1261,6 @@ each element of @var{array} is @var{object}. It returns @var{array}. @example @group -;; @r{Create a mutable vector and then fill it with zeros.} (setq a (copy-sequence [a b c d e f g])) @result{} [a b c d e f g] (fillarray a 0) @@ -1271,7 +1269,6 @@ a @result{} [0 0 0 0 0 0 0] @end group @group -;; @r{Create a mutable string and then fill it with "-".} (setq s (copy-sequence "When in the course")) @result{} "When in the course" (fillarray s ?-) @@ -1310,8 +1307,8 @@ same way in Lisp input. evaluation: the result of evaluating it is the same vector. This does not evaluate or even examine the elements of the vector. @xref{Self-Evaluating Forms}. Vectors written with square brackets -are constants and should not be modified via @code{aset} or other -destructive operations. @xref{Constants and Mutability}. +should not be modified via @code{aset} or other destructive +operations. @xref{Mutability}. Here are examples illustrating these principles: diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index a4c9c2549c..70c3b3cf4b 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi @@ -49,10 +49,9 @@ by a distinguished character code. Since strings are arrays, and therefore sequences as well, you can operate on them with the general array and sequence functions documented -in @ref{Sequences Arrays Vectors}. For example, you can access or -change individual characters in a string using the functions @code{aref} -and @code{aset} (@pxref{Array Functions}). However, you should not -try to change the contents of constant strings (@pxref{Modifying Strings}). +in @ref{Sequences Arrays Vectors}. For example, you can access +individual characters in a string using the function @code{aref} +(@pxref{Array Functions}). There are two text representations for non-@acronym{ASCII} characters in Emacs strings (and in buffers): unibyte and multibyte. @@ -382,9 +381,7 @@ usual value is @w{@code{"[ \f\t\n\r\v]+"}}. @cindex string modification You can alter the contents of a mutable string via operations -described in this section. However, you should not try to use these -operations to alter the contents of a constant string. -@xref{Constants and Mutability}. +described in this section. @xref{Mutability}. The most basic way to alter the contents of an existing string is with @code{aset} (@pxref{Array Functions}). @code{(aset @var{string}