unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Juri Linkov <juri@linkov.net>
Cc: 45412@debbugs.gnu.org, "Lars Ingebrigtsen" <larsi@gnus.org>,
	"積丹尼 Dan Jacobson" <jidanni@jidanni.org>
Subject: bug#45412: File ... is large (... MiB), really open? (y)es or (n)o or (l)iterally
Date: Sun, 11 Apr 2021 00:32:34 +0200	[thread overview]
Message-ID: <m11rbhbwjh.fsf@yahoo.es> (raw)
In-Reply-To: <87wnx62rpe.fsf@mail.linkov.net> (Juri Linkov's message of "Fri,  25 Dec 2020 11:32:11 +0200")

[-- Attachment #1: Type: text/plain, Size: 405 bytes --]

Juri Linkov <juri@linkov.net> writes:

>>> Another approach could be to offer a C-h binding that opens a help
>>> window that describes the possible options and briefly links to the
>>> customization entry point that removes the prompt permanently.
>>
>> Yeah, that sounds like a good idea.
>
> I agree, this is really the best idea.

OK, I've implemented it in the attached patch.  Suggestions
welcome.


[-- Attachment #2: 0001-Add-a-help-option-in-the-open-large-files-prompt.patch --]
[-- Type: text/x-patch, Size: 5246 bytes --]

From 8ae34d5bca1a8fc13f2388842880d4234ab28165 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <mardani29@yahoo.es>
Date: Sun, 11 Apr 2021 00:16:38 +0200
Subject: [PATCH] Add a help option in the open large files prompt

* lisp/files.el (files--ask-user-about-large-file-help): New function
that displays a Help buffer with information about opening large files
in Emacs.  (Bug#45412)
(files--ask-user-about-large-file): Add a ?/C-h option to the prompt.
* etc/NEWS: Advertise the change.
---
 etc/NEWS      |  6 ++++
 lisp/files.el | 76 +++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 61 insertions(+), 21 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index a0f05d8cf1..b1bd9689e2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -261,6 +261,12 @@ commands.  The new keystrokes are 'C-x x g' ('revert-buffer'),
 ** Commands 'set-frame-width' and 'set-frame-height' can now get their
 input using the minibuffer.
 
+---
+** When Emacs prompts before opening a large file, a new help window
+has been added.  This help window describes the available options and
+how to disable the prompt by customizing the
+'large-file-warning-threshold' variable.
+
 \f
 * Editing Changes in Emacs 28.1
 
diff --git a/lisp/files.el b/lisp/files.el
index 60d6034011..49224e4b1e 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2123,28 +2123,62 @@ out-of-memory-warning-percentage
 
 (declare-function x-popup-dialog "menu.c" (position contents &optional header))
 
+(defun files--ask-user-about-large-file-help (op-type size)
+  "Show a buffer explaining the options to open large files in Emacs."
+  (with-output-to-temp-buffer "*Help*"
+    (with-current-buffer standard-output
+      (insert
+       (format
+        "The file that you want to %s is large (%s).
+
+Large files may be slow to edit or navigate so Emacs asks you
+before you try to open such files.
+
+You can press ‘y‘ to open the file.
+You can press ‘n‘ to abort.
+You can press ‘l‘ to open the file literally, which means that
+Emacs will open the file without doing any format or character code
+conversion and in Fundamental mode, without loading any potentially
+expensive feature.
+
+You can customize the option ‘large-file-warning-threshold‘ to be
+the file size, in bytes, from which Emacs will ask for
+confirmation.  Set it to ‘nil‘ to never request
+confirmation."
+        op-type
+        size))
+      (save-excursion
+	(re-search-backward "\\(customize\\)" nil t)
+	(help-xref-button 1 'help-customize-variable 'large-file-warning-threshold)))))
+
 (defun files--ask-user-about-large-file (size op-type filename offer-raw)
-  (let ((prompt (format "File %s is large (%s), really %s?"
-		        (file-name-nondirectory filename)
-		        (funcall byte-count-to-string-function size) op-type)))
-    (if (not offer-raw)
-        (if (y-or-n-p prompt) nil 'abort)
-      (let* ((use-dialog (and (display-popup-menus-p)
-                              last-input-event
-	                      (listp last-nonmenu-event)
-	                      use-dialog-box))
-             (choice
-              (if use-dialog
-                  (x-popup-dialog t `(,prompt
-                                      ("Yes" . ?y)
-                                      ("No" . ?n)
-                                      ("Open literally" . ?l)))
-                (read-char-choice
-                 (concat prompt " (y)es or (n)o or (l)iterally ")
-                 '(?y ?Y ?n ?N ?l ?L)))))
-        (cond ((memq choice '(?y ?Y)) nil)
-              ((memq choice '(?l ?L)) 'raw)
-              (t 'abort))))))
+  (save-window-excursion
+    (let ((prompt (format "File %s is large (%s), really %s?"
+		          (file-name-nondirectory filename)
+		          (funcall byte-count-to-string-function size) op-type)))
+      (if (not offer-raw)
+          (if (y-or-n-p prompt) nil 'abort)
+        (let* ((use-dialog (and (display-popup-menus-p)
+                                last-input-event
+	                        (listp last-nonmenu-event)
+	                        use-dialog-box))
+               choice)
+          (if use-dialog
+              (setq choice (x-popup-dialog t `(,prompt
+                                               ("Yes" . ?y)
+                                               ("No" . ?n)
+                                               ("Open literally" . ?l))))
+            (while (null choice)
+              (setq choice (read-char-choice
+                            (concat prompt " (y)es, (n)o, (l)iterally, (?)")
+                            '(?y ?Y ?n ?N ?l ?L ?? ?\C-h)))
+              (when (memq choice '(?? ?\C-h))
+                (files--ask-user-about-large-file-help
+                 op-type (funcall byte-count-to-string-function size))
+                (setq choice nil))))
+          (cond ((memq choice '(?y ?Y)) nil)
+                ((memq choice '(?l ?L)) 'raw)
+                (t 'abort)))))))
 
 (defun abort-if-file-too-large (size op-type filename &optional offer-raw)
   "If file SIZE larger than `large-file-warning-threshold', allow user to abort.
-- 
2.31.0


  reply	other threads:[~2021-04-10 22:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-24 14:44 bug#45412: File ... is large (... MiB), really open? (y)es or (n)o or (l)iterally 積丹尼 Dan Jacobson
2020-12-25  1:00 ` Unknown
2020-12-25  1:29   ` 積丹尼 Dan Jacobson
2020-12-25  5:52   ` Lars Ingebrigtsen
2020-12-25  9:32     ` Juri Linkov
2021-04-10 22:32       ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-04-10 22:52         ` Juri Linkov
2021-04-11  7:03         ` Eli Zaretskii
2021-04-12  8:06         ` Lars Ingebrigtsen
2021-04-16 23:50           ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-04-17 11:44             ` Lars Ingebrigtsen
2021-04-21 22:12               ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-04-22 10:04                 ` Eli Zaretskii
2021-04-25 19:14                   ` Lars Ingebrigtsen
2021-04-25 21:23                     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-04-26  2:28                       ` Eli Zaretskii
2021-04-27  1:08                       ` Lars Ingebrigtsen
2021-05-05 23:10                         ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-06  8:28                           ` Lars Ingebrigtsen
2021-05-06  8:30                           ` Eli Zaretskii
2021-05-07 14:11                             ` Eli Zaretskii
2021-05-08 11:37                               ` Lars Ingebrigtsen
2021-05-08 12:22                                 ` Eli Zaretskii
2021-05-09  9:57                                   ` Lars Ingebrigtsen
2021-05-09 10:04                                     ` Eli Zaretskii
2021-04-22 22:09                 ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m11rbhbwjh.fsf@yahoo.es \
    --to=bug-gnu-emacs@gnu.org \
    --cc=45412@debbugs.gnu.org \
    --cc=jidanni@jidanni.org \
    --cc=juri@linkov.net \
    --cc=larsi@gnus.org \
    --cc=mardani29@yahoo.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).