Commits

Anonymous committed 35a46ab

2002-08-12 Steve Youngs <youngs@xemacs.org>

* Sync to upstream version 2.95.

* Makefile (all): Build autoloads first.
(REQUIRES): Add efs.
(AUTHOR_VERSION): Bump to 2.95.

Comments (0)

Files changed (3)

+2002-08-12  Steve Youngs  <youngs@xemacs.org>
+
+	* Sync to upstream version 2.95.
+
+	* Makefile (all): Build autoloads first.
+	(REQUIRES): Add efs.
+	(AUTHOR_VERSION): Bump to 2.95.
+
 1998-08-11  SL Baur  <steve@altair.xemacs.org>
 
 	* igrep.el-2.83.
 # Boston, MA 02111-1307, USA.
 
 VERSION = 1.08
-AUTHOR_VERSION = 2.83
+AUTHOR_VERSION = 2.95
 MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
 PACKAGE = igrep
 PKG_TYPE = regular
-REQUIRES = dired xemacs-base
+REQUIRES = dired xemacs-base efs
 CATEGORY = standard
 
 ELCS = igrep.elc
 
 include ../../XEmacs.rules
 
-all:: $(ELCS) auto-autoloads.elc
+all:: auto-autoloads.elc $(ELCS)
 
 srckit: srckit-std
 
 
 ;;;; igrep.el --- An improved interface to `grep` and `find`.
 
-;;; SCCS @(#)igrep.el	2.87
+;;; SCCS @(#)igrep.el	2.95
 
 ;;; Description:
 ;;; 
 ;;; analogues) provide defaults for the EXPRESSION and FILES arguments
 ;;; based on the current word and the visited file name (if the
 ;;; `igrep-expression-default' and `igrep-files-default' options are
-;;; set, respectively).  Other options that control the user interface
-;;; are `igrep-read-options', `igrep-read-multiple-files',
+;;; set, respectively).  The `igrep-insert-default-key' option allows
+;;; the default value to be inserted into the minibuffer for editing;
+;;; since Emacs 20 provides that via the minibuffer history, it's only
+;;; enabled for older versions by default. Other options that control
+;;; the user interface are `igrep-read-options', `igrep-read-multiple-files',
 ;;; `igrep-verbose-prompts', and `igrep-save-buffers'.
 ;;; 
 ;;; Besides the basic `igrep-program' and `igrep-find-program' global
 ;;; based on the visited directory (including any inserted
 ;;; subdirectories) and the current file.  The alternative
 ;;; `dired-do-igrep' and `dired-do-igrep-find' commands respect the
-;;; `dired-do-*' command calling conventions: a prefix argument is
-;;; interpreted as the number of succeeding files to `grep`, otherwise
-;;; all the marked files are `grep`ed.
+;;; `dired-do-*' command conventions: a prefix argument is interpreted
+;;; as the number of succeeding files to `grep`, otherwise all the
+;;; marked files are `grep`ed.
 ;;; 
 ;;; The `igrep-visited-files' command provides a simple way to `grep`
 ;;; just those files that are being visited in buffers.  The
 
 ;;; Copyright:
 ;;; 
-;;; Copyright � 1994,1995,1996,1997,1998,2000 Kevin Rodgers
+;;; Copyright � 1994-1998,2000-2002 Kevin Rodgers
 ;;; 
 ;;; This program is free software; you can redistribute it and/or modify
 ;;; it under the terms of the GNU General Public License as published by
 ;;; 2. Generalize support for the -prune find clause (e.g. -fstype nfs).
 ;;; 3. Provide support for `glimpse`.
 ;;; 4. Add a menu interface.
-;;; 5. Port to Emacs 20.
+;;; 5. Port to Emacs 20 (custom).
 
 ;;; Emacs Lisp Archive Entry:
 ;;; Filename: igrep.el
 ;;; Author: Kevin Rodgers <kevinr@ihs.com>
-;;; Version: 2.87
+;;; Version: 2.95
 ;;; Description: An improved interface to `grep` and `find`.
 ;;; Keywords: search
-;;; Last-Updated: 00/07/20
+;;; Last-Updated: 02/04/22
 
 
 ;;; Package interface:
 	(error nil)))
   )
 
-(defconst igrep-version "2.87"
+(defconst igrep-version "2.95"
   "Version of igrep.el")
 
 
 
 (defvar igrep-files-default 'igrep-buffer-file-name-pattern
   "*If non-nil, a function that returns the default FILES for `\\[igrep]'.
