special characters and allow Dired to handle them better. (You can
also use the @kbd{C-u C-x d} command to add @samp{-b} temporarily.)
+@code{dired-listing-switches} can be declared as connection-local
+variable to adjust it to match what a remote system expects
+(@pxref{Connection Variables}).
+
@vindex dired-switches-in-mode-line
Dired displays in the mode line an indication of what were the
switches used to invoke @command{ls}. By default, Dired will try to
@defvar connection-local-default-application
The default application, a symbol, to be applied in
-@code{with-connection-local-variables}. It defaults to @code{tramp},
-but you can let-bind it to change the application temporarily
-(@pxref{Local Variables}).
+@code{with-connection-local-variables} and
+@code{connection-local-value}. It defaults to @code{tramp}, but you
+can let-bind it to change the application temporarily (@pxref{Local
+Variables}).
This variable must not be changed globally.
@end defvar
@defmac connection-local-value symbol &optional application
This macro returns the connection-local value of @var{symbol} for
-@var{application}. If @var{symbol} does not have a connection-local
+@var{application}. If @var{application} is @code{nil}, the value of
+@code{connection-local-default-application} is used.
+
+If @var{symbol} does not have a connection-local
binding, the value is the default binding of the variable.
@end defmac
@item
Remote host does not understand default options for directory listing
-Emacs computes the @command{dired} options based on the local host but
-if the remote host cannot understand the same @command{ls} command,
-then set them with a hook as follows:
+@vindex dired-listing-switches
+Emacs computes the @command{dired} options based on the local host.
+Since @w{Emacs 30}, these options can be set connection-local.
+@ifinfo
+@xref{Connection Variables, , , emacs}.
+@end ifinfo
+
+@lisp
+@group
+(connection-local-set-profile-variables
+ 'my-dired-profile
+ '((dired-listing-switches . "-ahl")))
+@end group
+
+@group
+(connection-local-set-profiles
+ '(:application tramp :machine "remotehost")
+ 'my-dired-profile)
+@end group
+@end lisp
+
+@vindex dired-actual-switches
+In older Emacsen, you can set the @command{dired} options with a hook
+as follows:
@lisp
@group
(add-hook
'dired-before-readin-hook
(lambda ()
- (when (file-remote-p default-directory)
- (setq dired-actual-switches "-al"))))
+ (when (string-equal
+ (file-remote-p default-directory 'host) "remotehost")
+ (setq dired-actual-switches "-ahl"))))
@end group
@end lisp
example, on systems supporting XDG, this runs 'xdg-open' on the
files.
++++
+*** 'dired-listing-switches' handles connection-local values if exist.
+This allows to customize different switches for different remote machines.
+
** Ediff
---
(insert " "
(directory-file-name (file-name-directory default-directory))
":\n"))
- (dired-mode dirname (or switches dired-listing-switches))
+ (dired-mode
+ dirname (or switches (connection-local-value dired-listing-switches)))
(setq mode-name "Virtual Dired"
revert-buffer-function 'dired-virtual-revert
dired-subdir-alist nil)
On systems such as MS-DOS and MS-Windows, which use `ls' emulation in Lisp,
some of the `ls' switches are not supported; see the doc string of
-`insert-directory' in `ls-lisp.el' for more details."
+`insert-directory' in `ls-lisp.el' for more details.
+
+For remote Dired buffers, this option supports connection-local values."
:type 'string
:group 'dired)
;; is passed in directory name syntax
;; if it was the name of a directory at all.
(file-name-directory dirname)))
- (or switches (setq switches dired-listing-switches))
+ (or switches
+ (setq switches (connection-local-value dired-listing-switches)))
(if mode (funcall mode)
(dired-mode dir-or-list switches))
;; default-directory and dired-actual-switches are set now
(expand-file-name (if (listp dired-directory)
(car dired-directory)
dired-directory)))
- (setq-local dired-actual-switches (or switches dired-listing-switches))
+ (setq-local dired-actual-switches
+ (or switches (connection-local-value dired-listing-switches)))
(setq-local font-lock-defaults
'(dired-font-lock-keywords t nil nil beginning-of-line))
(setq-local desktop-save-buffer 'dired-desktop-buffer-misc-data)
;;;###autoload
(defmacro connection-local-value (variable &optional application)
"Return connection-local VARIABLE for APPLICATION in `default-directory'.
-If VARIABLE does not have a connection-local binding, the value
-is the default binding of the variable."
+If APPLICATION is nil, the value of
+`connection-local-default-application' is used.
+If VARIABLE does not have a connection-local binding, the return
+value is the default binding of the variable."
(unless (symbolp variable)
(signal 'wrong-type-argument (list 'symbolp variable)))
`(let (connection-local-variables-alist file-local-variables-alist)
(when (window-live-p window)
(quit-restore-window window 'kill)))))
(with-current-buffer standard-output
- (let ((switches dired-listing-switches))
+ (let ((switches (connection-local-value dired-listing-switches)))
(if (file-symlink-p file)
(setq switches (concat switches " -L")))
;; Use insert-directory-safely, not insert-directory,
;; hook.
(dired-mode-hook (delete 'dired-omit-mode dired-mode-hook)))
(dired (concat auto-save-list-file-prefix "*")
- (concat dired-listing-switches " -t")))
+ (concat (connection-local-value dired-listing-switches) " -t")))
(use-local-map (nconc (make-sparse-keymap) (current-local-map)))
(define-key (current-local-map) "\C-c\C-c" 'recover-session-finish)
(save-excursion
(defun Man-shell-file-name ()
"Return a proper shell file name, respecting remote directories."
(or ; This works also in the local case.
- (with-connection-local-variables shell-file-name)
+ (connection-local-value shell-file-name)
"/bin/sh"))
(defun Man-header-file-path ()
(ange-ftp-switches-ok dired-actual-switches))
(and (boundp 'dired-listing-switches)
(ange-ftp-switches-ok
- dired-listing-switches))
+ (connection-local-value
+ dired-listing-switches)))
"-al")
t no-error)
(gethash directory ange-ftp-files-hashtable)))))