From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: Re: Delayed warnings Date: Wed, 27 Apr 2011 02:55:57 +0200 Message-ID: References: <4D8705CA.1020300@gmx.at> <4D874FF3.9010606@gmx.at> <4D8793B1.2040701@gmx.at> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1303865808 28341 80.91.229.12 (27 Apr 2011 00:56:48 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 27 Apr 2011 00:56:48 +0000 (UTC) Cc: martin rudalics , Emacs developers To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 27 02:56:44 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QEt3b-0005Y4-Tc for ged-emacs-devel@m.gmane.org; Wed, 27 Apr 2011 02:56:44 +0200 Original-Received: from localhost ([::1]:37993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEt3b-0004R8-Di for ged-emacs-devel@m.gmane.org; Tue, 26 Apr 2011 20:56:43 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:40765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEt3X-0004Ql-RS for emacs-devel@gnu.org; Tue, 26 Apr 2011 20:56:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QEt3W-00087y-Hf for emacs-devel@gnu.org; Tue, 26 Apr 2011 20:56:39 -0400 Original-Received: from mail-yw0-f41.google.com ([209.85.213.41]:41283) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEt3W-00087q-DD for emacs-devel@gnu.org; Tue, 26 Apr 2011 20:56:38 -0400 Original-Received: by ywa1 with SMTP id 1so538159ywa.0 for ; Tue, 26 Apr 2011 17:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=apxkC2GR1/HMEon2DNv+Z2diamjBR364LAtcPamp6r8=; b=VU+u1oOYpfzNdn21x3EezM1waVdRn1feYL9Klvks4CeCKcVIaYW7fpKB70NrrVEga7 fytGKpez+dZtishrmJfjVzmIOyFxuRIqh+LypA7jXwrXnn2iwKJlAd46M8+mqRCE33/+ h4gORSZmGQJQ+LtZ1WLdYQgUWKW5ac6Cpp9xQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=nOizKZ38X9z/KZKYo4QBkLRzzHYTRsUo1seKFkz+yyR03s1WmL0T+B8jUHpoESLTG6 CpJ235k/h1daCOKDgc0GqBkGwMBhtsZvpGBFXwpj7U07BcDl4wV/8FPHtcJP8aHGHz4/ XIQlYUjdEMNbKpupjihDMI3fJUW78V8YI08KA= Original-Received: by 10.236.176.6 with SMTP id a6mr1695489yhm.428.1303865797155; Tue, 26 Apr 2011 17:56:37 -0700 (PDT) Original-Received: by 10.147.182.5 with HTTP; Tue, 26 Apr 2011 17:55:57 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.213.41 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:138818 Archived-At: No decision was reached about delayed warnings, so I'm proposing installing the attached patch. It is basically a trio of variables: - delayed-warnings-list: the list where desired warnigns are added. - delayed-warnings-function: the function to show warnings and reset `delayed-warning-list'. Defaults to `display-delayed-warnings'. - delayed-warnings-filter: a function that sould be called from `delayed-warnings-function' to filter out unwanted messages. plus one function: - display-delayed-warnings: Default value of `delayed-warnings-function'. It calls `display-warning' on the warnings (after filtering them with `delayed-warnings-filter'), then resets the warnings list to nil. I think this is conveniently flexible, and allows the user to filter out unwanted warnings with ease: (lexical-let* ((unwanted '("unwanted warning 1" "unwanted warning 2" ...)) (unwanted-re (regexp-opt unwanted))) (defun my-delayed-warnings-filter (warning) (let ((text (cadr warning))) (and (string-match-p unwanted-re text) (message "%s: %s" (car warning) text))))) =C2=A0 =C2=A0 Juanma 2011-04-26 Juanma Barranquero * subr.el (display-delayed-warnings): New function. (delayed-warnings-function, delayed-warnings-filter): New variables. 2011-04-26 Juanma Barranquero * keyboard.c (Qdelayed_warnings_function): Define. (command_loop_1): Run Qdelayed_warnings_function "hook" if Vdelayed_warnings_list is non-nil. (syms_of_keyboard) : DEFSYM it. (syms_of_keyboard) : DEFVAR_LISP them. =3D=3D=3D modified file 'lisp/subr.el' --- lisp/subr.el 2011-04-26 10:44:03 +0000 +++ lisp/subr.el 2011-04-27 00:01:44 +0000 @@ -1773,6 +1773,31 @@ (eval-after-load file (read))) (make-obsolete 'eval-next-after-load `eval-after-load "23.2") =0C +(defun display-delayed-warnings () + "Display delayed warnings in `delayed-warnings-list'. +Warnings are filtered through `delayed-warning-filter' (which see). +This is the default function for `delayed-warnings-function'." + (dolist (warning (nreverse delayed-warnings-list)) + (unless (and delayed-warnings-filter + (funcall delayed-warnings-filter warning)) + (apply 'display-warning warning))) + (setq delayed-warnings-list nil)) + +(defvar delayed-warnings-function 'display-delayed-warnings + "Function called to display delayed warnings. +The function should access variables `delayed-warnings-list', containing +the warnings waiting to be displayed, and `delayed-warnings-filter', +a function used to filter out warnings. +It is the responsibility of this function to clear `delayed-warnings-list' +as needed.") + +(defvar delayed-warnings-filter nil + "Function to filter delayed warnings. +It must be nil, meaning do not filter out any warning, or a function +of one argument, a list (TYPE MESSAGE [LEVEL [BUFFER-NAME]]), which must +return nil for warnings that should be displayed, non-nil otherwise.") + +=0C ;;;; Process stuff. (defun process-lines (program &rest args) =3D=3D=3D modified file 'src/keyboard.c' --- src/keyboard.c 2011-04-26 18:02:10 +0000 +++ src/keyboard.c 2011-04-26 23:47:10 +0000 @@ -267,6 +267,8 @@ static Lisp_Object Qdeferred_action_function; +static Lisp_Object Qdelayed_warnings_function; + static Lisp_Object Qinput_method_exit_on_first_char; static Lisp_Object Qinput_method_use_echo_area; @@ -1356,6 +1358,10 @@ if (!NILP (echo_area_buffer[0])) resize_echo_area_exactly (); + /* If there are warnings waiting, process them. */ + if (!NILP (Vdelayed_warnings_list)) + safe_run_hooks (Qdelayed_warnings_function); + if (!NILP (Vdeferred_action_list)) safe_run_hooks (Qdeferred_action_function); } @@ -1573,6 +1579,10 @@ if (!NILP (echo_area_buffer[0])) resize_echo_area_exactly (); + /* If there are warnings waiting, process them. */ + if (!NILP (Vdelayed_warnings_list)) + safe_run_hooks (Qdelayed_warnings_function); + safe_run_hooks (Qdeferred_action_function); /* If there is a prefix argument, @@ -11498,6 +11508,7 @@ DEFSYM (Qpre_command_hook, "pre-command-hook"); DEFSYM (Qpost_command_hook, "post-command-hook"); DEFSYM (Qdeferred_action_function, "deferred-action-function"); + DEFSYM (Qdelayed_warnings_function, "delayed-warnings-function"); DEFSYM (Qfunction_key, "function-key"); DEFSYM (Qmouse_click, "mouse-click"); DEFSYM (Qdrag_n_drop, "drag-n-drop"); @@ -12069,6 +12080,14 @@ whenever `deferred-action-list' is non-nil. */); Vdeferred_action_function =3D Qnil; + DEFVAR_LISP ("delayed-warnings-list", Vdelayed_warnings_list, + doc: /* List of warnings to be displayed as soon as possibl= e. +Each element must be a list (TYPE MESSAGE [LEVEL [BUFFER-NAME]]), +as per the args of `display-warning' (which see). +If this variable is non-nil, `delayed-warnings-function' will be called +immediately after running `post-command-hook'. */); + Vdelayed_warnings_list =3D Qnil; + DEFVAR_LISP ("suggest-key-bindings", Vsuggest_key_bindings, doc: /* *Non-nil means show the equivalent key-binding when M-x command has one. The value can be a length of time to show the message for.