unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Hrvoje Niksic <hniksic@arsdigita.com>
Cc: emacs-devel@gnu.org
Subject: Re: locate-file in Emacs
Date: Wed, 17 Apr 2002 11:47:14 +0200	[thread overview]
Message-ID: <sxs4riahd25.fsf@florida.arsdigita.de> (raw)
In-Reply-To: <200204170928.g3H9SVb27019@rum.cs.yale.edu> ("Stefan Monnier"'s message of "Wed, 17 Apr 2002 05:28:31 -0400")

"Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> 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	other threads:[~2002-04-17  9:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-17  5:05 locate-file in Emacs Hrvoje Niksic
2002-04-17  5:47 ` Eli Zaretskii
2002-04-17  8:53   ` Hrvoje Niksic
2002-04-17  9:28 ` Stefan Monnier
2002-04-17  9:47   ` Hrvoje Niksic [this message]
2002-04-17 10:01     ` Stefan Monnier
2002-04-18 13:16       ` Hrvoje Niksic
2002-04-18 13:54         ` Miles Bader
2002-04-18 14:09           ` Hrvoje Niksic
2002-04-18 14:25             ` Miles Bader
2002-04-18 14:08         ` Stefan Monnier
2002-04-18 15:11           ` Hrvoje Niksic
2002-04-18 15:27             ` Stefan Monnier
2002-04-18 16:20               ` Hrvoje Niksic
2002-04-18 18:59                 ` Stefan Monnier
2002-04-25 12:12                   ` Hrvoje Niksic
2002-04-25 22:52                     ` Stefan Monnier
2002-05-06 15:58                       ` Hrvoje Niksic
     [not found]                         ` <200205061655.g46Gt3K01382@rum.cs.yale.edu>
2002-05-06 19:53                           ` Hrvoje Niksic
     [not found]                             ` <200205062052.g46KqwO02482@rum.cs.yale.edu>
2002-05-06 20:59                               ` Hrvoje Niksic
2002-05-06 21:12                                 ` Stefan Monnier
2002-05-06 21:57                                   ` Hrvoje Niksic
2002-05-07 20:06                                     ` Richard Stallman
2002-04-18 16:39               ` Eli Zaretskii
2002-04-18 16:24                 ` Hrvoje Niksic
2002-04-19  5:25               ` Richard Stallman
2002-04-18 15:31             ` Miles Bader
2002-04-18 16:29               ` Hrvoje Niksic
2002-04-18 16:45                 ` Miles Bader
2002-04-18 16:49                   ` Hrvoje Niksic
2002-04-18 16:54                     ` Miles Bader

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=sxs4riahd25.fsf@florida.arsdigita.de \
    --to=hniksic@arsdigita.com \
    --cc=emacs-devel@gnu.org \
    /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).