* progmodes/grep.el (grep-probe): Use `process-file'.
(grep-compute-defaults): Handle variables host specific.
This commit is contained in:
parent
4e44b31fb8
commit
05c7c7b162
1 changed files with 120 additions and 78 deletions
|
@ -371,92 +371,134 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
|
|||
|
||||
(defun grep-probe (command args &optional func result)
|
||||
(equal (condition-case nil
|
||||
(apply (or func 'call-process) command args)
|
||||
(apply (or func 'process-file) command args)
|
||||
(error nil))
|
||||
(or result 0)))
|
||||
|
||||
;;;###autoload
|
||||
(defun grep-compute-defaults ()
|
||||
(unless (or (not grep-use-null-device) (eq grep-use-null-device t))
|
||||
(setq grep-use-null-device
|
||||
(with-temp-buffer
|
||||
(let ((hello-file (expand-file-name "HELLO" data-directory)))
|
||||
(not
|
||||
(and (if grep-command
|
||||
;; `grep-command' is already set, so
|
||||
;; use that for testing.
|
||||
(grep-probe grep-command
|
||||
`(nil t nil "^English" ,hello-file)
|
||||
#'call-process-shell-command)
|
||||
;; otherwise use `grep-program'
|
||||
(grep-probe grep-program
|
||||
`(nil t nil "-nH" "^English" ,hello-file)))
|
||||
(progn
|
||||
(goto-char (point-min))
|
||||
(looking-at
|
||||
(concat (regexp-quote hello-file)
|
||||
":[0-9]+:English")))))))))
|
||||
(unless (and grep-command grep-find-command
|
||||
grep-template grep-find-template)
|
||||
(let ((grep-options
|
||||
(concat (if grep-use-null-device "-n" "-nH")
|
||||
(if (grep-probe grep-program
|
||||
`(nil nil nil "-e" "foo" ,null-device)
|
||||
nil 1)
|
||||
" -e"))))
|
||||
(unless grep-command
|
||||
(setq grep-command
|
||||
(format "%s %s " grep-program grep-options)))
|
||||
(unless grep-template
|
||||
(setq grep-template
|
||||
(format "%s <C> %s <R> <F>" grep-program grep-options)))
|
||||
(unless grep-find-use-xargs
|
||||
(setq grep-find-use-xargs
|
||||
(cond
|
||||
((and
|
||||
(grep-probe find-program `(nil nil nil ,null-device "-print0"))
|
||||
(grep-probe "xargs" `(nil nil nil "-0" "-e" "echo")))
|
||||
'gnu)
|
||||
(t
|
||||
'exec))))
|
||||
(unless grep-find-command
|
||||
(setq grep-find-command
|
||||
(cond ((eq grep-find-use-xargs 'gnu)
|
||||
(format "%s . -type f -print0 | xargs -0 -e %s"
|
||||
find-program grep-command))
|
||||
((eq grep-find-use-xargs 'exec)
|
||||
(let ((cmd0 (format "%s . -type f -exec %s"
|
||||
find-program grep-command)))
|
||||
(cons
|
||||
(format "%s {} %s %s"
|
||||
cmd0 null-device
|
||||
(shell-quote-argument ";"))
|
||||
(1+ (length cmd0)))))
|
||||
(t
|
||||
(format "%s . -type f -print | xargs %s"
|
||||
find-program grep-command)))))
|
||||
(unless grep-find-template
|
||||
(setq grep-find-template
|
||||
(let ((gcmd (format "%s <C> %s <R>"
|
||||
grep-program grep-options)))
|
||||
(let ((host-id
|
||||
(intern (or (file-remote-p default-directory 'host) "localhost"))))
|
||||
;; There are different defaults on different hosts. They must be
|
||||
;; computed for every host once, then they are kept in the
|
||||
;; variables' property host-id for reuse.
|
||||
(setq grep-command
|
||||
(or (get 'grep-command host-id)
|
||||
(eval (car (get 'grep-command 'standard-value))))
|
||||
|
||||
grep-template
|
||||
(or (get 'grep-template host-id)
|
||||
(eval (car (get 'grep-template 'standard-value))))
|
||||
|
||||
grep-use-null-device
|
||||
(or (get 'grep-use-null-device host-id)
|
||||
(eval (car (get 'grep-use-null-device 'standard-value))))
|
||||
|
||||
grep-find-command
|
||||
(or (get 'grep-find-command host-id)
|
||||
(eval (car (get 'grep-find-command 'standard-value))))
|
||||
|
||||
grep-find-template
|
||||
(or (get 'grep-find-template host-id)
|
||||
(eval (car (get 'grep-find-template 'standard-value))))
|
||||
|
||||
grep-find-use-xargs
|
||||
(or (get 'grep-find-use-xargs host-id)
|
||||
(eval (car (get 'grep-find-use-xargs 'standard-value))))
|
||||
|
||||
grep-highlight-matches
|
||||
(or (get 'grep-highlight-matches host-id)
|
||||
(eval (car (get 'grep-highlight-matches 'standard-value)))))
|
||||
|
||||
(unless (or (not grep-use-null-device) (eq grep-use-null-device t))
|
||||
(setq grep-use-null-device
|
||||
(with-temp-buffer
|
||||
(let ((hello-file (expand-file-name "HELLO" data-directory)))
|
||||
(not
|
||||
(and (if grep-command
|
||||
;; `grep-command' is already set, so
|
||||
;; use that for testing.
|
||||
(grep-probe grep-command
|
||||
`(nil t nil "^English" ,hello-file)
|
||||
#'call-process-shell-command)
|
||||
;; otherwise use `grep-program'
|
||||
(grep-probe grep-program
|
||||
`(nil t nil "-nH" "^English" ,hello-file)))
|
||||
(progn
|
||||
(goto-char (point-min))
|
||||
(looking-at
|
||||
(concat (regexp-quote hello-file)
|
||||
":[0-9]+:English")))))))))
|
||||
(unless (and grep-command grep-find-command
|
||||
grep-template grep-find-template)
|
||||
(let ((grep-options
|
||||
(concat (if grep-use-null-device "-n" "-nH")
|
||||
(if (grep-probe grep-program
|
||||
`(nil nil nil "-e" "foo" ,null-device)
|
||||
nil 1)
|
||||
" -e"))))
|
||||
(unless grep-command
|
||||
(setq grep-command
|
||||
(format "%s %s " grep-program grep-options)))
|
||||
(unless grep-template
|
||||
(setq grep-template
|
||||
(format "%s <C> %s <R> <F>" grep-program grep-options)))
|
||||
(unless grep-find-use-xargs
|
||||
(setq grep-find-use-xargs
|
||||
(cond
|
||||
((and
|
||||
(grep-probe find-program `(nil nil nil ,null-device "-print0"))
|
||||
(grep-probe "xargs" `(nil nil nil "-0" "-e" "echo")))
|
||||
'gnu)
|
||||
(t
|
||||
'exec))))
|
||||
(unless grep-find-command
|
||||
(setq grep-find-command
|
||||
(cond ((eq grep-find-use-xargs 'gnu)
|
||||
(format "%s . <X> -type f <F> -print0 | xargs -0 -e %s"
|
||||
find-program gcmd))
|
||||
(format "%s . -type f -print0 | xargs -0 -e %s"
|
||||
find-program grep-command))
|
||||
((eq grep-find-use-xargs 'exec)
|
||||
(format "%s . <X> -type f <F> -exec %s {} %s %s"
|
||||
find-program gcmd null-device
|
||||
(shell-quote-argument ";")))
|
||||
(let ((cmd0 (format "%s . -type f -exec %s"
|
||||
find-program grep-command)))
|
||||
(cons
|
||||
(format "%s {} %s %s"
|
||||
cmd0 null-device
|
||||
(shell-quote-argument ";"))
|
||||
(1+ (length cmd0)))))
|
||||
(t
|
||||
(format "%s . <X> -type f <F> -print | xargs %s"
|
||||
find-program gcmd))))))))
|
||||
(unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
|
||||
(setq grep-highlight-matches
|
||||
(with-temp-buffer
|
||||
(and (grep-probe grep-program '(nil t nil "--help"))
|
||||
(progn
|
||||
(goto-char (point-min))
|
||||
(search-forward "--color" nil t))
|
||||
t)))))
|
||||
(format "%s . -type f -print | xargs %s"
|
||||
find-program grep-command)))))
|
||||
(unless grep-find-template
|
||||
(setq grep-find-template
|
||||
(let ((gcmd (format "%s <C> %s <R>"
|
||||
grep-program grep-options)))
|
||||
(cond ((eq grep-find-use-xargs 'gnu)
|
||||
(format "%s . <X> -type f <F> -print0 | xargs -0 -e %s"
|
||||
find-program gcmd))
|
||||
((eq grep-find-use-xargs 'exec)
|
||||
(format "%s . <X> -type f <F> -exec %s {} %s %s"
|
||||
find-program gcmd null-device
|
||||
(shell-quote-argument ";")))
|
||||
(t
|
||||
(format "%s . <X> -type f <F> -print | xargs %s"
|
||||
find-program gcmd))))))))
|
||||
(unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
|
||||
(setq grep-highlight-matches
|
||||
(with-temp-buffer
|
||||
(and (grep-probe grep-program '(nil t nil "--help"))
|
||||
(progn
|
||||
(goto-char (point-min))
|
||||
(search-forward "--color" nil t))
|
||||
t))))
|
||||
|
||||
;; Save defaults for this host.
|
||||
(put 'grep-command host-id grep-command)
|
||||
(put 'grep-template host-id grep-template)
|
||||
(put 'grep-use-null-device host-id grep-use-null-device)
|
||||
(put 'grep-find-command host-id grep-find-command)
|
||||
(put 'grep-find-template host-id grep-find-template)
|
||||
(put 'grep-find-use-xargs host-id grep-find-use-xargs)
|
||||
(put 'grep-highlight-matches host-id grep-highlight-matches)))
|
||||
|
||||
(defun grep-tag-default ()
|
||||
(or (and transient-mark-mode mark-active
|
||||
|
|
Loading…
Add table
Reference in a new issue