From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: Fixing numerous `message' bugs.. Date: Thu, 06 Dec 2007 11:56:25 +0100 Message-ID: <85sl2gqeg6.fsf@lola.goethe.zz> References: <87myso8yrs.fsf@marie.gnufans.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1196939436 5697 80.91.229.12 (6 Dec 2007 11:10:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 6 Dec 2007 11:10:36 +0000 (UTC) Cc: Dave Goel , emacs-devel@gnu.org To: D. Goel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 06 12:10:45 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J0Ecs-0004pD-HQ for ged-emacs-devel@m.gmane.org; Thu, 06 Dec 2007 12:10:42 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J0Ecb-0005o3-QJ for ged-emacs-devel@m.gmane.org; Thu, 06 Dec 2007 06:10:25 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J0EcW-0005ms-34 for emacs-devel@gnu.org; Thu, 06 Dec 2007 06:10:20 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J0EcV-0005m3-NK for emacs-devel@gnu.org; Thu, 06 Dec 2007 06:10:19 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J0EcV-0005lp-DF for emacs-devel@gnu.org; Thu, 06 Dec 2007 06:10:19 -0500 Original-Received: from fencepost.gnu.org ([140.186.70.10]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J0EcU-00074O-Ql for emacs-devel@gnu.org; Thu, 06 Dec 2007 06:10:18 -0500 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J0EcU-00081x-D4; Thu, 06 Dec 2007 06:10:18 -0500 Original-Received: by lola.goethe.zz (Postfix, from userid 1002) id 770F71C4CCE5; Thu, 6 Dec 2007 11:56:25 +0100 (CET) In-Reply-To: <87myso8yrs.fsf@marie.gnufans.net> (D. Goel's message of "Wed, 05 Dec 2007 19:14:47 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:84786 Archived-At: D. Goel writes: > The emacs source code is littered with thousands of buggy calls to > `message'. Here is an example of such a structure: > > > (message > (if foo > nil > (if bar "abc" > (concat "def" filename)))) > > This example will lead to an error if the filename has %s in it. > > At the same time, the simplistic fix of replacing (message by (message > "%s" would be incorrect because if foo is true, the coder wanted > (message nil), and not (message "%s" nil). > > > The appropriate fix to this would be > > (let ((arg ((rest-of-the-code)))) > (if (null arg) > (message nil) > (message "%s" arg))) (message (unless foo (if bar "abc" "def%s")) filename) Note that it is perfectly fine to have spurious trailing arguments to message. > > ^^^ This fix will have to be repeated thousands of time as I go > through the source code. > > It would rather make much more sense to code this fix into a little > function: > > (defun msg (arg) > (if (null arg) > (message nil) > (message (format "%s" arg)))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Uh, no. You mean (message "%s" arg) here, and anyway: (defun msg (arg) (message (and arg "%s") arg)) and then it is simple enough that it is not worth bothering introducing a separate function. Of course, arg should not involve a complex calculation. > .. this new function can be further improved to be more general, so > that develepors can simply start preferring the new msg if they like - > > (defun msg (&rest args) > (cond > ((null args) (message nil)) > ((null (car args) (message nil))) > ((= (length args) 1) (message "%s" (car args))) > (apply 'message args))) I think that is nonsensical. Problems occur only when a message contains non-fixed material (which may or may not contain percentages), but a message will pretty much never contain _exclusively_ non-fixed material. So a good solution will almost always involve more than a trivial "%s" format. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum