diff options
Diffstat (limited to 'lisp/progmodes/grep.el')
-rw-r--r-- | lisp/progmodes/grep.el | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 24d5eababc6..fd93015ab2c 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -343,6 +343,12 @@ This variable's value takes effect when `grep-compute-defaults' is called.") (defvar grep-regexp-history nil) (defvar grep-files-history '("ch" "el")) +(defvar grep-host-defaults-alist nil + "Default values depending on target host. +`grep-compute-defaults' returns default values for every local or +remote host `grep' runs. These values can differ from host to +host. Once computed, the default values are kept here in order +to avoid computing them again.") ;;;###autoload (defun grep-process-setup () @@ -377,38 +383,51 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'." ;;;###autoload (defun grep-compute-defaults () - (let ((host-id - (intern (or (file-remote-p default-directory 'host) "localhost")))) + ;; Keep default values. + (unless grep-host-defaults-alist + (add-to-list + 'grep-host-defaults-alist + (cons nil + `((grep-command ,grep-command) + (grep-template ,grep-template) + (grep-use-null-device ,grep-use-null-device) + (grep-find-command ,grep-find-command) + (grep-find-template ,grep-find-template) + (grep-find-use-xargs ,grep-find-use-xargs) + (grep-highlight-matches ,grep-highlight-matches))))) + (let* ((host-id + (intern (or (file-remote-p default-directory 'host) "localhost"))) + (host-defaults (assq host-id grep-host-defaults-alist)) + (defaults (assq nil grep-host-defaults-alist))) ;; 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. + ;; computed for every host once. (setq grep-command - (or (get 'grep-command host-id) - (eval (car (get 'grep-command 'standard-value)))) + (or (cadr (assq 'grep-command host-defaults)) + (cadr (assq 'grep-command defaults))) grep-template - (or (get 'grep-template host-id) - (eval (car (get 'grep-template 'standard-value)))) + (or (cadr (assq 'grep-template host-defaults)) + (cadr (assq 'grep-template defaults))) grep-use-null-device - (or (get 'grep-use-null-device host-id) - (eval (car (get 'grep-use-null-device 'standard-value)))) + (or (cadr (assq 'grep-use-null-device host-defaults)) + (cadr (assq 'grep-use-null-device defaults))) grep-find-command - (or (get 'grep-find-command host-id) - (eval (car (get 'grep-find-command 'standard-value)))) + (or (cadr (assq 'grep-find-command host-defaults)) + (cadr (assq 'grep-find-command defaults))) grep-find-template - (or (get 'grep-find-template host-id) - (eval (car (get 'grep-find-template 'standard-value)))) + (or (cadr (assq 'grep-find-template host-defaults)) + (cadr (assq 'grep-find-template defaults))) grep-find-use-xargs - (or (get 'grep-find-use-xargs host-id) - (eval (car (get 'grep-find-use-xargs 'standard-value)))) + (or (cadr (assq 'grep-find-use-xargs host-defaults)) + (cadr (assq 'grep-find-use-xargs defaults))) grep-highlight-matches - (or (get 'grep-highlight-matches host-id) - (eval (car (get 'grep-highlight-matches 'standard-value))))) + (or (cadr (assq 'grep-highlight-matches host-defaults)) + (cadr (assq 'grep-highlight-matches defaults)))) (unless (or (not grep-use-null-device) (eq grep-use-null-device t)) (setq grep-use-null-device @@ -492,13 +511,19 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'." 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))) + (setq grep-host-defaults-alist + (delete (assq host-id grep-host-defaults-alist) + grep-host-defaults-alist)) + (add-to-list + 'grep-host-defaults-alist + (cons host-id + `((grep-command ,grep-command) + (grep-template ,grep-template) + (grep-use-null-device ,grep-use-null-device) + (grep-find-command ,grep-find-command) + (grep-find-template ,grep-find-template) + (grep-find-use-xargs ,grep-find-use-xargs) + (grep-highlight-matches ,grep-highlight-matches)))))) (defun grep-tag-default () (or (and transient-mark-mode mark-active |