diff options
| author | Michael Albinus | 2017-04-02 11:02:54 +0200 |
|---|---|---|
| committer | Michael Albinus | 2017-04-02 11:02:54 +0200 |
| commit | 59191cd0cbe8463f9095a71cb4048bb138d6e446 (patch) | |
| tree | ea0e063deb25c07c6e315b02d3db427e25e917b8 | |
| parent | 21918f4e1c5939038c7e8d0b8b8e8a647c086796 (diff) | |
| download | emacs-59191cd0cbe8463f9095a71cb4048bb138d6e446.tar.gz emacs-59191cd0cbe8463f9095a71cb4048bb138d6e446.zip | |
Apply connecion-local variables for shells
* doc/misc/tramp.texi (Remote processes): Show use of connection-local
variables. Don't mention Emacs 23 anymore.
(Frequently Asked Questions): Precise Emacs and MS Windows version.
* lisp/files-x.el (connection-local-normalize-criteria):
Suppress nil properties.
(connection-local-set-profiles, with-connection-local-profiles):
Adapt docstring.
* lisp/shell.el (shell): Apply connecion-local variables.
| -rw-r--r-- | doc/misc/tramp.texi | 50 | ||||
| -rw-r--r-- | lisp/files-x.el | 14 | ||||
| -rw-r--r-- | lisp/shell.el | 67 |
3 files changed, 86 insertions, 45 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index e1d84457ff9..8e04d69c199 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi | |||
| @@ -2499,6 +2499,42 @@ Starting with Emacs 24, when @option{explicit-shell-file-name} is | |||
| 2499 | equal to @code{nil}, calling @code{shell} interactively will prompt | 2499 | equal to @code{nil}, calling @code{shell} interactively will prompt |
| 2500 | for a shell name. | 2500 | for a shell name. |
| 2501 | 2501 | ||
| 2502 | Starting with Emacs 26, you could use connection-local variables for | ||
| 2503 | setting different values of @option{explicit-shell-file-name} for | ||
| 2504 | different remote hosts. | ||
| 2505 | @ifinfo | ||
| 2506 | @pxref{Connection Local Variables, , , elisp} | ||
| 2507 | @end ifinfo | ||
| 2508 | |||
| 2509 | @lisp | ||
| 2510 | @group | ||
| 2511 | (connection-local-set-profile-variables | ||
| 2512 | 'remote-bash | ||
| 2513 | '((explicit-shell-file-name . "/bin/bash") | ||
| 2514 | (explicit-bash-args . ("-i")))) | ||
| 2515 | @end group | ||
| 2516 | |||
| 2517 | @group | ||
| 2518 | (connection-local-set-profile-variables | ||
| 2519 | 'remote-ksh | ||
| 2520 | '((explicit-shell-file-name . "/bin/ksh") | ||
| 2521 | (explicit-ksh-args . ("-i")))) | ||
| 2522 | @end group | ||
| 2523 | |||
| 2524 | @group | ||
| 2525 | (connection-local-set-profiles | ||
| 2526 | '(:application 'tramp :protocol "ssh" :machine "localhost") | ||
| 2527 | 'remote-bash) | ||
| 2528 | @end group | ||
| 2529 | |||
| 2530 | @group | ||
| 2531 | (connection-local-set-profiles | ||
| 2532 | `(:application 'tramp :protocol "sudo" | ||
| 2533 | :user "root" :machine ,(system-name)) | ||
| 2534 | 'remote-ksh) | ||
| 2535 | @end group | ||
| 2536 | @end lisp | ||
| 2537 | |||
| 2502 | 2538 | ||
| 2503 | @subsection Running @code{shell-command} on a remote host | 2539 | @subsection Running @code{shell-command} on a remote host |
| 2504 | @cindex shell-command | 2540 | @cindex shell-command |
| @@ -2542,11 +2578,10 @@ uid=0(root) gid=0(root) groups=0(root) | |||
| 2542 | @end group | 2578 | @end group |
| 2543 | @end example | 2579 | @end example |
| 2544 | 2580 | ||
| 2545 | @code{eshell} in Emacs 23.2 added custom @code{su} and @code{sudo} | 2581 | @code{eshell} added custom @code{su} and @code{sudo} commands that set |
| 2546 | commands that set the default directory correctly for the | 2582 | the default directory correctly for the @file{*eshell*} buffer. |
| 2547 | @file{*eshell*} buffer. @value{tramp} silently updates | 2583 | @value{tramp} silently updates @option{tramp-default-proxies-alist} |
| 2548 | @option{tramp-default-proxies-alist} with an entry for this directory | 2584 | with an entry for this directory (@pxref{Multi-hops}): |
| 2549 | (@pxref{Multi-hops}): | ||
| 2550 | 2585 | ||
| 2551 | @example | 2586 | @example |
| 2552 | @group | 2587 | @group |
| @@ -2763,11 +2798,12 @@ Where is the latest @value{tramp}? | |||
| 2763 | @item | 2798 | @item |
| 2764 | Which systems does it work on? | 2799 | Which systems does it work on? |
| 2765 | 2800 | ||
| 2766 | The package works successfully on Emacs 23, Emacs 24, and Emacs 25. | 2801 | The package works successfully on Emacs 23, Emacs 24, Emacs 25, and |
| 2802 | Emacs 26. | ||
| 2767 | 2803 | ||
| 2768 | While Unix and Unix-like systems are the primary remote targets, | 2804 | While Unix and Unix-like systems are the primary remote targets, |
| 2769 | @value{tramp} has equal success connecting to other platforms, such as | 2805 | @value{tramp} has equal success connecting to other platforms, such as |
| 2770 | MS Windows XP/Vista/7. | 2806 | MS Windows 7/8/10. |
| 2771 | 2807 | ||
| 2772 | 2808 | ||
| 2773 | @item | 2809 | @item |
diff --git a/lisp/files-x.el b/lisp/files-x.el index a0cad708425..b7c6f51e658 100644 --- a/lisp/files-x.el +++ b/lisp/files-x.el | |||
| @@ -585,7 +585,7 @@ Return a new ordered plist list containing only property names from PROPERTIES." | |||
| 585 | nil | 585 | nil |
| 586 | (mapcar | 586 | (mapcar |
| 587 | (lambda (property) | 587 | (lambda (property) |
| 588 | (when (plist-member criteria property) | 588 | (when (and (plist-member criteria property) (plist-get criteria property)) |
| 589 | (list property (plist-get criteria property)))) | 589 | (list property (plist-get criteria property)))) |
| 590 | properties))) | 590 | properties))) |
| 591 | 591 | ||
| @@ -606,12 +606,10 @@ using this connection, see `connection-local-criteria-alist'." | |||
| 606 | 606 | ||
| 607 | ;;;###autoload | 607 | ;;;###autoload |
| 608 | (defun connection-local-set-profiles (criteria &rest profiles) | 608 | (defun connection-local-set-profiles (criteria &rest profiles) |
| 609 | "Add PROFILES for remote servers. | 609 | "Add PROFILES for CRITERIA. |
| 610 | CRITERIA is either a regular expression identifying a remote | 610 | CRITERIA is a plist identifying a connection and the application |
| 611 | server, or a function with one argument IDENTIFICATION, which | 611 | using this connection, see `connection-local-criteria-alist'. |
| 612 | returns non-nil when a remote server shall apply PROFILE's | 612 | PROFILES are the names of connection profiles (a symbol). |
| 613 | variables. If CRITERIA is nil, it always applies. | ||
| 614 | PROFILES are the names of a connection profile (a symbol). | ||
| 615 | 613 | ||
| 616 | When a connection to a remote server is opened and CRITERIA | 614 | When a connection to a remote server is opened and CRITERIA |
| 617 | matches to that server, the connection-local variables from | 615 | matches to that server, the connection-local variables from |
| @@ -678,7 +676,7 @@ will not be changed." | |||
| 678 | ;;;###autoload | 676 | ;;;###autoload |
| 679 | (defmacro with-connection-local-profiles (profiles &rest body) | 677 | (defmacro with-connection-local-profiles (profiles &rest body) |
| 680 | "Apply connection-local variables according to PROFILES in current buffer. | 678 | "Apply connection-local variables according to PROFILES in current buffer. |
| 681 | Execute BODY, and unwind connection local variables." | 679 | Execute BODY, and unwind connection-local variables." |
| 682 | (declare (indent 1) (debug t)) | 680 | (declare (indent 1) (debug t)) |
| 683 | `(let ((enable-connection-local-variables t) | 681 | `(let ((enable-connection-local-variables t) |
| 684 | (old-buffer-local-variables (buffer-local-variables)) | 682 | (old-buffer-local-variables (buffer-local-variables)) |
diff --git a/lisp/shell.el b/lisp/shell.el index c8a8555d632..55a053295fa 100644 --- a/lisp/shell.el +++ b/lisp/shell.el | |||
| @@ -711,36 +711,43 @@ Otherwise, one argument `-i' is passed to the shell. | |||
| 711 | ;; If the current buffer is a dead shell buffer, use it. | 711 | ;; If the current buffer is a dead shell buffer, use it. |
| 712 | (current-buffer))) | 712 | (current-buffer))) |
| 713 | 713 | ||
| 714 | ;; On remote hosts, the local `shell-file-name' might be useless. | 714 | (with-current-buffer buffer |
| 715 | (if (and (called-interactively-p 'any) | 715 | (when (file-remote-p default-directory) |
| 716 | (file-remote-p default-directory) | 716 | ;; Apply connection-local variables. |
| 717 | (null explicit-shell-file-name) | 717 | (hack-connection-local-variables-apply |
| 718 | (null (getenv "ESHELL"))) | 718 | `(:application 'tramp |
| 719 | (with-current-buffer buffer | 719 | :protocol ,(file-remote-p default-directory 'method) |
| 720 | (set (make-local-variable 'explicit-shell-file-name) | 720 | :user ,(file-remote-p default-directory 'user) |
| 721 | (expand-file-name | 721 | :machine ,(file-remote-p default-directory 'host))) |
| 722 | (file-local-name | 722 | |
| 723 | (read-file-name | 723 | ;; On remote hosts, the local `shell-file-name' might be useless. |
| 724 | "Remote shell path: " default-directory shell-file-name | 724 | (if (and (called-interactively-p 'any) |
| 725 | t shell-file-name)))))) | 725 | (null explicit-shell-file-name) |
| 726 | 726 | (null (getenv "ESHELL"))) | |
| 727 | ;; The buffer's window must be correctly set when we call comint (so | 727 | (set (make-local-variable 'explicit-shell-file-name) |
| 728 | ;; that comint sets the COLUMNS env var properly). | 728 | (expand-file-name |
| 729 | (pop-to-buffer buffer) | 729 | (file-local-name |
| 730 | (unless (comint-check-proc buffer) | 730 | (read-file-name |
| 731 | (let* ((prog (or explicit-shell-file-name | 731 | "Remote shell path: " default-directory shell-file-name |
| 732 | (getenv "ESHELL") shell-file-name)) | 732 | t shell-file-name)))))) |
| 733 | (name (file-name-nondirectory prog)) | 733 | |
| 734 | (startfile (concat "~/.emacs_" name)) | 734 | ;; The buffer's window must be correctly set when we call comint |
| 735 | (xargs-name (intern-soft (concat "explicit-" name "-args")))) | 735 | ;; (so that comint sets the COLUMNS env var properly). |
| 736 | (unless (file-exists-p startfile) | 736 | (pop-to-buffer buffer) |
| 737 | (setq startfile (concat user-emacs-directory "init_" name ".sh"))) | 737 | (unless (comint-check-proc buffer) |
| 738 | (apply 'make-comint-in-buffer "shell" buffer prog | 738 | (let* ((prog (or explicit-shell-file-name |
| 739 | (if (file-exists-p startfile) startfile) | 739 | (getenv "ESHELL") shell-file-name)) |
| 740 | (if (and xargs-name (boundp xargs-name)) | 740 | (name (file-name-nondirectory prog)) |
| 741 | (symbol-value xargs-name) | 741 | (startfile (concat "~/.emacs_" name)) |
| 742 | '("-i"))) | 742 | (xargs-name (intern-soft (concat "explicit-" name "-args")))) |
| 743 | (shell-mode))) | 743 | (unless (file-exists-p startfile) |
| 744 | (setq startfile (concat user-emacs-directory "init_" name ".sh"))) | ||
| 745 | (apply 'make-comint-in-buffer "shell" buffer prog | ||
| 746 | (if (file-exists-p startfile) startfile) | ||
| 747 | (if (and xargs-name (boundp xargs-name)) | ||
| 748 | (symbol-value xargs-name) | ||
| 749 | '("-i"))) | ||
| 750 | (shell-mode)))) | ||
| 744 | buffer) | 751 | buffer) |
| 745 | 752 | ||
| 746 | ;;; Directory tracking | 753 | ;;; Directory tracking |