;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 ;; David J. Biesack ;; This file is not part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Edit shell command. Look up COMMAND in $PATH ;; and edit the file ;; ;; Sort of like doing ;; # emacsclient `whence command` ;; from ksh, or ;; % emacsclient `which command` ;; from csh ;; ;; Author: David Biesack (David.Biesack@sas.com or biesack@mindspring.com) ;; Last Modified By: biesack@mindspring.com ;; Last Modified: Thu Mar 15 17:41:54 2001 (defun ef (command) "Edit function/command" (interactive "sEdit shell command: ") (let ((command-path (sh-which command))) (if command-path (find-file command-path) (error "Command %s not found in path." command)))) (defun delimited-string-to-list (string &optional separator) "Parse a STRING into a list. Elements are delimited by SEPARATOR, which defaults to \" \"" (or separator (setq separator " ")) (let (list index) (while (> (length string) 0) (setq index (string-match separator string)) (if index (setq list (cons (substring string 0 index) list) string (substring string (1+ index))) (setq list (cons string list) string ""))) (nreverse list))) (defvar pathext (if (getenv "PATHEXT") (delimited-string-to-list (getenv "PATHEXT") ";") ()) "executable extensions.") (defvar search-path (delimited-string-to-list (getenv "PATH") (cond ((eq system-type 'windows-nt) ";") (t ":"))) "Environment list PATH as a list") (defun sh-which (command) "Return pathname where COMMAND is found in $PATH" (let (path file attr found candidate (extensions (cons "" pathext))) (while (and extensions (not found)) (setq candidate (concat command (car extensions)) extensions (cdr extensions)) (setq path search-path) (while (and path (not found)) (and (file-exists-p (setq file (concat (car path) "/" candidate))) (setq attr (file-attributes file)) (not (eq t (nth 0 attr))) ; not directory ; (or (message (format "%s %s" file attr)) (sit-for 1) t) (string-match "x" (nth 8 attr)) (setq found file)) (setq path (cdr path))) ) found))