-The function is called with no arguments and should return a string (or nil).
+The function is called with no arguments and should return a string,
+or a list of strings (or nil).
 
 A different function can be specified for any particular mode by specifying
 a value for that `major-mode' property; for example:
 (put 'igrep-verbose-prompts 'variable-interactive
      "XPrompt verbosely? (t, 'semi, or nil): ")
 
+(defvar igrep-insert-default-key
+  (if (< emacs-major-version 20) "\C-c\C-e")
+  "*The key used to insert the default argument in the minibuffer.
+In Emacs 20, the default is available via the minibuffer history \
+(\\<minibuffer-local-map>\\[next-history-element]).")
+(put 'igrep-insert-default-key 'variable-interactive
+     "kSet key to insert the default `\\[igrep]' argument in the minibuffer: ")
+
 (defvar igrep-save-buffers 'query
   "*If t, `\\[igrep]' first saves each modified file buffer;
 if not t but non-nil, `\\[igrep]' offers to save each modified file buffer.")
 With a prefix arg, override the current `grep` command definitions."
   (interactive "P")
   (if override
-      (defalias 'grep-find 'igrep-find)
+      (defalias 'grep 'igrep)
     (defadvice grep (around igrep-interactive first (&rest command-args)
 			    activate)
       "If called interactively, use the `\\[igrep]' interface instead,
 			      (if igrep-find-use-xargs
 				  ""
 				(shell-quote-argument "{}"))
-			    (mapconcat 'identity files " "))
+			    (mapconcat (lambda (file)
+					 (let ((dir (file-name-directory file)))
+					   (if dir
+					       (expand-file-name
+						(file-name-nondirectory file)
+						(shell-quote-argument dir))
+					     file)))
+				       files " "))
 			  igrep-null-device)))
     (if igrep-find
 	(setq command
      igrep-args))
   (igrep program expression
 	 (let ((directory-abbrev-alist
-		(cons (cons (expand-file-name default-directory)
+		(cons (cons (regexp-quote (expand-file-name default-directory))
 			    "./")	; or even ""
 		      directory-abbrev-alist)))
 	   (mapcar 'abbreviate-file-name
     (setq marked-files (nreverse marked-files))
     (igrep program expression
 	   (let ((directory-abbrev-alist
-		  (cons (cons (expand-file-name default-directory)
+		  (cons (cons (regexp-quote (expand-file-name default-directory))
 			      "./")	; or even ""
 			directory-abbrev-alist)))
 	     (mapcar 'abbreviate-file-name marked-files))
 		  (t
 		   "%s %s %s %s %s -exec %s %s"))
 	    igrep-find-program
-	    (mapconcat 'identity (nreverse directories)
+	    (mapconcat 'shell-quote-argument (nreverse directories)
 		       " ")
 	    (if igrep-find-prune-clause
 		(format "%s -prune -o" igrep-find-prune-clause)
 		    (format "%s %s %s"
 			    (shell-quote-argument "(")
 			    (mapconcat (lambda (pat)
-					 (format "-name \"%s\"" pat))
+					 (format "-name %s"
+						 (shell-quote-argument pat)))
 				       (nreverse patterns)
 				       " -o ")
 			    (shell-quote-argument ")"))
-		  (format "-name \"%s\"" (car patterns)))
+		  (format "-name %s" (shell-quote-argument (car patterns))))
 	      "")
 	    command
 	    (shell-quote-argument ";")
 	      (funcall (get (quote ,variable) major-mode)))
 	     (t (funcall ,variable)))))
 
+(defun igrep-default-expression ()
+  (igrep-default-arg igrep-expression-default))
+
+(defun igrep-default-files ()
+  (let* ((dired-subdirectory (if (eq major-mode 'dired-mode)
+				 (dired-current-directory t)))
+	 (default-files (igrep-default-arg igrep-files-default)))
+    (if (not (listp default-files))	; stringp
+	(setq default-files (list default-files)))
+    (if dired-subdirectory
+	(mapcar (lambda (file)
+		  (concat dired-subdirectory file))
+		default-files)
+      default-files)))
+
 (defsubst igrep-prefix (prefix string &rest strings)
   ;; If PREFIX is non-nil or any STRINGS are specified, concatenate them
   ;; before and after STRING; otherwise, return the STRING.
 (defun igrep-read-expression (&optional prompt-prefix)
   ;; Read and return a `grep` expression string from the minibuffer.
   ;; Optional PROMPT-PREFIX is prepended to the "Expression: " prompt.
-  (let ((default-expression (igrep-default-arg igrep-expression-default)))
-    (if (string= default-expression "")
-	(setq default-expression nil))
-    (read-from-minibuffer (igrep-prefix prompt-prefix "Expression: ")
-			  default-expression nil nil
-			  'igrep-expression-history)))
+  (if igrep-insert-default-key
+      (define-key minibuffer-local-map igrep-insert-default-key
+	'igrep-insert-default-expression))
+  (let* ((default-expression (igrep-default-expression))
+	 (prompt (igrep-prefix prompt-prefix
+			       (if default-expression
+				   (format "Expression [default: %s]: "
+					   default-expression)
+				 "Expression: ")))
+	 (expression (cond ((featurep 'xemacs) ; incompatible
+			    (read-from-minibuffer prompt
+						  nil nil nil
+						  'igrep-expression-history
+						  nil ; ABBREV-TABLE
+						  default-expression))
+			   ((>= emacs-major-version 20)
+			    (read-from-minibuffer prompt
+						  nil nil nil
+						  'igrep-expression-history
+						  default-expression))
+			   (t
+			    (read-from-minibuffer prompt
+						  nil nil nil
+						  'igrep-expression-history)))))
+    (if (equal expression "")
+	(progn
+	  (or (equal default-expression (car igrep-expression-history))
+	      (setq igrep-expression-history
+		    (cons default-expression igrep-expression-history)))
+	  default-expression)
+      expression)))
+
+(defun igrep-insert-default-expression (&optional clear-minibuffer)
+  "*Insert the default expression in the minibuffer.
+If a prefix argument is specified, clear the minibuffer contents first."
+  (interactive "P")
+  (if clear-minibuffer
+      (delete-region (if (fboundp 'minibuffer-prompt-end) ; Emacs 21
+			 (minibuffer-prompt-end)
+		       (point-min))
+		     (point-max)))
+  (insert (or (save-excursion
+		(set-buffer (window-buffer minibuffer-scroll-window))
+		(igrep-default-expression))
+	      "")))
+
+(defun igrep-insert-default-files (&optional clear-minibuffer)
+  "*Insert the default files in the minibuffer.
+If a prefix argument is specified, clear the minibuffer contents first."
+  (interactive "P")
+  (if clear-minibuffer
+      (delete-region (if (fboundp 'minibuffer-prompt-end) ; Emacs 21
+			 (minibuffer-prompt-end)
+		       (point-min))
+		     (point-max)))
+  (insert (mapconcat 'identity
+		     (save-excursion
+		       (set-buffer (window-buffer minibuffer-scroll-window))
+		       (igrep-default-files))
+		     " ")))
 
 (defsubst igrep-default-key (command &optional keymap key)
   ;; Return the key bound to COMMAND in KEYMAP, preferably KEY.
   ;; current-prefix-arg is '(16) or '(64), read multiple file name
   ;; patterns and return them in a list.  Optional PROMPT-PREFIX is
   ;; prepended to the "File(s): " prompt.
-  (let* ((dired-subdirectory (if (eq major-mode 'dired-mode)
-				 (dired-current-directory t)))
-	 (default-files (if dired-subdirectory
-			    (concat dired-subdirectory
-				    (igrep-default-arg igrep-files-default))
-			  (igrep-default-arg igrep-files-default)))
+  (let* ((default-files (igrep-default-files))
+	 (default-files-string (mapconcat 'identity default-files " "))
 	 (insert-default-directory nil)	; use relative path names
 	 (file (igrep-read-file-name
-		(igrep-prefix prompt-prefix "File(s): ")
-		nil default-files nil default-files
-		'igrep-files-history)))
+		(igrep-prefix prompt-prefix
+			      (if default-files
+				  (format "File(s) [default: %s]: "
+					  default-files-string)
+				"File(s): "))
+		nil default-files-string nil nil
+		'igrep-files-history))
+	 (files (cond ((equal file default-files-string)
+		       (setq file default-files))
+		      ((not (listp file))
+		       (setq file (list file))))))
     (if (or igrep-read-multiple-files
 	    (and (consp current-prefix-arg)
 		 (memq (prefix-numeric-value current-prefix-arg)
 		       '(16 64))))
-	(let ((files (list file))
-	      (prompt
+	(let ((prompt
 	       (igrep-prefix prompt-prefix
 			     (if igrep-verbose-prompts
 				 (format "File(s): [Type `%s' when done] "
 			       ""))
 	    (setq files (cons file files)))
 	  (nreverse files))
-      file)))
+      files)))
 
 (defun igrep-read-file-name (prompt
   &optional directory default existing initial history)
   ;; Just like read-file-name, but with optional HISTORY.
   ;; Also: convert DIRECTORY to DIRECTORY/* file name pattern.
+  (if igrep-insert-default-key
+      (define-key minibuffer-local-completion-map igrep-insert-default-key
+	'igrep-insert-default-files))
   (let ((file-name
 	 (if history
 	     (let ((file-name-history (symbol-value history)))