emacs-devel
[Top][All Lists]
Advanced

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

Re: locate-file in Emacs


From: Hrvoje Niksic
Subject: Re: locate-file in Emacs
Date: Wed, 17 Apr 2002 11:47:14 +0200
User-agent: Gnus/5.090006 (Oort Gnus v0.06) XEmacs/21.4 (Common Lisp, i686-pc-linux)

"Stefan Monnier" <monnier+gnu/address@hidden> writes:

>> Several years ago I talked to Richard Stallman about incorporating the
>> `locate-file' function in Emacs.  `locate-file' is a very useful
>> XEmacs function that searches for a file in a path.
>
> I like it.

Thanks.

> This is obviously very convenient.  It should ideally be implemented
> on top of the `openp' function, such as the quick-hack
> implementation below.

It ignores a part of the interface -- the MODE argument in this case.
My version may not be as optimized, but at least it implements all of
the interface.  You might want to start by including (and advertising)
it, and replacing it with an optimized version if it gets used.

PREDICATE might make sense, but I don't remember needing it in
practice.  Plus, it'd change the interface and hence undermine the
whole point of sharing the function.

Note that MODE is actually quite easy to implement -- just add a MODE
option to openp(), and have it call access() instead of open() when
MODE is provided.  Before doing anything else, decode MODE from Lisp
to C with code like this (written by me, thus copyright-safe):

static int
decode_mode_1 (Lisp_Object mode)
{
  if (EQ (mode, Qexists))
    return F_OK;
  else if (EQ (mode, Qexecutable))
    return X_OK;
  else if (EQ (mode, Qwritable))
    return W_OK;
  else if (EQ (mode, Qreadable))
    return R_OK;
  else if (INTP (mode))
    {
      check_int_range (XINT (mode), 0, 7);
      return XINT (mode);
    }
  else
    signal_simple_error ("Invalid value", mode);
  return 0;                     /* unreached */
}

static int
decode_mode (Lisp_Object mode)
{
  if (NILP (mode))
    return R_OK;
  else if (CONSP (mode))
    {
      Lisp_Object tail;
      int mask = 0;
      EXTERNAL_LIST_LOOP (tail, mode)
        mask |= decode_mode_1 (XCAR (tail));
      return mask;
    }
  else
    return decode_mode_1 (mode);
}

Such decoded mode is a valid second argument to access.



reply via email to

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