unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Cc: schwab@suse.de, michael.cadilhac-@t-lrde.epita.fr,
	emacs-devel@gnu.org, monnier@iro.umontreal.ca, eliz@gnu.org,
	snogglethorpe@gmail.com, miles@gnu.org
Subject: Re: File modes facilities.
Date: Mon, 24 Oct 2005 16:02:38 +0200	[thread overview]
Message-ID: <m3zmozgght.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <E1ET5Er-0003lR-Cd@fencepost.gnu.org> (Richard M. Stallman's message of "Fri, 21 Oct 2005 18:19:49 -0400")

"Richard M. Stallman" <rms@gnu.org> writes:

>     *** callint.c	14 Aug 2005 14:47:25 +0200	1.140
>     --- callint.c	21 Oct 2005 16:38:22 +0200
>     ***************
>     *** 346,351 ****
>     --- 346,356 ----
> 	      function = wrong_type_argument (Qcommandp, function);
> 	      goto retry;
> 	    }
>     +       else if (*string == '#')
>     + 	{
>     + 	  string = 0;
>     + 	  goto get_interactive_form;
>     + 	}
>
> This would be much cleaner (and easier to use) if it read the Lisp
> expression out of the string itself, after the #.

I did consider that, and we could do that as well, but IMO, the whole
point of this to allow interactive specs for built-in functions to be
written in Lisp, i.e. in a .el file, so people can improve on the code
without modifying the base functionality.

Also, doing it right in the string makes it much harder to edit and
debug, and may cause problems on systems which has an upper limit on
constant string size.

> But as I said, I'd rather not install this now.

Ok, as a strong advocate of focusing on the release, I have to accept
that :-), although this change is really minor compared to some of the
other recent changes to core functionality ...

However, the patch is not the right approach in any case -- as it only
allows creating an interactive spec for DEFUN's which explicitly allow
it with the prompt = "#" marker.

Below is a _much_better_ patch which allows ANY function to have its
interactive specification overridden, and consequently you can make
any function into a command.

Here are some trivial examples:

(put 'set-file-modes 'interactive
     '(list (read-file-name "Set modes on file: ")
	    (read-number "New modes (decimal): ")))

(put 'set-file-times 'interactive
     '(list (read-file-name "Set current time on file: ")
            (current-time)))

(defun test (a b)
 (message "%d" (+ a b)))

(put 'test 'interactive
     '(list (read-number "a: ")
	    (read-number "b: ")))

(put 'test 'interactive "nx: \nny: ")


*** callint.c	14 Aug 2005 14:47:25 +0200	1.140
--- callint.c	24 Oct 2005 14:40:54 +0200	
***************
*** 333,338 ****
--- 333,348 ----
    /* If k or K discard an up-event, save it here so it can be retrieved with U */
    up_event = Qnil;
  
+   /* Allow overriding the interactive spec of any function
+      by placing an interactive property on the function name.  */
+ 
+   if (SYMBOLP (function)
+       && (specs = Fget (function, Qinteractive), !NILP (specs)))
+     {
+       filter_specs = specs;
+       goto override_interactive_form;
+     }
+ 
    /* Decode the kind of function.  Either handle it and return,
       or go to `lose' if not interactive, or go to `retry'
       to specify a different function, or set either STRING or SPECS.  */
***************
*** 357,363 ****
      {
        Lisp_Object form;
        GCPRO2 (function, prefix_arg);
!       form = Finteractive_form (function);
        UNGCPRO;
        if (CONSP (form))
  	specs = filter_specs = Fcar (XCDR (form));
--- 367,373 ----
      {
        Lisp_Object form;
        GCPRO2 (function, prefix_arg);
!       form = Finteractive_form (function, Qt);
        UNGCPRO;
        if (CONSP (form))
  	specs = filter_specs = Fcar (XCDR (form));
***************
*** 365,370 ****
--- 375,382 ----
  	goto lose;
      }
  
+     override_interactive_form:
+ 
    /* If either SPECS or STRING is set to a string, use it.  */
    if (STRINGP (specs))
      {

*** data.c	19 Sep 2005 00:24:45 +0200	1.254
--- data.c	24 Oct 2005 14:40:32 +0200	
***************
*** 775,788 ****
    return make_string (name, strlen (name));
  }
  
! DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0,
         doc: /* Return the interactive form of CMD or nil if none.
  If CMD is not a command, the return value is nil.
  Value, if non-nil, is a list \(interactive SPEC).  */)
