emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (message (format "File %s" file))


From: Kim F. Storm
Subject: Re: (message (format "File %s" file))
Date: Mon, 05 Sep 2005 16:07:54 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> All this almost makes one wonder if it would make sense to provide a
>> msg:
>
>> (defun msg (arg)
>>      (message "%s" arg))
>
>> A lot of times, an author accidentally writes the code with msg in
>> mind rather than message.  This error is pervasive, especially if you
>> look at all the add-on code (not part of emacs).  I bet there is aon
>> average, at least one bug per file.
>
> In the past I suggested to make (message ARG) automatically behave like
> (message "%s" ARG) and AFAIK the only prolem with that was a few rare case
> like (message "Compiling list...( 0%%)") and those problems are easy to fix.
>

I think this would be a very good approach -- and trivial to implement.

One problem is that it is not backwards compatible, so code written for
22.x may cause problems when used on older emacsen or other dialects.

I.e. (message "%s") works fine on 22.x, but breaks on 21.x.

Anyway, here is a patch (mostly doc changes in fact)...


*** editfns.c   04 Sep 2005 23:32:29 +0200      1.396
--- editfns.c   05 Sep 2005 16:00:17 +0200      
***************
*** 3115,3125 ****
  The message also goes into the `*Messages*' buffer.
  \(In keyboard macros, that's all it does.)
  
! The first argument is a format control string, and the rest are data
! to be formatted under control of the string.  See `format' for details.
! 
! If the first argument is nil, the function clears any existing message;
! this lets the minibuffer contents show.  See also `current-message'.
  
  usage: (message STRING &rest ARGS)  */)
       (nargs, args)
--- 3115,3128 ----
  The message also goes into the `*Messages*' buffer.
  \(In keyboard macros, that's all it does.)
  
! If called with one string argument, that string is printed literally.
! Otherwise, the first argument is a format control string, and the rest
! are data to be formatted under control of the string.  See `format'
! for details.
! 
! If the first argument is nil or an empty string, the function clears
! any existing message; this lets the minibuffer contents show.
! See also `current-message'.
  
  usage: (message STRING &rest ARGS)  */)
       (nargs, args)
***************
*** 3136,3142 ****
    else
      {
        register Lisp_Object val;
!       val = Fformat (nargs, args);
        message3 (val, SBYTES (val), STRING_MULTIBYTE (val));
        return val;
      }
--- 3139,3148 ----
    else
      {
        register Lisp_Object val;
!       if (nargs == 1 && STRINGP (args[0]))
!       val = args[0];
!       else
!       val = Fformat (nargs, args);
        message3 (val, SBYTES (val), STRING_MULTIBYTE (val));
        return val;
      }
***************
*** 3145,3155 ****
  DEFUN ("message-box", Fmessage_box, Smessage_box, 1, MANY, 0,
         doc: /* Display a message, in a dialog box if possible.
  If a dialog box is not available, use the echo area.
- The first argument is a format control string, and the rest are data
- to be formatted under control of the string.  See `format' for details.
  
! If the first argument is nil, clear any existing message; let the
! minibuffer contents show.
  
  usage: (message-box STRING &rest ARGS)  */)
       (nargs, args)
--- 3151,3164 ----
  DEFUN ("message-box", Fmessage_box, Smessage_box, 1, MANY, 0,
         doc: /* Display a message, in a dialog box if possible.
  If a dialog box is not available, use the echo area.
  
! If called with one string argument, that string is printed literally.
! Otherwise, the first argument is a format control string, and the rest
! are data to be formatted under control of the string.  See `format'
! for details.
! 
! If the first argument is nil or an empty string, clear any existing
! message; let the minibuffer contents show.
  
  usage: (message-box STRING &rest ARGS)  */)
       (nargs, args)
***************
*** 3164,3170 ****
    else
      {
        register Lisp_Object val;
!       val = Fformat (nargs, args);
  #ifdef HAVE_MENUS
        /* The MS-DOS frames support popup menus even though they are
         not FRAME_WINDOW_P.  */
--- 3173,3182 ----
    else
      {
        register Lisp_Object val;
!       if (nargs == 1 && STRINGP (args[0]))
!       val = args[0];
!       else
!       val = Fformat (nargs, args);
  #ifdef HAVE_MENUS
        /* The MS-DOS frames support popup menus even though they are
         not FRAME_WINDOW_P.  */
***************
*** 3207,3217 ****
  If this command was invoked with the mouse, use a dialog box if
  `use-dialog-box' is non-nil.
  Otherwise, use the echo area.
- The first argument is a format control string, and the rest are data
- to be formatted under control of the string.  See `format' for details.
  
! If the first argument is nil, clear any existing message; let the
! minibuffer contents show.
  
  usage: (message-or-box STRING &rest ARGS)  */)
       (nargs, args)
--- 3219,3232 ----
  If this command was invoked with the mouse, use a dialog box if
  `use-dialog-box' is non-nil.
  Otherwise, use the echo area.
  
! If called with one string argument, that string is printed literally.
! Otherwise, the first argument is a format control string, and the rest
! are data to be formatted under control of the string.  See `format'
! for details.
! 
! If the first argument is nil or an empty string, clear any existing
! message; let the minibuffer contents show.
  
  usage: (message-or-box STRING &rest ARGS)  */)
       (nargs, args)


-- 
Kim F. Storm <address@hidden> http://www.cua.dk





reply via email to

[Prev in Thread] Current Thread [Next in Thread]