aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMichael Albinus2019-03-09 16:44:24 +0100
committerMichael Albinus2019-03-09 16:44:24 +0100
commit21f54feee8c83e2c5fd8eeb6741cbd479a7b19eb (patch)
tree3edf223c49dfedf09ec93804856954a9554a93cd /lisp
parentc37bdd00c7dcabaa3ca8405d9dc5122ed36f27e0 (diff)
downloademacs-21f54feee8c83e2c5fd8eeb6741cbd479a7b19eb.tar.gz
emacs-21f54feee8c83e2c5fd8eeb6741cbd479a7b19eb.zip
Do not hardcode "/bin/sh" in compile. Bug#24338, Bug#29723
* doc/emacs/custom.texi (Connection Variables): New node. * doc/emacs/emacs.texi (Top): Add entry for Connection Variables. * doc/emacs/misc.texi (Single Shell): Mention default value for remote buffers. * doc/lispref/variables.texi (Connection Local Variables): Describe `with-connection-local-variables' instead of `with-connection-local-profiles'. * doc/misc/tramp.texi (Remote processes): Refer to Emacs manual. Mention default connection-local settings for `shell-file-name' and `shell-command-switch'. * etc/NEWS: Mention connection-local variables changes. * lisp/files-x.el (hack-connection-local-variables): Push connection-local variables to `file-local-variables-alist'. (connection-local-criteria-for-default-directory): New defsubst. (with-connection-local-variables): Rename from `with-connection-local-profiles'. Adapt implementation. * lisp/files.el (hack-local-variables): Call `hack-connection-local-variables'. * lisp/shell.el (shell): Use `with-connection-local-variables'. * lisp/subr.el (start-file-process-shell-command): * lisp/progmodes/compile.el (compilation-start): Use `with-connection-local-variables'. Do not set "/bin/sh" for remote buffers, trust settings of `shell-file-name'. (Bug#24338), (Bug#29723) * lisp/net/ange-ftp.el (ange-ftp-compress, ange-ftp-uncompress): Use `shell-command-switch'. * lisp/net/tramp-adb.el (tramp-adb-connection-local-default-profile): New defvar. Add it to connection-local profiles after loading "shell". * lisp/net/tramp-integration.el (tramp-compat): Require tramp-compat. (tramp-compat-exec-path): Do not declare anymore. (tramp-connection-local-safe-shell-file-names): New defvar. (tramp-connection-local-default-profile): New defconst. Activate it after loading "shell". (shell-file-name, shell-command-switch): Add safe-local-variable property. * lisp/net/tramp-sh.el (tramp-display-escape-sequence-regexp): Add tramp-autoload cookie. * test/lisp/files-x-tests.el (remote-shell-file-name): Add safe-local-variable property to remote-* variables. (tramp-connection-local-default-profile): Declare. (files-x-test-with-connection-local-variables): Rename from `files-x-test-with-connection-local-profiles'. Adapt implementation. * test/lisp/net/tramp-tests.el (tramp-test34-connection-local-variables): New test. (tramp-test34-explicit-shell-file-name): Run it also for tramp-adb. Bind connection-local-{profile,criteria}-alist. Use tramp-adb specific `shell-file-name'. Add safe-local-variable property to `explicit-shell-file-name' and `explicit-sh-args'.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files-x.el51
-rw-r--r--lisp/files.el5
-rw-r--r--lisp/net/ange-ftp.el4
-rw-r--r--lisp/net/tramp-adb.el20
-rw-r--r--lisp/net/tramp-integration.el34
-rw-r--r--lisp/net/tramp-sh.el1
-rw-r--r--lisp/progmodes/compile.el19
-rw-r--r--lisp/shell.el27
-rw-r--r--lisp/subr.el11
9 files changed, 120 insertions, 52 deletions
diff --git a/lisp/files-x.el b/lisp/files-x.el
index c9abb695700..eedf630b71f 100644
--- a/lisp/files-x.el
+++ b/lisp/files-x.el
@@ -582,7 +582,7 @@ changed by the user.")
582(setq ignored-local-variables 582(setq ignored-local-variables
583 (cons 'connection-local-variables-alist ignored-local-variables)) 583 (cons 'connection-local-variables-alist ignored-local-variables))
584 584
585(defvar connection-local-profile-alist '() 585(defvar connection-local-profile-alist nil
586 "Alist mapping connection profiles to variable lists. 586 "Alist mapping connection profiles to variable lists.
587Each element in this list has the form (PROFILE VARIABLES). 587Each element in this list has the form (PROFILE VARIABLES).
588PROFILE is the name of a connection profile (a symbol). 588PROFILE is the name of a connection profile (a symbol).
@@ -590,7 +590,7 @@ VARIABLES is a list that declares connection-local variables for
590PROFILE. An element in VARIABLES is an alist whose elements are 590PROFILE. An element in VARIABLES is an alist whose elements are
591of the form (VAR . VALUE).") 591of the form (VAR . VALUE).")
592 592
593(defvar connection-local-criteria-alist '() 593(defvar connection-local-criteria-alist nil
594 "Alist mapping connection criteria to connection profiles. 594 "Alist mapping connection criteria to connection profiles.
595Each element in this list has the form (CRITERIA PROFILES). 595Each element in this list has the form (CRITERIA PROFILES).
596CRITERIA is a plist identifying a connection and the application 596CRITERIA is a plist identifying a connection and the application
@@ -685,7 +685,9 @@ This does nothing if `enable-connection-local-variables' is nil."
685 ;; Loop over variables. 685 ;; Loop over variables.
686 (dolist (variable (connection-local-get-profile-variables profile)) 686 (dolist (variable (connection-local-get-profile-variables profile))
687 (unless (assq (car variable) connection-local-variables-alist) 687 (unless (assq (car variable) connection-local-variables-alist)
688 (push variable connection-local-variables-alist)))))) 688 (push variable connection-local-variables-alist))))
689 ;; Push them to `file-local-variables-alist'.
690 (hack-local-variables-filter connection-local-variables-alist nil)))
689 691
690;;;###autoload 692;;;###autoload
691(defun hack-connection-local-variables-apply (criteria) 693(defun hack-connection-local-variables-apply (criteria)
@@ -697,24 +699,35 @@ will not be changed."
697 (copy-tree connection-local-variables-alist))) 699 (copy-tree connection-local-variables-alist)))
698 (hack-local-variables-apply))) 700 (hack-local-variables-apply)))
699 701
702(defsubst connection-local-criteria-for-default-directory ()
703 "Return a connection-local criteria, which represents `default-directory'."
704 (when (file-remote-p default-directory)
705 `(:application tramp
706 :protocol ,(file-remote-p default-directory 'method)
707 :user ,(file-remote-p default-directory 'user)
708 :machine ,(file-remote-p default-directory 'host))))
709
700;;;###autoload 710;;;###autoload
701(defmacro with-connection-local-profiles (profiles &rest body) 711(defmacro with-connection-local-variables (&rest body)
702 "Apply connection-local variables according to PROFILES in current buffer. 712 "Apply connection-local variables according to `default-directory'.
703Execute BODY, and unwind connection-local variables." 713Execute BODY, and unwind connection-local variables."
704 (declare (indent 1) (debug t)) 714 (declare (debug t))
705 `(let ((enable-connection-local-variables t) 715 `(if (file-remote-p default-directory)
706 (old-buffer-local-variables (buffer-local-variables)) 716 (let ((enable-connection-local-variables t)
707 connection-local-variables-alist connection-local-criteria-alist) 717 (old-buffer-local-variables (buffer-local-variables))
708 (apply 'connection-local-set-profiles nil ,profiles) 718 connection-local-variables-alist)
709 (hack-connection-local-variables-apply nil) 719 (hack-connection-local-variables-apply
710 (unwind-protect 720 (connection-local-criteria-for-default-directory))
711 (progn ,@body) 721 (unwind-protect
712 ;; Cleanup. 722 (progn ,@body)
713 (dolist (variable connection-local-variables-alist) 723 ;; Cleanup.
714 (let ((elt (assq (car variable) old-buffer-local-variables))) 724 (dolist (variable connection-local-variables-alist)
715 (if elt 725 (let ((elt (assq (car variable) old-buffer-local-variables)))
716 (set (make-local-variable (car elt)) (cdr elt)) 726 (if elt
717 (kill-local-variable (car variable)))))))) 727 (set (make-local-variable (car elt)) (cdr elt))
728 (kill-local-variable (car variable)))))))
729 ;; No connection-local variables to apply.
730 ,@body))
718 731
719 732
720 733
diff --git a/lisp/files.el b/lisp/files.el
index 9948bd4a034..77a194b085d 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3590,6 +3590,11 @@ local variables, but directory-local variables may still be applied."
3590 result) 3590 result)
3591 (unless (eq handle-mode t) 3591 (unless (eq handle-mode t)
3592 (setq file-local-variables-alist nil) 3592 (setq file-local-variables-alist nil)
3593 (when (file-remote-p default-directory)
3594 (with-demoted-errors "Connection-local variables error: %s"
3595 ;; Note this is a no-op if enable-local-variables is nil.
3596 (hack-connection-local-variables
3597 (connection-local-criteria-for-default-directory))))
3593 (with-demoted-errors "Directory-local variables error: %s" 3598 (with-demoted-errors "Directory-local variables error: %s"
3594 ;; Note this is a no-op if enable-local-variables is nil. 3599 ;; Note this is a no-op if enable-local-variables is nil.
3595 (hack-dir-local-variables))) 3600 (hack-dir-local-variables)))
diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el
index 428bf32947b..5af9ea75ed1 100644
--- a/lisp/net/ange-ftp.el
+++ b/lisp/net/ange-ftp.el
@@ -4277,7 +4277,7 @@ NEWNAME should be the name to give the new compressed or uncompressed file.")
4277 nil 4277 nil
4278 t 4278 t
4279 nil 4279 nil
4280 "-c" 4280 shell-command-switch
4281 (format "compress -f -c < %s > %s" tmp1 tmp2)) 4281 (format "compress -f -c < %s > %s" tmp1 tmp2))
4282 (and ange-ftp-process-verbose 4282 (and ange-ftp-process-verbose
4283 (ange-ftp-message "Compressing %s...done" abbr)) 4283 (ange-ftp-message "Compressing %s...done" abbr))
@@ -4313,7 +4313,7 @@ NEWNAME should be the name to give the new compressed or uncompressed file.")
4313 nil 4313 nil
4314 t 4314 t
4315 nil 4315 nil
4316 "-c" 4316 shell-command-switch
4317 (format "uncompress -c < %s > %s" tmp1 tmp2)) 4317 (format "uncompress -c < %s > %s" tmp1 tmp2))
4318 (and ange-ftp-process-verbose 4318 (and ange-ftp-process-verbose
4319 (ange-ftp-message "Uncompressing %s...done" abbr)) 4319 (ange-ftp-message "Uncompressing %s...done" abbr))
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index eb3295ee352..b40e69ef634 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -1370,6 +1370,26 @@ connection if a previous connection has died for some reason."
1370 ;; Mark it as connected. 1370 ;; Mark it as connected.
1371 (tramp-set-connection-property p "connected" t))))))) 1371 (tramp-set-connection-property p "connected" t)))))))
1372 1372
1373;; Default settings for connection-local variables.
1374(defconst tramp-adb-connection-local-default-profile
1375 '((shell-file-name . "/system/bin/sh")
1376 (shell-command-switch . "-c"))
1377 "Default connection-local variables for remote adb connections.")
1378(add-to-list 'tramp-connection-local-safe-shell-file-names "/system/bin/sh")
1379
1380;; `connection-local-set-profile-variables' and
1381;; `connection-local-set-profiles' exists since Emacs 26.1.
1382(eval-after-load "shell"
1383 '(progn
1384 (tramp-compat-funcall
1385 'connection-local-set-profile-variables
1386 'tramp-adb-connection-local-default-profile
1387 tramp-adb-connection-local-default-profile)
1388 (tramp-compat-funcall
1389 'connection-local-set-profiles
1390 `(:application tramp :protocol ,tramp-adb-method)
1391 'tramp-adb-connection-local-default-profile)))
1392
1373(add-hook 'tramp-unload-hook 1393(add-hook 'tramp-unload-hook
1374 (lambda () 1394 (lambda ()
1375 (unload-feature 'tramp-adb 'force))) 1395 (unload-feature 'tramp-adb 'force)))
diff --git a/lisp/net/tramp-integration.el b/lisp/net/tramp-integration.el
index 2a461763480..946d7f8cbab 100644
--- a/lisp/net/tramp-integration.el
+++ b/lisp/net/tramp-integration.el
@@ -27,9 +27,10 @@
27 27
28;;; Code: 28;;; Code:
29 29
30(require 'tramp-compat)
31
30;; Pacify byte-compiler. 32;; Pacify byte-compiler.
31(require 'cl-lib) 33(require 'cl-lib)
32(declare-function tramp-compat-exec-path "tramp")
33(declare-function tramp-dissect-file-name "tramp") 34(declare-function tramp-dissect-file-name "tramp")
34(declare-function tramp-file-name-equal-p "tramp") 35(declare-function tramp-file-name-equal-p "tramp")
35(declare-function tramp-tramp-file-p "tramp") 36(declare-function tramp-tramp-file-p "tramp")
@@ -170,6 +171,37 @@ NAME must be equal to `tramp-current-connection'."
170 (remove-hook 'tramp-cleanup-all-connections-hook 171 (remove-hook 'tramp-cleanup-all-connections-hook
171 #'tramp-recentf-cleanup-all))))) 172 #'tramp-recentf-cleanup-all)))))
172 173
174;;; Default connection-local variables for Tramp:
175
176;;;###tramp-autoload
177(defvar tramp-connection-local-safe-shell-file-names nil
178 "List of safe `shell-file-name' values for remote hosts.")
179(add-to-list 'tramp-connection-local-safe-shell-file-names "/bin/sh")
180
181(defconst tramp-connection-local-default-profile
182 '((shell-file-name . "/bin/sh")
183 (shell-command-switch . "-c"))
184 "Default connection-local variables for remote connections.")
185(put 'shell-file-name 'safe-local-variable
186 (lambda (item)
187 (and (stringp item)
188 (member item tramp-connection-local-safe-shell-file-names))))
189(put 'shell-command-switch 'safe-local-variable
190 (lambda (item) (and (stringp item) (string-equal item "-c"))))
191
192;; `connection-local-set-profile-variables' and
193;; `connection-local-set-profiles' exists since Emacs 26.1.
194(eval-after-load "shell"
195 '(progn
196 (tramp-compat-funcall
197 'connection-local-set-profile-variables
198 'tramp-connection-local-default-profile
199 tramp-connection-local-default-profile)
200 (tramp-compat-funcall
201 'connection-local-set-profiles
202 `(:application tramp)
203 'tramp-connection-local-default-profile)))
204
173(add-hook 'tramp-unload-hook 205(add-hook 'tramp-unload-hook
174 (lambda () (unload-feature 'tramp-integration 'force))) 206 (lambda () (unload-feature 'tramp-integration 'force)))
175 207
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index ee16138f700..d9edcb14198 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -81,6 +81,7 @@ the default storage location, e.g. \"$HOME/.sh_history\"."
81 (const :tag "Unset HISTFILE" t) 81 (const :tag "Unset HISTFILE" t)
82 (string :tag "Redirect to a file"))) 82 (string :tag "Redirect to a file")))
83 83
84;;;###tramp-autoload
84(defconst tramp-display-escape-sequence-regexp "\e[[;0-9]+m" 85(defconst tramp-display-escape-sequence-regexp "\e[[;0-9]+m"
85 "Terminal control escape sequences for display attributes.") 86 "Terminal control escape sequences for display attributes.")
86 87
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index b3f32c82316..3650b05607c 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -1754,15 +1754,16 @@ Returns the compilation buffer created."
1754 (if (fboundp 'make-process) 1754 (if (fboundp 'make-process)
1755 (let ((proc 1755 (let ((proc
1756 (if (eq mode t) 1756 (if (eq mode t)
1757 ;; comint uses `start-file-process'. 1757 ;; On remote hosts, the local `shell-file-name'
1758 (get-buffer-process 1758 ;; might be useless.
1759 (with-no-warnings 1759 (with-connection-local-variables
1760 (comint-exec 1760 ;; comint uses `start-file-process'.
1761 outbuf (downcase mode-name) 1761 (get-buffer-process
1762 (if (file-remote-p default-directory) 1762 (with-no-warnings
1763 "/bin/sh" 1763 (comint-exec
1764 shell-file-name) 1764 outbuf (downcase mode-name)
1765 nil `("-c" ,command)))) 1765 shell-file-name
1766 nil `(,shell-command-switch ,command)))))
1766 (start-file-process-shell-command (downcase mode-name) 1767 (start-file-process-shell-command (downcase mode-name)
1767 outbuf command)))) 1768 outbuf command))))
1768 ;; Make the buffer's mode line show process state. 1769 ;; Make the buffer's mode line show process state.
diff --git a/lisp/shell.el b/lisp/shell.el
index 524a8848840..8a2d4489b8a 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -99,6 +99,7 @@
99 99
100(require 'comint) 100(require 'comint)
101(require 'pcomplete) 101(require 'pcomplete)
102(eval-when-compile (require 'files-x)) ;with-connection-local-variables
102 103
103;;; Customization and Buffer Variables 104;;; Customization and Buffer Variables
104 105
@@ -721,23 +722,17 @@ Otherwise, one argument `-i' is passed to the shell.
721 722
722 (with-current-buffer buffer 723 (with-current-buffer buffer
723 (when (file-remote-p default-directory) 724 (when (file-remote-p default-directory)
724 ;; Apply connection-local variables.
725 (hack-connection-local-variables-apply
726 `(:application tramp
727 :protocol ,(file-remote-p default-directory 'method)
728 :user ,(file-remote-p default-directory 'user)
729 :machine ,(file-remote-p default-directory 'host)))
730
731 ;; On remote hosts, the local `shell-file-name' might be useless. 725 ;; On remote hosts, the local `shell-file-name' might be useless.
732 (if (and (called-interactively-p 'any) 726 (with-connection-local-variables
733 (null explicit-shell-file-name) 727 (if (and (called-interactively-p 'any)
734 (null (getenv "ESHELL"))) 728 (null explicit-shell-file-name)
735 (set (make-local-variable 'explicit-shell-file-name) 729 (null (getenv "ESHELL")))
736 (file-local-name 730 (set (make-local-variable 'explicit-shell-file-name)
737 (expand-file-name 731 (file-local-name
738 (read-file-name 732 (expand-file-name
739 "Remote shell path: " default-directory shell-file-name 733 (read-file-name
740 t shell-file-name))))))) 734 "Remote shell path: " default-directory shell-file-name
735 t shell-file-name))))))))
741 736
742 ;; The buffer's window must be correctly set when we call comint 737 ;; The buffer's window must be correctly set when we call comint
743 ;; (so that comint sets the COLUMNS env var properly). 738 ;; (so that comint sets the COLUMNS env var properly).
diff --git a/lisp/subr.el b/lisp/subr.el
index 5b0330745fa..4024c68e68d 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3185,11 +3185,12 @@ discouraged."
3185 "Start a program in a subprocess. Return the process object for it. 3185 "Start a program in a subprocess. Return the process object for it.
3186Similar to `start-process-shell-command', but calls `start-file-process'." 3186Similar to `start-process-shell-command', but calls `start-file-process'."
3187 (declare (advertised-calling-convention (name buffer command) "23.1")) 3187 (declare (advertised-calling-convention (name buffer command) "23.1"))
3188 (start-file-process 3188 ;; On remote hosts, the local `shell-file-name' might be useless.
3189 name buffer 3189 (with-connection-local-variables
3190 (if (file-remote-p default-directory) "/bin/sh" shell-file-name) 3190 (start-file-process
3191 (if (file-remote-p default-directory) "-c" shell-command-switch) 3191 name buffer
3192 (mapconcat 'identity args " "))) 3192 shell-file-name shell-command-switch
3193 (mapconcat 'identity args " "))))
3193 3194
3194(defun call-process-shell-command (command &optional infile buffer display 3195(defun call-process-shell-command (command &optional infile buffer display
3195 &rest args) 3196 &rest args)