!      (cmd)
!      Lisp_Object cmd;
  {
!   Lisp_Object fun = indirect_function (cmd);
  
    if (SUBRP (fun))
      {
--- 775,799 ----
    return make_string (name, strlen (name));
  }
  
! DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 2, 0,
         doc: /* Return the interactive form of CMD or nil if none.
  If CMD is not a command, the return value is nil.
+ If optional second arg NO-OVERRIDE is non-nil, do not look for an
+ overriding `interactive' specification property on CMD.
  Value, if non-nil, is a list \(interactive SPEC).  */)
!   (cmd, no_override)
!      Lisp_Object cmd, no_override;
  {
!   Lisp_Object fun;
!   Lisp_Object specs;
! 
!  retry:
!   if (NILP (no_override)
!       && SYMBOLP (cmd)
!       && (specs = Fget (cmd, Qinteractive), !NILP (specs)))
!     return list2 (Qinteractive, specs);
! 
!   fun = indirect_function (cmd);
  
    if (SUBRP (fun))
      {
***************
*** 797,811 ****
    else if (CONSP (fun))
      {
        Lisp_Object funcar = XCAR (fun);
        if (EQ (funcar, Qlambda))
  	return Fassq (Qinteractive, Fcdr (XCDR (fun)));
!       else if (EQ (funcar, Qautoload))
  	{
  	  struct gcpro gcpro1;
  	  GCPRO1 (cmd);
  	  do_autoload (fun, cmd);
  	  UNGCPRO;
! 	  return Finteractive_form (cmd);
  	}
      }
    return Qnil;
--- 808,824 ----
    else if (CONSP (fun))
      {
        Lisp_Object funcar = XCAR (fun);
+ 
        if (EQ (funcar, Qlambda))
  	return Fassq (Qinteractive, Fcdr (XCDR (fun)));
! 
!       if (EQ (funcar, Qautoload))
  	{
  	  struct gcpro gcpro1;
  	  GCPRO1 (cmd);
  	  do_autoload (fun, cmd);
  	  UNGCPRO;
! 	  goto retry;
  	}
      }
    return Qnil;

*** eval.c	14 Aug 2005 14:47:28 +0200	1.256
--- eval.c	24 Oct 2005 14:48:31 +0200	
***************
*** 1908,1913 ****
--- 1908,1917 ----
    register Lisp_Object fun;
    register Lisp_Object funcar;
  
+   if (SYMBOLP (function)
+       && !NILP (Fget (function, Qinteractive)))
+     return Qt;
+ 
    fun = function;
  
    fun = indirect_function (fun);

*** fileio.c	20 Oct 2005 16:48:05 +0200	1.557
--- fileio.c	21 Oct 2005 16:21:25 +0200	
***************
*** 3462,3468 ****
    return make_number (st.st_mode & 07777);
  }
  
! DEFUN ("set-file-modes", Fset_file_modes, Sset_file_modes, 2, 2, 0,
         doc: /* Set mode bits of file named FILENAME to MODE (an integer).
  Only the 12 low bits of MODE are used.  */)
    (filename, mode)
--- 3462,3468 ----
    return make_number (st.st_mode & 07777);
  }
  
! DEFUN ("set-file-modes", Fset_file_modes, Sset_file_modes, 2, 2, "#",
         doc: /* Set mode bits of file named FILENAME to MODE (an integer).
  Only the 12 low bits of MODE are used.  */)
    (filename, mode)

*** lisp.h	02 Oct 2005 21:08:17 +0200	1.542
--- lisp.h	24 Oct 2005 14:41:07 +0200	
***************
*** 2117,2123 ****
  extern Lisp_Object Qinteger;
  
  extern void circular_list_error P_ ((Lisp_Object));
! EXFUN (Finteractive_form, 1);
  
  /* Defined in frame.c */
  extern Lisp_Object Qframep;
