unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Delayed warnings
@ 2011-03-20  5:44 Juanma Barranquero
  2011-03-21  8:01 ` martin rudalics
  0 siblings, 1 reply; 30+ messages in thread
From: Juanma Barranquero @ 2011-03-20  5:44 UTC (permalink / raw)
  To: Emacs developers

I want to warn the user for the case that the Windows port defaults to
setting HOME=C:\ because HOME is not set but C:/.emacs exists.

The only problem is that I want to use a warning, not a message,
because a warning is much more visible and less easy to overlook.

So, I need to set up a warning, delaying it until the right moment
(during startup.el, when the display is set up, lisp code can be
executed and everything's just right).

To such effect I want to add a new C-level variable Vdelayed_warnings
that C code can use to warn the user of problems during
initialization.

Already existing similar facilities are the
pending_malloc_warning/display_malloc_warning stuff and
deferred_action_list/deferred_action_function:

- *_malloc_warning could be used, but it is too specifically tied to
malloc, and it's best left alone.
- deferred_action_* is undocumented (see my other message).

Am I missing some other facility that would make Vdelayed_warnings unnecessary?

The following patch is just a proof-of-concept for discussion, BTW.

    Juanma



2011-03-20  Juanma Barranquero  <lekktu@gmail.com>

	* emacs.c (syms_of_emacs) <Vdelayed_warnings>: New variable.
	* w32.c (init_environment): Use it to warn about default HOME=C:\.


2011-03-20  Juanma Barranquero  <lekktu@gmail.com>

	* startup.el (command-line): Show delayed warnings.



=== modified file 'lisp/startup.el'
--- lisp/startup.el	2011-03-19 18:27:55 +0000
+++ lisp/startup.el	2011-03-20 04:41:59 +0000
@@ -1249,6 +1249,10 @@
   ;; If -batch, terminate after processing the command options.
   (if noninteractive (kill-emacs t))

+  ;; If we have delayed warnings, show them
+  (dolist (warning (nreverse delayed-warnings))
+    (apply 'display-warning warning))
+
   ;; In daemon mode, start the server to allow clients to connect.
   ;; This is done after loading the user's init file and after
   ;; processing all command line arguments to allow e.g. `server-name'

=== modified file 'src/emacs.c'
--- src/emacs.c	2011-03-17 16:32:03 +0000
+++ src/emacs.c	2011-03-20 04:22:09 +0000
@@ -2484,6 +2484,16 @@
   Vdynamic_library_alist = Qnil;
   Fput (intern_c_string ("dynamic-library-alist"), Qrisky_local_variable, Qt);

+  DEFVAR_LISP ("delayed-warnings", Vdelayed_warnings,
+               doc: /* List of warnings to be displayed during startup.
+For each item of the list,
+
+   (apply 'display-warning ITEM)
+
+is called, so ITEM must be a list of (TYPE MESSAGE [LEVEL [BUFFER-NAME]]),
+as per the args of `display-warning' (which see). */);
+  Vdelayed_warnings = Qnil;
+
   /* Make sure IS_DAEMON starts up as false.  */
   daemon_pipe[1] = 0;
 }

=== modified file 'src/w32.c'
--- src/w32.c	2011-03-14 17:07:53 +0000
+++ src/w32.c	2011-03-20 05:25:36 +0000
@@ -1554,6 +1554,7 @@
     char locale_name[32];
     struct stat ignored;
     char default_home[MAX_PATH];
+    int appdata = 0;

     static const struct env_entry
     {
@@ -1607,7 +1608,10 @@

 	  /* If we can't get the appdata dir, revert to old behavior.  */
 	  if (profile_result == S_OK)
+	      {
 	    env_vars[0].def_value = default_home;
+		appdata = 1;
+	      }
 	}
     }

@@ -1694,6 +1698,14 @@
 		lpval = env_vars[i].def_value;
 		dwType = REG_EXPAND_SZ;
 		dont_free = 1;
+		if (!strcmp (env_vars[i].name, "HOME") && !appdata)
+		  {
+		    Lisp_Object warning[2];
+		    warning[0] = intern ("initialization");
+		    warning[1] = build_string ("Setting HOME to C:\\ by default is
deprecated");
+		    Vdelayed_warnings = Fcons (Flist (2, warning),
+					       Vdelayed_warnings);
+		  }
 	      }

 	    if (lpval)



^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2011-05-09 18:28 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-20  5:44 Delayed warnings Juanma Barranquero
2011-03-21  8:01 ` martin rudalics
2011-03-21 12:01   ` Juanma Barranquero
2011-03-21 13:17     ` martin rudalics
2011-03-21 13:43       ` Eli Zaretskii
2011-03-21 18:06         ` martin rudalics
2011-03-21 14:48       ` Juanma Barranquero
2011-03-21 18:06         ` martin rudalics
2011-03-21 20:19           ` Juanma Barranquero
2011-03-21 22:05             ` Stefan Monnier
2011-03-22  7:59               ` martin rudalics
2011-03-22 11:59               ` Juanma Barranquero
2011-03-23 13:50               ` Jeff Sparkes
2011-03-25 13:10               ` Juanma Barranquero
2011-04-27  0:55                 ` Juanma Barranquero
2011-04-27  3:05                   ` Eli Zaretskii
2011-04-27 11:27                     ` Juanma Barranquero
2011-04-27 17:32                   ` Stefan Monnier
2011-04-27 22:11                     ` Juanma Barranquero
2011-04-28  0:40                       ` Stefan Monnier
2011-04-28  0:59                         ` Juanma Barranquero
2011-04-28 15:26                           ` Stefan Monnier
2011-04-28 16:22                             ` Juanma Barranquero
2011-04-28 18:39                               ` Stefan Monnier
2011-05-08 17:58                               ` Chong Yidong
2011-05-08 18:43                                 ` Juanma Barranquero
2011-05-09 14:15                                   ` Stefan Monnier
2011-05-09 18:28                                   ` Richard Stallman
2011-03-22  7:58             ` martin rudalics
2011-03-22 12:04               ` Juanma Barranquero

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).