From: Michael Albinus Date: Wed, 1 Nov 2023 15:54:31 +0000 (+0100) Subject: Run `man' also on remote systems X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=861ac933dd8aed1028edc4b9142400e3702874d5;p=emacs.git Run `man' also on remote systems This implements bug#66758 * doc/emacs/programs.texi (Man Page): Describe Man-support-remote-systems. * etc/NEWS: Mention user option 'Man-support-remote-systems'. Fix typos. * lisp/dired.el (Man-support-remote-systems): Declare. (dired-do-man): Use it. Use also `file-local-name'. * lisp/man.el (Man-support-remote-systems): New defcustom. (Man-xref-normal-file): Handle remote files. (Man-default-directory, Man-shell-file-name) (Man-header-file-path): New defuns. (Man-init-defvars): Use octal numbers. (Man-support-local-filenames): Handle remote files. (Man-completion-table): Use `Man-default-directory' and `process-file'. (man): Adapt docstring. (Man-start-calling): Use `Man-default-directory'. (Man-getpage-in-background): Use `Man-default-directory', `Man-shell-file-name', `start-file-process' and `process-file'. Adapt buffer name. (Man-update-manpage): Use `Man-shell-file-name' and `process-file'. (Man-view-header-file): Use `Man-header-file-path'. --- diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi index 40746e03ecc..7746bc8bc23 100644 --- a/doc/emacs/programs.texi +++ b/doc/emacs/programs.texi @@ -1402,6 +1402,13 @@ asynchronously. You can force the invocation to be synchronous by customizing @code{Man-prefer-synchronous-calls} to a non-@code{nil} value. +@vindex Man-support-remote-systems + If the user option @code{Man-support-remote-systems} is +non-@code{nil}, and @code{default-directory} indicates a remote system +(@pxref{Remote Files}), the man page is taken from the remote system. +Calling the @code{man} command with a prefix like @kbd{C-u M-x man} +reverts the value of @code{Man-support-remote-systems} for that call. + @findex woman @cindex manual pages, on MS-DOS/MS-Windows An alternative way of reading manual pages is the @kbd{M-x woman} diff --git a/etc/NEWS b/etc/NEWS index 9c0f28e3fa9..817d53baa78 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -62,15 +62,17 @@ more details. ** Emacs now supports Unicode Standard version 15.1. +** Network Security Manager + +++ -** The Network Security Manager now warns about 3DES by default. +*** The Network Security Manager now warns about 3DES by default. This cypher is no longer recommended owing to a major vulnerability disclosed in 2016, and its small 112 bit key size. Emacs now warns about its use also when 'network-security-level' is set to 'medium' (the default). See 'network-security-protocol-checks'. --- -** The Network Security Manager now warns about <2048 bits in DH key exchange. +*** The Network Security Manager now warns about <2048 bits in DH key exchange. Emacs used to warn for Diffie-Hellman key exchanges with prime numbers smaller than 1024 bits. Since more servers now support it, this number has been bumped to 2048 bits. @@ -149,11 +151,11 @@ When this minor mode is enabled, buttons representing modifier keys are displayed along the tool bar. +++ -** 'd' in the mode line now indicates that the window is dedicated. +** "d" in the mode line now indicates that the window is dedicated. Windows have always been able to be dedicated to a specific buffer; see 'window-dedicated-p'. Now the mode line indicates the dedicated -status of a window, with 'd' appearing in the mode line if a window is -dedicated and 'D' if the window is strongly dedicated. This indicator +status of a window, with "d" appearing in the mode line if a window is +dedicated and "D" if the window is strongly dedicated. This indicator appears before the buffer name, and after the buffer modification and remote buffer indicators (usually "---" together). @@ -164,11 +166,6 @@ dedicated, so it won't be reused by 'display-buffer'. This can be useful for complicated window setups. It is bound to 'C-x w d' globally. -** cl-print -*** You can expand the "..." truncation everywhere. -The code that allowed "..." to be expanded in the *Backtrace* should -now work anywhere the data is generated by `cl-print`. - --- ** New user option 'uniquify-dirname-transform'. This can be used to customize how buffer names are uniquified, by @@ -202,12 +199,14 @@ should now work anywhere the data is generated by 'cl-print'. *** Modes can control the expansion via 'cl-print-expand-ellipsis-function'. +++ -*** There is a new setting 'raw' for 'cl-print-compiled' which causes -byte-compiled functions to be printed in full by 'prin1'. A button on -this output can be activated to disassemble the function. +*** New setting 'raw' for 'cl-print-compiled'. +This setting causes byte-compiled functions to be printed in full by +'prin1'. A button on this output can be activated to disassemble the +function. +++ *** There is a new chapter in the CL manual documenting cl-print.el. +See the Info node "(cl) Printing". ** Modeline elements can now be right-aligned. Anything following the symbol 'mode-line-format-right-align' in @@ -222,10 +221,11 @@ It can be used to add, remove and reorder functions that change the appearance of every tab on the tab bar. +++ -** New optional argument for modifying directory local variables +** New optional argument for modifying directory-local variables. The commands 'add-dir-local-variable', 'delete-dir-local-variable' and 'copy-file-locals-to-dir-locals' now take an optional prefix argument, to enter the file you want to modify. + ** Miscellaneous --- @@ -336,7 +336,7 @@ functions in CJK locales. +++ ** New command 'lldb'. Run the LLDB debugger, analogous to the 'gud-gdb' command. Note that -you might want to add these settings to your .lldbinit file, to reduce +you might want to add these settings to your ".lldbinit" file, to reduce the output in the LLDB output when stepping through source files. settings set stop-line-count-before 0 @@ -396,7 +396,7 @@ switches for shortlogs, such as the one produced by 'C-x v L'. *** Obsolete command 'vc-switch-backend' re-added as 'vc-change-backend'. The command was previously obsoleted and unbound in Emacs 28. -** Diff Mode +** Diff mode +++ *** 'diff-ignore-whitespace-hunk' can now be applied to all hunks. @@ -563,7 +563,7 @@ The command 'makefile-switch-to-browser' command is now obsolete, together with related commands used in the "*Macros and Targets*" buffer. We recommend using an alternative like 'imenu' instead. -** Prog Mode +** Prog mode +++ *** New command 'prog-fill-reindent-defun'. @@ -572,10 +572,10 @@ docstring, or a comment, or (re)indents the surrounding defun if point is not in a comment or a string. It is by default bound to 'M-q' in 'prog-mode' and all its descendants. -** Which Function Mode +** Which Function mode +++ -*** Which Function Mode can now display function names on the header line. +*** Which Function mode can now display function names on the header line. The new user option 'which-func-display' allows choosing where the function name is displayed. The default is 'mode' to display in the mode line. 'header' will display in the header line; @@ -684,13 +684,21 @@ This command adds a docstring comment to the current defun. If a comment already exists, point is only moved to the comment. It is bound to 'C-c C-d' in 'go-ts-mode'. -** Man-mode +** Man mode +++ *** New user option 'Man-prefer-synchronous-call'. When this is non-nil, call the 'man' program synchronously rather than asynchronously (which is the default behavior). ++++ +*** New user option 'Man-support-remote-systems'. +If the user option 'Man-support-remote-systems' is non-nil, and +'default-directory' indicates a remote system, the man page is taken +from the remote system. Calling the 'man' command with a prefix like +'C-u M-x man' reverts the value of 'Man-support-remote-systems' for +that call. + ** DocView --- @@ -757,7 +765,7 @@ distracting and easily confused with actual code, or a significant early aid that relieves you from moving the buffer or reaching for the mouse to consult an error message. -** Python Mode +** Python mode --- *** New user option 'python-indent-block-paren-deeper'. @@ -790,7 +798,7 @@ This keyword enables the user to install packages using 'package-vc'. *** The 'nnweb-type' option 'gmane' has been removed. The gmane.org website is, sadly, down since a number of years with no prospect of it coming back. Therefore, it is no longer valid to set -the user option 'nnweb-type' to the 'gmane'. +the user option 'nnweb-type' to 'gmane'. ** Rmail @@ -875,14 +883,13 @@ CPerl mode supports the new keywords for exception handling and the object oriented syntax which were added in Perl 5.36 and 5.38. *** New user option 'cperl-fontify-trailer'. -This user option takes the values "perl-code" or "comment" and treats +This user option takes the values 'perl-code' or 'comment' and treats text after an "__END__" or "__DATA__" token accordingly. The default -value of "perl-code" is useful for trailing POD and for AutoSplit -modules, the value "comment" makes cperl-mode treat trailers as -comment, like perl-mode does. +value of 'perl-code' is useful for trailing POD and for AutoSplit +modules, the value 'comment' makes CPerl mode treat trailers as +comment, like Perl mode does. *** Commands using the Perl info page are obsolete. - The Perl documentation in info format is no longer distributed with Perl or on CPAN since more than 10 years. Perl documentation can be read with 'cperl-perldoc' instead. @@ -942,11 +949,11 @@ neither of which have been supported by Emacs since version 23.1. The user option 'url-gateway-nslookup-program' and the function 'url-gateway-nslookup-host' are consequently also obsolete. -** socks +** Socks +++ -*** SOCKS supports version 4a. -The 'socks-server' option accepts '4a' as a value for its version +*** Socks supports version 4a. +The 'socks-server' user option accepts '4a' as a value for its version field. ** Edmacro @@ -973,9 +980,10 @@ previously assumed that they should be prefixed with "http://". Such URIs are now prefixed with "https://" instead. ** Customize + +++ -*** New command customize-dirlocals -This command pops up a buffer to edit the settings in .dir-locals.el +*** New command 'customize-dirlocals'. +This command pops up a buffer to edit the settings in ".dir-locals.el". * New Modes and Packages in Emacs 30.1 @@ -1045,8 +1053,8 @@ the file listing's performance is still optimized. * Incompatible Lisp Changes in Emacs 30.1 -** `buffer-match-p and `match-buffers` take `&rest args` -They used to take a single `&optional arg` and were documented to use +** 'buffer-match-p' and 'match-buffers' take '&rest args'. +They used to take a single '&optional arg' and were documented to use an unreliable hack to try and support condition predicates that don't accept this optional arg. The new semantics makes no such accommodation, but the code still @@ -1130,7 +1138,7 @@ The compatibility aliases 'x-defined-colors', 'x-color-defined-p', Use 'define-minor-mode' and 'define-globalized-minor-mode' instead. ** The obsolete calling convention of 'sit-for' has been removed. -That convention was: (sit-for SECONDS MILLISEC &optional NODISP) +That convention was: '(sit-for SECONDS MILLISEC &optional NODISP)'. ** The 'millisec' argument of 'sleep-for' has been declared obsolete. Use a float value for the first argument instead. @@ -1147,7 +1155,7 @@ values. It is now possible for drag-and-drop handler functions to respond to drops incorporating more than one URL. Functions capable of this must set their 'dnd-multiple-handler' symbol properties to a non-nil value. -See the Info node "(elisp)Drag and Drop". +See the Info node "(elisp) Drag and Drop". Incident to this change, the function 'dnd-handle-one-url' has been made obsolete, for it cannot take these new handlers into account. @@ -1165,8 +1173,8 @@ Other features in Emacs which employ XLFDs have been modified to produce and understand XLFDs larger than 255 characters. ** 'defadvice' is marked as obsolete. -See the "(elisp) Porting Old Advice" node for help converting them -to use 'advice-add' or 'define-advice' instead. +See the "(elisp) Porting Old Advice" Info node for help converting +them to use 'advice-add' or 'define-advice' instead. ** 'cl-old-struct-compat-mode' is marked as obsolete. You may need to recompile our code if it was compiled with Emacs < 24.3. @@ -1469,10 +1477,11 @@ When supplied with ':default-language LANGUAGE', rules after it will default to use 'LANGUAGE'. --- -** New optional argument to 'modify-dir-local-variable' +** New optional argument to 'modify-dir-local-variable'. A 5th argument, optional, has been added to 'modify-dir-local-variable'. It can be used to specify which dir-locals file to modify. + * Changes in Emacs 30.1 on Non-Free Operating Systems diff --git a/lisp/dired.el b/lisp/dired.el index 231d305210b..99156b28365 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -4998,6 +4998,7 @@ Interactively with prefix argument, read FILE-NAME." ;;; Miscellaneous commands (declare-function Man-getpage-in-background "man" (topic)) +(defvar Man-support-remote-systems) ; from man.el (defvar manual-program) ; from man.el (defun dired-do-man () @@ -5005,10 +5006,11 @@ Interactively with prefix argument, read FILE-NAME." (interactive nil dired-mode) (require 'man) (let* ((file (dired-get-file-for-visit)) + (Man-support-remote-systems (file-remote-p file)) (manual-program (string-replace "*" "%s" (dired-guess-shell-command "Man command: " (list file))))) - (Man-getpage-in-background file))) + (Man-getpage-in-background (file-local-name file)))) (defun dired-do-info () "In Dired, run `info' on this file." diff --git a/lisp/man.el b/lisp/man.el index 506d6060269..d64a355e3d8 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -105,6 +105,13 @@ When this is non-nil, call the \"man\" program synchronously :group 'man :version "30.1") +(defcustom Man-support-remote-systems nil + "Whether to call the Un*x \"man\" program on remote systems. +When this is non-nil, call the \"man\" program on the remote +system determined by `default-directory'." + :type 'boolean + :version "30.1") + (defcustom Man-filter-list nil "Manpage cleaning filter command phrases. This variable contains a list of the following form: @@ -531,8 +538,9 @@ Otherwise, the value is whatever the function (define-button-type 'Man-xref-normal-file 'action (lambda (button) - (let ((f (substitute-in-file-name - (button-get button 'Man-target-string)))) + (let ((f (concat (file-remote-p default-directory) + (substitute-in-file-name + (button-get button 'Man-target-string))))) (if (file-exists-p f) (if (file-readable-p f) (view-file f) @@ -545,6 +553,63 @@ Otherwise, the value is whatever the function ;; ====================================================================== ;; utilities +(defun Man-default-directory () + "Return a default directory according to `Man-support-remote-systems'." + ;; Ensure that `default-directory' exists and is readable. + ;; We assume, that this function is always called inside the `man' + ;; command, so that we can check `current-prefix-arg' for reverting + ;; `Man-support-remote-systems'. + (let ((result default-directory) + (remote (if current-prefix-arg + (not Man-support-remote-systems) + Man-support-remote-systems))) + + ;; Use a local directory if remote isn't possible. + (when (and (file-remote-p default-directory) + (not (and remote + ;; TODO:: Test that remote processes are supported. + ))) + (setq result (expand-file-name "~/"))) + + ;; Check, whether the directory is accessible. + (if (file-accessible-directory-p result) + result + (expand-file-name (concat (file-remote-p result) "~/"))))) + +(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) + "/bin/sh")) + +(defun Man-header-file-path () + "C Header file search path used in Man. +In the local case, it is the value of `Man-header-file-path'. +Otherwise, it will be checked on the remote system." + (let ((remote-id (file-remote-p default-directory))) + (if (null remote-id) + ;; The local case. + Man-header-file-path + ;; The remote case. Use connection-local variables. + (mapcar + (lambda (elt) (concat remote-id elt)) + (with-connection-local-variables + (or (and (local-variable-p 'Man-header-file-path (current-buffer)) + Man-header-file-path) + (setq-connection-local + Man-header-file-path + (let ((arch (with-temp-buffer + (when (zerop (ignore-errors + (process-file "gcc" nil '(t nil) nil + "-print-multiarch"))) + (goto-char (point-min)) + (buffer-substring (point) (line-end-position))))) + (base '("/usr/include" "/usr/local/include"))) + (if (zerop (length arch)) + base + (append + base (list (expand-file-name arch "/usr/include")))))))))))) + (defun Man-init-defvars () "Used for initializing variables based on display's color support. This is necessary if one wants to dump man.el with Emacs." @@ -583,7 +648,9 @@ This is necessary if one wants to dump man.el with Emacs." (if Man-sed-script (concat "-e '" Man-sed-script "'") "") - "-e '/^[\001-\032][\001-\032]*$/d'" + ;; Use octal numbers. Otherwise, \032 (Ctrl-Z) would + ;; suspend remote connections. + "-e '/^[\\o001-\\o032][\\o001-\\o032]*$/d'" "-e '/\e[789]/s///g'" "-e '/Reformatting page. Wait/d'" "-e '/Reformatting entry. Wait/d'" @@ -717,22 +784,23 @@ program has no such option, but interprets any name containing a \"/\" as a local filename. The function returns either `man-db' `man', or nil." (if (eq Man-support-local-filenames 'auto-detect) - (setq Man-support-local-filenames - (with-temp-buffer - (let ((default-directory - ;; Ensure that `default-directory' exists and is readable. - (if (file-accessible-directory-p default-directory) - default-directory - (expand-file-name "~/")))) - (ignore-errors - (call-process manual-program nil t nil "--help"))) - (cond ((search-backward "--local-file" nil 'move) - 'man-db) - ;; This feature seems to be present in at least ver 1.4f, - ;; which is about 20 years old. - ;; I don't know if this version has an official name? - ((looking-at "^man, versione? [1-9]") - 'man)))) + (with-connection-local-variables + (or (and (local-variable-p 'Man-support-local-filenames (current-buffer)) + Man-support-local-filenames) + (setq-connection-local + Man-support-local-filenames + (with-temp-buffer + (let ((default-directory (Man-default-directory))) + (ignore-errors + (process-file manual-program nil t nil "--help"))) + (cond ((search-backward "--local-file" nil 'move) + 'man-db) + ;; This feature seems to be present in at least + ;; ver 1.4f, which is about 20 years old. I + ;; don't know if this version has an official + ;; name? + ((looking-at "^man, versione? [1-9]") + 'man)))))) Man-support-local-filenames)) @@ -918,7 +986,8 @@ foo(sec)[, bar(sec) [, ...]] [other stuff] - description" (unless (and Man-completion-cache (string-prefix-p (car Man-completion-cache) prefix)) (with-temp-buffer - (setq default-directory "/") ;; in case inherited doesn't exist + ;; In case inherited doesn't exist. + (setq default-directory (Man-default-directory)) ;; Actually for my `man' the arg is a regexp. ;; POSIX says it must be ERE and "man-db" seems to agree, ;; whereas under macOS it seems to be BRE-style and doesn't @@ -932,7 +1001,7 @@ foo(sec)[, bar(sec) [, ...]] [other stuff] - description" ;; error later. (when (eq 0 (ignore-errors - (call-process + (process-file manual-program nil '(t nil) nil "-k" (concat (when (or Man-man-k-use-anchor (string-equal prefix "")) @@ -1016,7 +1085,14 @@ names or descriptions. The pattern argument is usually an Note that in some cases you will need to use \\[quoted-insert] to quote the SPC character in the above examples, because this command attempts -to auto-complete your input based on the installed manual pages." +to auto-complete your input based on the installed manual pages. + +If `default-directory' is remote, and `Man-support-remote-systems' +is non-nil, the man page will be formatted on the corresponding +remote system. + +If `man' is called interactively with a prefix argument, the +value of `Man-support-remote-systems' is reverted." (interactive (list (let* ((default-entry (Man-default-man-entry)) @@ -1082,12 +1158,7 @@ to auto-complete your input based on the installed manual pages." Man-coding-system locale-coding-system)) ;; Avoid possible error by using a directory that always exists. - (default-directory - (if (and (file-directory-p default-directory) - (not (find-file-name-handler default-directory - 'file-directory-p))) - default-directory - "/"))) + (default-directory (Man-default-directory))) ;; Prevent any attempt to use display terminal fanciness. (setenv "TERM" "dumb") ;; In Debian Woody, at least, we get overlong lines under X @@ -1116,9 +1187,13 @@ to auto-complete your input based on the installed manual pages." (defun Man-getpage-in-background (topic) "Use TOPIC to build and fire off the manpage and cleaning command. Return the buffer in which the manpage will appear." - (let* ((man-args topic) - (bufname (concat "*Man " man-args "*")) - (buffer (get-buffer bufname))) + (let* ((default-directory (Man-default-directory)) + (man-args topic) + (bufname + (if (file-remote-p default-directory) + (format "*Man %s %s *" (file-remote-p default-directory) man-args) + (format "*Man %s *" man-args))) + (buffer (get-buffer bufname))) (if buffer (Man-notify-when-ready buffer) (message "Invoking %s %s in the background" manual-program man-args) @@ -1137,20 +1212,19 @@ Return the buffer in which the manpage will appear." (Man-start-calling (if (and (fboundp 'make-process) (not Man-prefer-synchronous-call)) - (let ((proc (start-process + (let ((proc (start-file-process manual-program buffer - (if (memq system-type '(cygwin windows-nt)) - shell-file-name - "sh") + (Man-shell-file-name) shell-command-switch (format (Man-build-man-command) man-args)))) (set-process-sentinel proc 'Man-bgproc-sentinel) (set-process-filter proc 'Man-bgproc-filter)) (let* ((inhibit-read-only t) (exit-status - (call-process shell-file-name nil (list buffer nil) nil - shell-command-switch - (format (Man-build-man-command) man-args))) + (process-file + (Man-shell-file-name) nil (list buffer nil) nil + shell-command-switch + (format (Man-build-man-command) man-args))) (msg "")) (or (and (numberp exit-status) (= exit-status 0)) @@ -1178,9 +1252,10 @@ Return the buffer in which the manpage will appear." (buffer-read-only nil)) (erase-buffer) (Man-start-calling - (call-process shell-file-name nil (list (current-buffer) nil) nil - shell-command-switch - (format (Man-build-man-command) Man-arguments))) + (process-file + (Man-shell-file-name) nil (list (current-buffer) nil) nil + shell-command-switch + (format (Man-build-man-command) Man-arguments))) (if Man-fontify-manpage-flag (Man-fontify-manpage) (Man-cleanup-manpage)) @@ -1944,7 +2019,7 @@ Specify which REFERENCE to use; default is based on word at point." ;; Header file support (defun Man-view-header-file (file) "View a header file specified by FILE from `Man-header-file-path'." - (let ((path Man-header-file-path) + (let ((path (Man-header-file-path)) complete-path) (while path (setq complete-path (expand-file-name file (car path))