--- 2117,2123 ----
  extern Lisp_Object Qinteger;
  
  extern void circular_list_error P_ ((Lisp_Object));
! EXFUN (Finteractive_form, 2);
  
  /* Defined in frame.c */
  extern Lisp_Object Qframep;


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

  reply	other threads:[~2005-10-24 14:02 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-19 20:09 File modes facilities Michael Cadilhac
2005-10-19 20:35 ` Stefan Monnier
2005-10-19 21:28   ` Michael Cadilhac
2005-10-19 22:19     ` Nick Roberts
2005-10-19 22:44       ` Michael Cadilhac
2005-10-19 22:48         ` Kim F. Storm
2005-10-19 22:57           ` Edward O'Connor
2005-10-19 23:00           ` Michael Cadilhac
2005-10-20  9:04         ` Eli Zaretskii
2005-10-20 10:41           ` Michael Cadilhac
2005-10-20 11:51             ` Romain Francoise
2005-10-20 12:41             ` Eli Zaretskii
2005-10-20 14:18               ` Michael Cadilhac
2005-10-20 16:15           ` Stefan Monnier
2005-10-20 22:16             ` Kim F. Storm
2005-10-21  3:21               ` Stefan Monnier
2005-10-21  8:44                 ` Andreas Schwab
2005-10-21 12:59                   ` Michael Cadilhac
2005-10-21 14:14                     ` Miles Bader
2005-10-21 14:43                       ` Kim F. Storm
2005-10-21 16:42                         ` Michael Cadilhac
2005-10-21 22:19                         ` Richard M. Stallman
2005-10-24 14:02                           ` Kim F. Storm [this message]
2005-10-24 14:16                             ` David Kastrup
2005-10-24 16:02                               ` Andreas Schwab
2005-10-24 21:00                               ` Kim F. Storm
2005-10-24 14:46                             ` Stefan Monnier
2005-10-24 22:14                               ` Kim F. Storm
2005-10-24 23:02                                 ` Stefan Monnier
2005-10-25  8:51                                   ` Kim F. Storm
2005-10-25 20:29                                     ` Richard M. Stallman
2005-10-25 15:58                             ` Richard M. Stallman
2005-10-25 21:34                               ` Kim F. Storm
2005-10-26  8:52                                 ` Kim F. Storm
2005-10-27  1:31                                   ` Richard M. Stallman
2005-10-27  1:29                                 ` Richard M. Stallman
2005-10-21 10:58                 ` Kim F. Storm
2005-10-21 11:05                 ` Kim F. Storm
2005-10-21 15:07                   ` Stefan Monnier
2005-10-21 17:51                 ` Richard M. Stallman
2005-10-21 18:43                   ` Stefan Monnier
2005-10-22  4:18                     ` Richard M. Stallman
2005-10-22  5:39                       ` Drew Adams
2005-10-22  6:17                         ` Miles Bader
2005-10-22  6:32                           ` Drew Adams
2005-10-22  7:33                             ` Miles Bader
2005-10-22  7:45                               ` Drew Adams
2005-10-23 18:05                         ` Stefan Monnier
2005-10-23 18:27                           ` Drew Adams
2005-10-24 13:37                             ` Richard M. Stallman
2005-10-24 13:40                             ` Stefan Monnier
2005-10-24 16:41                               ` Drew Adams
2005-10-24 16:59                                 ` Stefan Monnier
2005-10-24 17:13                                   ` Drew Adams
2005-10-20 23:38             ` Richard M. Stallman
2005-10-21  0:58               ` Michael Cadilhac
2005-10-21  1:06                 ` Miles Bader
2005-10-21  1:24                   ` Michael Cadilhac
2005-10-21 17:51                     ` Richard M. Stallman
2005-10-23 23:42                       ` Michael Cadilhac
2005-10-24 14:09                         ` Kim F. Storm
2005-10-25 15:58                           ` Richard M. Stallman
2005-10-20  1:42 ` Kevin Ryde
2005-10-20  2:01   ` Miles Bader
2005-10-20  7:12     ` Michael Cadilhac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3zmozgght.fsf@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=michael.cadilhac-@t-lrde.epita.fr \
    --cc=miles@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=schwab@suse.de \
    --cc=snogglethorpe@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).