From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: format-quote? Date: Thu, 3 Aug 2006 11:25:09 -0700 Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1154629562 6611 80.91.229.2 (3 Aug 2006 18:26:02 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 3 Aug 2006 18:26:02 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 03 20:26:01 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1G8ht3-0004ED-Ai for ged-emacs-devel@m.gmane.org; Thu, 03 Aug 2006 20:25:38 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G8ht3-0008Nb-1T for ged-emacs-devel@m.gmane.org; Thu, 03 Aug 2006 14:25:37 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G8hsq-0008M5-UV for emacs-devel@gnu.org; Thu, 03 Aug 2006 14:25:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G8hsp-0008Kz-5q for emacs-devel@gnu.org; Thu, 03 Aug 2006 14:25:23 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G8hso-0008Ko-O4 for emacs-devel@gnu.org; Thu, 03 Aug 2006 14:25:22 -0400 Original-Received: from [148.87.113.118] (helo=rgminet01.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.52) id 1G8hwB-0005rF-6a for emacs-devel@gnu.org; Thu, 03 Aug 2006 14:28:52 -0400 Original-Received: from rcsmt251.oracle.com (rcsmt251.oracle.com [148.87.90.196]) by rgminet01.oracle.com (Switch-3.1.6/Switch-3.1.6) with ESMTP id k731Bw4i014556 for ; Thu, 3 Aug 2006 12:25:16 -0600 Original-Received: from dradams-lap.us.oracle.com by rcsmt251.oracle.com with ESMTP id 1693268751154629515; Thu, 03 Aug 2006 12:25:15 -0600 Original-To: "Emacs-Devel" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 X-Whitelist: TRUE 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:58054 Archived-At: The first arg to `format' is a format string. In some contexts, it happens that the string is the only argument used, it should be interpreted literally, and it might not be known ahead of time. For example, if you use (error (error-message-string foo)), it's possible that `error-message-string' will return something like this: "No match for regexp `^[^#$%>\n]*[#$%>] *\\S-.*'". Calling `error' on this directly would result in the (derivative) error "Not enough arguments for format string". AFAIK, there is no way to let `format' (and `error' etc.) know that you want the format string to be interpreted literally, so (in the use case mentioned) the `%'s need to be escaped before passing the string to `format', in order to show the original error message. That is: "No match for regexp `^[^#$%%>\n]*[#$%%>] *\\S-.*'" This escaping is easy, but having a function that does only that might be helpful, in terms of making people aware of this possible gotcha. (defun format-quote (string) "Quote STRING, so it becomes a literal format string. This just escapes each `%' in STRING." (replace-regexp-in-string "%" "%%" string t t)) Just as reading about `regexp-quote' can draw attention to the gotcha of forgetting to quote a regexp for literal regexp matching, reading about `format-quote' might draw attention to the gotcha of forgetting to quote a format string that should be treated literally in some context. WDOT? Would it be useful to add a `format-quote' function?