From 89558533683a100ca7946c4a35bf4ef50463efef Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 24 Jul 2023 18:08:40 +0300 Subject: [PATCH 1/4] Don't signal error when locking a file from non file-visiting buffer * lisp/userlock.el (userlock--check-content-unchanged): Support the case where a file is locked before being written to from a non file-visiting buffer. (Bug#64821) --- lisp/userlock.el | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lisp/userlock.el b/lisp/userlock.el index 562bc0a0a9f..96de17d54fd 100644 --- a/lisp/userlock.el +++ b/lisp/userlock.el @@ -110,10 +110,11 @@ You can <\\`q'>uit; don't modify this file.")) (defun userlock--check-content-unchanged (filename) (with-demoted-errors "Unchanged content check: %S" - ;; Even tho we receive `filename', we know that `filename' refers to the current - ;; buffer's file. - (cl-assert (equal (expand-file-name filename) - (expand-file-name buffer-file-truename))) + ;; Even tho we receive `filename', we know that `filename' refers + ;; to the current buffer's file. + (cl-assert (or (null buffer-file-truename) ; temporary buffer + (equal (expand-file-name filename) + (expand-file-name buffer-file-truename)))) ;; Note: rather than read the file and compare to the buffer, we could save ;; the buffer and compare to the file, but for encrypted data this ;; wouldn't work well (and would risk exposing the data). @@ -135,7 +136,13 @@ You can <\\`q'>uit; don't modify this file.")) (compare-buffer-substrings buf start end (current-buffer) (point-min) (point-max)))))) - (set-visited-file-modtime) + ;; We know that some buffer visits FILENAME, because our + ;; caller (see lock_file) verified that. Thus, we set the + ;; modtime in that buffer, to cater to use case where the + ;; file is about to be written to from some buffer that + ;; doesn't visit any file, like a temporary buffer. + (with-current-buffer (get-file-buffer (file-truename filename)) + (set-visited-file-modtime)) 'unchanged))))) ;;;###autoload From f6e4e77d23d0be79be83ef41c3ea9acd5c983af2 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 25 Jul 2023 16:49:18 +0300 Subject: [PATCH 2/4] ; Minor documentation fixes * src/character.c (Fstring_width): Doc fix. * doc/emacs/trouble.texi (Understanding Bug Reporting): Fix typo (bug#64854). --- doc/emacs/trouble.texi | 2 +- src/character.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/emacs/trouble.texi b/doc/emacs/trouble.texi index bccdea72b19..d2e8ac3452a 100644 --- a/doc/emacs/trouble.texi +++ b/doc/emacs/trouble.texi @@ -706,7 +706,7 @@ produced by typing those commands. for the detailed raw data. Reporting the facts is straightforward, but many people strain to posit explanations and report them instead of the facts. If the explanations are based on guesses about how -Emacs is implemented, they night not be useful; meanwhile, lacking the +Emacs is implemented, they might not be useful; meanwhile, lacking the facts, we will have no real information about the bug. If you want to actually @emph{debug} the problem, and report explanations that are more than guesses, that is useful---but please include the raw facts diff --git a/src/character.c b/src/character.c index ae153a579d6..9389e1c0098 100644 --- a/src/character.c +++ b/src/character.c @@ -470,7 +470,7 @@ used for non-Latin and other unusual characters (such as emoji) is ignored as well, as are display properties and invisible text. For these reasons, the results are not generally reliable; for accurate dimensions of text as it will be displayed, -use `window-text-pixel-size' instead. +use `string-pixel-width' or `window-text-pixel-size' instead. usage: (string-width STRING &optional FROM TO) */) (Lisp_Object str, Lisp_Object from, Lisp_Object to) { From 142007b747eacf81b609f98852053bc0f6e18bdf Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 25 Jul 2023 17:51:58 +0300 Subject: [PATCH 3/4] Don't suggest to revert buffer from non-existing file * lisp/files-x.el (modify-file-local-variable-message): Suggest to revert from the buffer's file only if that file exists; otherwise suggest 'normal-mode'. (Bug#64844) --- lisp/files-x.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/files-x.el b/lisp/files-x.el index 9b1a7a17902..3ba7632d253 100644 --- a/lisp/files-x.el +++ b/lisp/files-x.el @@ -136,7 +136,10 @@ Intended to be used in the `interactive' spec of (eq new-value not-value) (not (equal old-value new-value))) (message "%s" (substitute-command-keys - "For this change to take effect revisit file using \\[revert-buffer]"))))) + (if (and (stringp buffer-file-name) + (file-exists-p buffer-file-name)) + "For this change to take effect revisit file using \\[revert-buffer]" + "For this change to take effect use \\[normal-mode]")))))) (defun modify-file-local-variable (variable value op &optional interactive) "Modify file-local VARIABLE in Local Variables depending on operation OP. From 65834b8f8d53402517da7fe2446f5bac0aa30c39 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 25 Jul 2023 20:38:01 +0300 Subject: [PATCH 4/4] Avoid crashes under 'which-key-mode' * src/keyboard.c (Fthis_single_command_keys): Don't allow calls to Fvector with negative first argument. (Bug#64857) --- src/keyboard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index 41cda2e65de..2e850b74b9b 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -11138,8 +11138,8 @@ the command loop or by `read-key-sequence'. The value is always a vector. */) (void) { - return Fvector (this_command_key_count - - this_single_command_key_start, + ptrdiff_t nkeys = this_command_key_count - this_single_command_key_start; + return Fvector (nkeys < 0 ? 0 : nkeys, (XVECTOR (this_command_keys)->contents + this_single_command_key_start)); }