From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: jari.aalto@poboxes.com (Jari Aalto+mail.linux) Newsgroups: gmane.emacs.bugs Subject: [patch] 21.3 executable.find - Use cache in `executable-find' Date: Sun, 08 Feb 2004 13:37:16 +0200 Organization: Private Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Message-ID: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1076239782 7527 80.91.224.253 (8 Feb 2004 11:29:42 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 8 Feb 2004 11:29:42 +0000 (UTC) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 08 12:29:28 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Apn7w-0001i9-00 for ; Sun, 08 Feb 2004 12:29:28 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Apn5F-0007jP-S4 for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Feb 2004 06:26:41 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1Apn5B-0007iM-8J for bug-gnu-emacs@prep.ai.mit.edu; Sun, 08 Feb 2004 06:26:37 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1Apn4d-0007WS-7m for bug-gnu-emacs@prep.ai.mit.edu; Sun, 08 Feb 2004 06:26:34 -0500 Original-Received: from [193.229.0.48] (helo=fep21-app.kolumbus.fi) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Apn4b-0007W4-HH for bug-gnu-emacs@prep.ai.mit.edu; Sun, 08 Feb 2004 06:26:01 -0500 Original-Received: from poboxes.com ([81.197.3.110]) by fep21-app.kolumbus.fi with ESMTP id <20040208112559.FABJ27281.fep21-app.kolumbus.fi@poboxes.com> for ; Sun, 8 Feb 2004 13:25:59 +0200 Original-To: gnu.emacs.bug User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (windows-nt) (i386-msvc-nt5.0.2195) X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.bugs:6915 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:6915 It is common that searches for programs are done multiple times, so it would be good if the precious values were cached just like bash does. Here is patch to make this happen. This patch supposes that my other patches have been applied (See patch to implement `executable-command-find-unix-p') 2004-02-08 Sun Jari Aalto poboxes.com> * progmodes/executable.el (executable-find-cache): New variable. (executable-find-sans-suffix): New function. (executable-find-path): Renamed. Was `executable-find'. (executable-find-cache): New function. (executable-find): Rewritten. Now utilizes cache `executable-find-cache'. Added new OPTIONAL parameter `no-cache' to force searching COMMAND again. Index: executable.el =================================================================== RCS file: /cygdrive/h/data/version-control/cvsroot/emacs/gnu-emacs/lisp213/progmodes/executable.el,v retrieving revision 1.5 retrieving revision 1.6 diff -u -IId: -u -b -w -r1.5 -r1.6 --- executable.el 3 Feb 2004 16:34:18 -0000 1.5 +++ executable.el 8 Feb 2004 11:30:11 -0000 1.6 @@ -107,6 +107,10 @@ (defvar executable-command nil) +(defvar executable-find-cache nil + "*`executable-find' cache. +Syntax: '((program path) ...).") + (defcustom executable-self-display "tail" "*Command you use with argument `+2' to make text files self-display. Note that the like of `more' doesn't work too well under Emacs \\[shell]." @@ -205,10 +209,21 @@ ((search-forward "find: bad option -maxdepth" nil t) t))))) +(defun executable-find-sans-suffix (command) + "Return COMMAND without `executable-binary-suffixes'." + (let ((ext (file-name-extension command))) + (if (and ext + (member (concat "." ext) executable-binary-suffixes)) + (file-name-sans-extension command) + command))) + +(defsubst executable-find-cache (command) + "Look up COMMAND from `executable-find-cache'." + (assoc command executable-find-cache)) + ;;;###autoload -(defun executable-find (command) - "Search for COMMAND in exec-path and return the absolute file name. -Return nil if COMMAND is not found anywhere in `exec-path'." +(defun executable-find-path (command) + "Search for COMMAND in exec-path and return the absolute file name." (let ((list exec-path) file) (while list @@ -229,6 +244,29 @@ (cdr list)))) file)) +;;;###autoload +(defun executable-find (command &optional no-cache) + "Search for COMMAND in exec-path and return the absolute file name. +Return nil if COMMAND is not found anywhere in `exec-path'. +Optional parameter NO-CACHE says to search all PATH hierarchy +without looking the program location from `executable-find-cache'." + (let (cache + path) + (unless no-cache + (setq path (executable-find-cache + (executable-find-sans-suffix command)))) + (unless path + ;; Was not in cache, or user requested full PATH search + (when (setq path (executable-find-path command)) + ;; Record this to cache + (setq cache + (list (executable-find-sans-suffix + (file-name-nondirectory command)) + path)))) + (when cache + (push cache executable-find-cache)) + path)) + (defun executable-chmod () "This gets called after saving a file to assure that it be executable. You can set the absolute or relative mode in variable `executable-chmod' for @@ -241,7 +279,6 @@ (- executable-chmod) (logior executable-chmod (file-modes buffer-file-name))))))) - (defun executable-interpret (command) "Run script with user-specified args, and collect output in a buffer. -- http://tiny-tools.sourceforge.net/ Swatch @time http://www.mir.com.my/iTime/itime.htm http://www.ryanthiessen.com/swatch/resources.htm Use Licenses! http://www.linuxjournal.com/article.php?sid=6225 Which Licence? http://www.linuxjournal.com/article.php?sid=4825 OSI Licences http://www.opensource.org/licenses/