Obey tramp-histfile-override in remote direct async processes
authorMichael Albinus <michael.albinus@gmx.de>
Wed, 29 May 2024 15:11:49 +0000 (17:11 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Wed, 29 May 2024 15:11:49 +0000 (17:11 +0200)
* doc/emacs/custom.texi (Connection Variables):
Mention `permanent-local' symbol property.

* lisp/net/tramp-sh.el (tramp-histfile-override):
Add ;;;###tramp-autoload cookie and `permanent-local' symbol
property.

* lisp/net/tramp.el (tramp-handle-make-process):
Obey `tramp-histfile-override'.  (Bug#71049)

doc/emacs/custom.texi
lisp/net/tramp-sh.el
lisp/net/tramp.el

index 4725af0ee5fea431f8501d5bdd6088d8ab591d17..0d695032d779c51c026b3cfa38e6dcc8849e800f 100644 (file)
@@ -1607,6 +1607,13 @@ matches all buffers with a remote default directory.
 and setting these profiles to criteria which could match in parallel.
 It is unspecified which variable value is used then.
 
+  Be also careful when setting connection-local variables in a buffer,
+which changes its major mode afterwards.  Because all buffer-local
+variables will be killed when changing the major mode, the
+connection-local variable's value would be lost.  You can prevent this
+by setting the respective variable's @code{permanent-local} symbol
+property to non-@code{nil}.
+
 @node Key Bindings
 @section Customizing Key Bindings
 @cindex key bindings
index c079455a444705141c38190ca3937a6fd7f9d92c..615f921944842898e9314c75587f463fb5224da3 100644 (file)
@@ -64,6 +64,7 @@ If it is nil, out-of-the-band copy will be used without a check."
   :group 'tramp
   :type '(choice (const nil) integer))
 
+;;;###tramp-autoload
 (defcustom tramp-histfile-override "~/.tramp_history"
   "When invoking a shell, override the HISTFILE with this value.
 When setting to a string, it redirects the shell history to that
@@ -80,6 +81,8 @@ the default storage location, e.g. \"$HOME/.sh_history\"."
                  (const :tag "Unset HISTFILE" t)
                  (string :tag "Redirect to a file")))
 
+(put 'tramp-histfile-override 'permanent-local t)
+
 ;; ksh on OpenBSD 4.5 requires that $PS1 contains a `#' character for
 ;; root users.  It uses the `$' character for other users.  In order
 ;; to guarantee a proper prompt, we use "#$ " for the prompt.
index 9385b023392cf388154ebf077aec0d9ae45cfcc5..b2442f4538cfa28f64e935be03c5b67d719ad73c 100644 (file)
@@ -4962,6 +4962,18 @@ should be set conmnection-local.")
                              (string-join (tramp-get-remote-path v) ":")))
                        (setenv-internal env "PATH" remote-path 'keep)
                      env))
+              ;; Add HISTFILE if indicated.
+              (env (if-let ((sh-file-name-handler-p))
+                       (cond
+                        ((stringp tramp-histfile-override)
+                         (setenv-internal env "HISTFILE" tramp-histfile-override 'keep))
+                        (tramp-histfile-override
+                         (setq env (setenv-internal env "HISTFILE" "''" 'keep))
+                         (setq env (setenv-internal env "HISTSIZE" "0" 'keep))
+                         (setenv-internal env "HISTFILESIZE" "0" 'keep))
+                        (t env))
+                     env))
+              ;; Add INSIDE_EMACS.
               (env (setenv-internal
                     env "INSIDE_EMACS" (tramp-inside-emacs) 'keep))
               (env (mapcar #'tramp-shell-quote-argument (delq nil env)))