commit 407b88333bec69faba2d9d0a889a556e01247a76 (HEAD, refs/remotes/origin/master) Author: Juri Linkov Date: Tue May 14 09:55:52 2024 +0300 Add documentation about sorting Imenu completions (bug#70846) * doc/emacs/programs.texi (Imenu): Document how Imenu completions can be sorted. * lisp/imenu.el (imenu-sort-function): Explain in the docstring how to sort Imenu completions. diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi index 01a1462044c..8ab5033795d 100644 --- a/doc/emacs/programs.texi +++ b/doc/emacs/programs.texi @@ -378,6 +378,10 @@ they occur in the buffer; if you want alphabetic sorting, use the symbol @code{imenu--sort-by-name} as the value. You can also define your own comparison function by writing Lisp code. + You can also customize how Imenu completions are sorted by changing +the variable @code{completion-category-overrides} and setting its +@code{display-sort-function} for the category @code{imenu}. + If Eglot is activated for the current buffer's project (@pxref{Projects}) and the current buffer's major mode, Eglot provides its own facility for producing the buffer's index based on the diff --git a/etc/NEWS b/etc/NEWS index 5ecc385fa5b..7b429414a7f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1046,6 +1046,11 @@ point is not in a comment or a string. It is by default bound to It defines whether to flatten the list of sections in an imenu or show it nested. ++++ +*** Imenu completions now can be sorted. +You can customize the option 'completion-category-overrides' +and set 'display-sort-function' for the category 'imenu'. + ** Which Function mode +++ diff --git a/lisp/imenu.el b/lisp/imenu.el index 2b1d4f5ce85..ea097f5da3a 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -115,7 +115,10 @@ Useful things to use here include `reposition-window', `recenter', and (defcustom imenu-sort-function nil "The function to use for sorting the index mouse-menu. -Affects only the mouse index menu. +Affects only the mouse index menu. If you want to change +the sorting order of completions, you can customize +the option `completion-category-overrides' and set +`display-sort-function' for the category `imenu'. Set this to nil if you don't want any sorting (faster). The items in the menu are then presented in the order they were found commit f6d060b39a02da14aa1763bb688cb2e048f0c666 Author: Eli Zaretskii Date: Tue May 14 08:51:13 2024 +0300 ; Fix documentation of recently-installed changes * lisp/emacs-lisp/bytecomp.el (compilation-safety): Doc fix. * etc/NEWS: Fix wording of the 'compilation-safety' entry. * doc/lispref/functions.texi (Declare Form): Fix cross-reference and wording. * doc/lispref/compile.texi (Native-Compilation Variables): Add the missing @anchor. Fix wording. diff --git a/doc/lispref/compile.texi b/doc/lispref/compile.texi index f8f1242586e..9f93fb4a981 100644 --- a/doc/lispref/compile.texi +++ b/doc/lispref/compile.texi @@ -987,21 +987,23 @@ form, @pxref{Declare Form}.) The default value is 2. @end defopt +@anchor{compilation-safety} @defopt compilation-safety -This variable specifies the safetyness level used for the code emitted -native code. The value of compilation-safety should be a number between -zero and one with the following meaning: +This variable specifies the safety level to be used for the emitted +native code. The value should be a number, either 0 or 1 with the +following meanings: @table @asis @item 0 -Emitted code can misbehave or crash Emacs if function declarations are -not correct and the function is native compiled. +Emitted code can misbehave (up to even crashing Emacs) if a function's +declaration does not describe correctly what the function does or how it +is called, and the function is natively compiled. @item 1 -Emitted code is generated in a safe matter even if function are -miss-declared." +Emitted code must be generated in a safe manner even if functions are +mis-declared. @end table -This can be controlled at function granularity as well by using the +This can also be controlled at a function granularity, by using the @code{safety} @code{declare} form, @pxref{Declare Form}. @end defopt diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index 9d4ecd8da25..deca99960c7 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -2761,10 +2761,11 @@ argument of type @var{string} and return one of the symbols For description of additional types, see @ref{Lisp Data Types}). Declaring a function with an incorrect type produces undefined behavior -and could lead to unexpected results or might even crash Emacs when code -is native-compiled and loaded if compiled with @ref{compilation-safety} -0. Note also that when redefining (or advising) a type declared -function the replacement should respect the original signature to avoid +and could lead to unexpected results or might even crash Emacs when +natively-compiled code is loaded, if it was compiled with +@code{compilation-safety} level of zero (@pxref{compilation-safety}). +Note also that when redefining (or advising) a type-declared function, +the replacement should respect the original signature to avoid such undefined behavior. @item no-font-lock-keyword diff --git a/etc/NEWS b/etc/NEWS index 5f131386a43..5ecc385fa5b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1986,9 +1986,11 @@ unibyte string. * Lisp Changes in Emacs 30.1 +++ -** New 'compilation-safety' compilation parameter. -It's now possible to use the safety parameter to control how safe is -code generated by the native compiler. +** New user option 'compilation-safety' to control safety of native code. +It's now possible to control how safe is the code generated by native +compilation, by customizing this user option. It is also possible to +control this at function granularity by using the new 'safety' parameter +in the function's 'declare' form. ** New types 'closure' and 'interpreted-function'. 'interpreted-function' is the new type used for interpreted functions, diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 3e7674eeef6..12b45f9f5b8 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -138,11 +138,14 @@ :group 'lisp) (defcustom compilation-safety 1 - "Safety level for compilation. + "Safety level for generated compiled code. Possible values are: -0 emitted code can misbehave or crash Emacs if function declarations are not -correct. -1 emitted code is generated in a safe matter even if function are miss-declared." + 0 - emitted code can misbehave, even crash Emacs, if declarations of + functions do not correctly describe their actual behavior; + 1 - emitted code is to be generated in a safe manner, even if functions + are mis-declared. + +This currently affects only code produced by native-compilation." :type 'integer :safe #'integerp :version "30.1") commit fff245c52931fc829877ae379e48b373c15a1dcb Author: Po Lu Date: Tue May 14 10:16:18 2024 +0800 Fix failure of `restart-emacs' to restart Emacs on Android * src/emacs.c (Fkill_emacs) [HAVE_ANDROID && !ANDROID_STUBIFY]: Arrange to terminate Emacs upon receipt of a bus error. diff --git a/src/emacs.c b/src/emacs.c index 58c751eaa6a..f122955884e 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -3005,7 +3005,9 @@ killed. */ #if defined HAVE_ANDROID && !defined ANDROID_STUBIFY if (android_init_gui) { - /* Calls to exit may be followed by illegal accesses from + struct sigaction sa; + + /* Calls to exit may be followed by invalid accesses from toolkit-managed threads as the thread group is destroyed, which are inconsequential when the process is being terminated, but which must be suppressed to inhibit reporting of superfluous @@ -3013,8 +3015,10 @@ killed. */ Execution won't return to Emacs whatever the value of RESTART, as `android_restart_emacs' will only ever abort or succeed. */ - signal (SIGBUS, SIG_IGN); - signal (SIGSEGV, SIG_IGN); + sigemptyset (&sa.sa_mask); + sa.sa_handler = _exit; + sigaction (SIGSEGV, &sa, NULL); + sigaction (SIGBUS, &sa, NULL); } #endif /* HAVE_ANDROID && !ANDROID_STUBIFY */ commit 8dccc586ea4e927226585d15386cd935b15e9464 Author: Andrea Corallo Date: Tue May 7 10:19:22 2024 +0200 * etc/NEWS (Safety compilation parameter): Add entry. diff --git a/etc/NEWS b/etc/NEWS index 4f2c59a1300..5f131386a43 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1985,6 +1985,10 @@ unibyte string. * Lisp Changes in Emacs 30.1 ++++ +** New 'compilation-safety' compilation parameter. +It's now possible to use the safety parameter to control how safe is +code generated by the native compiler. ** New types 'closure' and 'interpreted-function'. 'interpreted-function' is the new type used for interpreted functions, commit 04e7078d5e2a61c92e61946ffedea25c11951dec Author: Andrea Corallo Date: Sat May 4 08:55:56 2024 +0200 Add some 'compilation-safety' documentation * lisp/emacs-lisp/bytecomp.el (compilation-safety): Better doc. * doc/lispref/functions.texi (Declare Form): Add 'safety'. * doc/lispref/compile.texi (Native-Compilation Variables): Add 'compilation-safety'. diff --git a/doc/lispref/compile.texi b/doc/lispref/compile.texi index 19451f31740..f8f1242586e 100644 --- a/doc/lispref/compile.texi +++ b/doc/lispref/compile.texi @@ -987,6 +987,24 @@ form, @pxref{Declare Form}.) The default value is 2. @end defopt +@defopt compilation-safety +This variable specifies the safetyness level used for the code emitted +native code. The value of compilation-safety should be a number between +zero and one with the following meaning: + +@table @asis +@item 0 +Emitted code can misbehave or crash Emacs if function declarations are +not correct and the function is native compiled. +@item 1 +Emitted code is generated in a safe matter even if function are +miss-declared." +@end table + +This can be controlled at function granularity as well by using the +@code{safety} @code{declare} form, @pxref{Declare Form}. +@end defopt + @defopt native-comp-debug This variable specifies the level of debugging information produced by native-compilation. Its value should be a number between zero and 3, diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index a77bf6e233d..9d4ecd8da25 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -2709,6 +2709,12 @@ native code emitted for the function. In particular, if @var{n} is @minus{}1, native compilation of the function will emit bytecode instead of native code for the function. +@item (safety @var{n}) +Specify the value of @code{compilation-safety} in effect for this +function. This allows function-level control of the safety level used +for the code emitted for the function (@pxref{Native-Compilation +Variables}). + @item (type @var{type}) Declare @var{type} to be the type of this function. This is used for documentation by @code{describe-function}. Also it can be used by the @@ -2756,9 +2762,10 @@ For description of additional types, see @ref{Lisp Data Types}). Declaring a function with an incorrect type produces undefined behavior and could lead to unexpected results or might even crash Emacs when code -is native-compiled and loaded. Note also that when redefining (or -advising) a type declared function the replacement should respect the -original signature to avoid undefined behavior. +is native-compiled and loaded if compiled with @ref{compilation-safety} +0. Note also that when redefining (or advising) a type declared +function the replacement should respect the original signature to avoid +undefined behavior. @item no-font-lock-keyword This is valid for macros only. Macros with this declaration are diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 732a1629177..3e7674eeef6 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -138,7 +138,11 @@ :group 'lisp) (defcustom compilation-safety 1 - "Safety level." + "Safety level for compilation. +Possible values are: +0 emitted code can misbehave or crash Emacs if function declarations are not +correct. +1 emitted code is generated in a safe matter even if function are miss-declared." :type 'integer :safe #'integerp :version "30.1") commit 9e4e6d0fc904e8a57c8433c40d6e3e9a230773d9 Author: Andrea Corallo Date: Fri May 3 22:45:04 2024 +0200 Add 'safety' function declaration * lisp/emacs-lisp/comp.el (comp-known-predicates): Use 'comp-func-safety'. (comp-ctxt, comp-mvar-type-hint-match-p): New 'safety' slot. (comp-c-func-name): New function. (comp--spill-lap-function, comp--intern-func-in-ctxt): Update. * lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Spill safety. * lisp/emacs-lisp/byte-run.el (byte-run--set-completion): New alias. (defun-declarations-alist): Update. diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el index f9e86d88806..2acd22d0a6a 100644 --- a/lisp/emacs-lisp/byte-run.el +++ b/lisp/emacs-lisp/byte-run.el @@ -193,6 +193,11 @@ So far, FUNCTION can only be a symbol, not a lambda expression." (list 'function-put (list 'quote f) ''speed (list 'quote val)))) +(defalias 'byte-run--set-safety + #'(lambda (f _args val) + (list 'function-put (list 'quote f) + ''safety (list 'quote val)))) + (defalias 'byte-run--set-completion #'(lambda (f _args val) (list 'function-put (list 'quote f) @@ -242,6 +247,7 @@ If `error-free', drop calls even if `byte-compile-delete-errors' is nil.") (list 'doc-string #'byte-run--set-doc-string) (list 'indent #'byte-run--set-indent) (list 'speed #'byte-run--set-speed) + (list 'safety #'byte-run--set-safety) (list 'completion #'byte-run--set-completion) (list 'modes #'byte-run--set-modes) (list 'interactive-args #'byte-run--set-interactive-args) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index e0bcdce502b..732a1629177 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -2449,6 +2449,7 @@ With argument ARG, insert value in current buffer after the form." (when byte-native-compiling (defvar native-comp-speed) (push `(native-comp-speed . ,native-comp-speed) byte-native-qualities) + (push `(compilation-safety . ,compilation-safety) byte-native-qualities) (defvar native-comp-debug) (push `(native-comp-debug . ,native-comp-debug) byte-native-qualities) (defvar native-comp-compiler-options) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 0536b45d118..f9fa83da585 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -368,6 +368,8 @@ Returns ELT." :documentation "Target output file-name for the compilation.") (speed native-comp-speed :type number :documentation "Default speed for this compilation unit.") + (safety compilation-safety :type number + :documentation "Default safety level for this compilation unit.") (debug native-comp-debug :type number :documentation "Default debug level for this compilation unit.") (compiler-options native-comp-compiler-options :type list @@ -527,6 +529,8 @@ CFG is mutated by a pass.") :documentation "t if non local jumps are present.") (speed nil :type number :documentation "Optimization level (see `native-comp-speed').") + (safety nil :type number + :documentation "Safety level (see `safety').") (pure nil :type boolean :documentation "t if pure nil otherwise.") (declared-type nil :type list @@ -698,6 +702,11 @@ current instruction or its cell." (or (comp--spill-decl-spec function-name 'speed) (comp-ctxt-speed comp-ctxt))) +(defun comp--spill-safety (function-name) + "Return the safety level for FUNCTION-NAME." + (or (comp--spill-decl-spec function-name 'safety) + (comp-ctxt-safety comp-ctxt))) + ;; Autoloaded as might be used by `disassemble-internal'. ;;;###autoload (defun comp-c-func-name (name prefix &optional first) @@ -824,6 +833,7 @@ clashes." (comp-func-lap func) lap (comp-func-frame-size func) (comp--byte-frame-size byte-func) (comp-func-speed func) (comp--spill-speed name) + (comp-func-safety func) (comp--spill-safety name) (comp-func-declared-type func) (comp--spill-decl-spec name 'function-type) (comp-func-pure func) (comp--spill-decl-spec name 'pure)) @@ -850,6 +860,8 @@ clashes." (comp-el-to-eln-filename filename native-compile-target-directory))) (setf (comp-ctxt-speed comp-ctxt) (alist-get 'native-comp-speed byte-native-qualities) + (comp-ctxt-safety comp-ctxt) (alist-get 'compilation-safety + byte-native-qualities) (comp-ctxt-debug comp-ctxt) (alist-get 'native-comp-debug byte-native-qualities) (comp-ctxt-compiler-options comp-ctxt) (alist-get 'native-comp-compiler-options commit 13ddfc201108bfc71c7fa9040ee9970e929070cf Author: Andrea Corallo Date: Fri May 3 22:21:20 2024 +0200 Introduce 'compilation-safety' variable * lisp/emacs-lisp/bytecomp.el (compilation-safety): New customize. * src/comp.c (comp_t): Add func_safety. (emit_call_with_type_hint, emit_call2_with_type_hint): Make use of. (compile_function): Set 'comp.func_safety'. diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index d9890b5c37a..e0bcdce502b 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -137,6 +137,12 @@ "Emacs Lisp byte-compiler." :group 'lisp) +(defcustom compilation-safety 1 + "Safety level." + :type 'integer + :safe #'integerp + :version "30.1") + (defcustom emacs-lisp-file-regexp "\\.el\\'" "Regexp which matches Emacs Lisp source files. If you change this, you might want to set `byte-compile-dest-file-function'. diff --git a/src/comp.c b/src/comp.c index 4e779cdf898..e8945df63ff 100644 --- a/src/comp.c +++ b/src/comp.c @@ -633,6 +633,7 @@ typedef struct { gcc_jit_function *func; /* Current function being compiled. */ bool func_has_non_local; /* From comp-func has-non-local slot. */ EMACS_INT func_speed; /* From comp-func speed slot. */ + EMACS_INT func_safety; /* From comp-func safety slot. */ gcc_jit_block *block; /* Current basic block being compiled. */ gcc_jit_lvalue *scratch; /* Used as scratch slot for some code sequence (switch). */ ptrdiff_t frame_size; /* Size of the following array in elements. */ @@ -2586,7 +2587,8 @@ emit_call_with_type_hint (gcc_jit_function *func, Lisp_Object insn, Lisp_Object type) { bool hint_match = - !NILP (CALL2I (comp-mvar-type-hint-match-p, SECOND (insn), type)); + !comp.func_safety + && !NILP (CALL2I (comp-mvar-type-hint-match-p, SECOND (insn), type)); gcc_jit_rvalue *args[] = { emit_mvar_rval (SECOND (insn)), gcc_jit_context_new_rvalue_from_int (comp.ctxt, @@ -2602,7 +2604,8 @@ emit_call2_with_type_hint (gcc_jit_function *func, Lisp_Object insn, Lisp_Object type) { bool hint_match = - !NILP (CALL2I (comp-mvar-type-hint-match-p, SECOND (insn), type)); + !comp.func_safety + && !NILP (CALL2I (comp-mvar-type-hint-match-p, SECOND (insn), type)); gcc_jit_rvalue *args[] = { emit_mvar_rval (SECOND (insn)), emit_mvar_rval (THIRD (insn)), @@ -4282,6 +4285,7 @@ compile_function (Lisp_Object func) comp.func_has_non_local = !NILP (CALL1I (comp-func-has-non-local, func)); comp.func_speed = XFIXNUM (CALL1I (comp-func-speed, func)); + comp.func_safety = XFIXNUM (CALL1I (comp-func-safety, func)); comp.func_relocs_local = gcc_jit_function_new_local (comp.func, commit 595799edd3188a8992bbd08d0b29feaf184a092e Author: Andrea Corallo Date: Mon May 13 16:41:25 2024 +0200 * lisp/emacs-lisp/comp.el (comp--get-function-cstr): Fix it. diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index fa866b802cc..0536b45d118 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -197,12 +197,11 @@ Useful to hook into pass checkers.") (defun comp--get-function-cstr (function) "Given FUNCTION return the corresponding `comp-constraint'." (when (symbolp function) - (let ((f (symbol-function function))) - (or (gethash f comp-primitive-func-cstr-h) - (when-let ((type (or (when-let ((f (comp--symbol-func-to-fun function))) - (comp-func-declared-type f)) - (function-get function 'function-type)))) - (comp-type-spec-to-cstr type)))))) + (or (gethash function comp-primitive-func-cstr-h) + (when-let ((type (or (when-let ((f (comp--symbol-func-to-fun function))) + (comp-func-declared-type f)) + (function-get function 'function-type)))) + (comp-type-spec-to-cstr type))))) ;; Keep it in sync with the `cl-deftype-satisfies' property set in ;; cl-macs.el. We can't use `cl-deftype-satisfies' directly as the commit e86c4d8bdc8bdbc959a1f7f03576205ce707743e Author: Dmitry Gutov Date: Mon May 13 16:16:22 2024 +0300 ; Fix the xref--group-name-for-display tests diff --git a/test/lisp/progmodes/xref-tests.el b/test/lisp/progmodes/xref-tests.el index 89051256273..39eab7c7fd1 100644 --- a/test/lisp/progmodes/xref-tests.el +++ b/test/lisp/progmodes/xref-tests.el @@ -132,6 +132,7 @@ (lambda (loc) (xref--group-name-for-display (xref-location-group loc) + nil nil)) (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)"))) (list @@ -145,6 +146,7 @@ (lambda (loc) (xref--group-name-for-display (xref-location-group loc) + nil nil)) (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)"))) (list @@ -161,7 +163,8 @@ (lambda (loc) (xref--group-name-for-display (xref-location-group loc) - data-parent-dir)) + data-parent-dir + nil)) (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)"))) (list "xref-resources/file1.txt" commit 49e243c0c85d18fc775970d9ebd846eba3a6866e Author: Mattias Engdegård Date: Mon May 13 10:44:05 2024 +0200 Avoid resizing mutation in subst-char-in-string, take two This time we take care to preserve properties, and add a test. * lisp/subr.el (subst-char-in-string): Use string-replace to avoid resizing mutation and O(n^2) time. * test/lisp/subr-tests.el (subr--subst-char-in-string): New test. diff --git a/lisp/subr.el b/lisp/subr.el index 0ac71560c59..d18765c2a5b 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -5690,13 +5690,25 @@ The SEPARATOR regexp defaults to \"\\s-+\"." (defun subst-char-in-string (fromchar tochar string &optional inplace) "Replace FROMCHAR with TOCHAR in STRING each time it occurs. Unless optional argument INPLACE is non-nil, return a new string." - (let ((i (length string)) - (newstr (if inplace string (copy-sequence string)))) - (while (> i 0) - (setq i (1- i)) - (if (eq (aref newstr i) fromchar) - (aset newstr i tochar))) - newstr)) + (if (and (not inplace) + (if (multibyte-string-p string) + (> (max fromchar tochar) 127) + (> tochar 255))) + ;; Avoid quadratic behaviour from resizing replacement. + (let ((res (string-replace (string fromchar) (string tochar) string))) + (unless (eq res string) + ;; Mend properties broken by the replacement. + ;; Not fast, but this case never was. + (dolist (p (object-intervals string)) + (set-text-properties (nth 0 p) (nth 1 p) (nth 2 p) res))) + res) + (let ((i (length string)) + (newstr (if inplace string (copy-sequence string)))) + (while (> i 0) + (setq i (1- i)) + (if (eq (aref newstr i) fromchar) + (aset newstr i tochar))) + newstr))) (defun string-replace (from-string to-string in-string) "Replace FROM-STRING with TO-STRING in IN-STRING each time it occurs." diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index 119c124f3a5..6f28e057342 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -1330,5 +1330,53 @@ final or penultimate step during initialization.")) (t x) (:success (1+ x))) '(error ""))))) +(ert-deftest subr--subst-char-in-string () + ;; Cross-validate `subst-char-in-string' with `string-replace', + ;; which should produce the same results when there are no properties. + (dolist (str '("ananas" "na\x80ma\x80s" "hétérogénéité" + "Ω, Ω, Ω" "é-\x80-\x80")) + (dolist (mb '(nil t)) + (unless (and (not mb) (multibyte-string-p str)) + (let ((str (if (and mb (not (multibyte-string-p str))) + (string-to-multibyte str) + str))) + (dolist (inplace '(nil t)) + (dolist (from '(?a ?é ?Ω #x80 #x3fff80)) + (dolist (to '(?o ?á ?ƒ ?☃ #x1313f #xff #x3fffc9)) + ;; Can't put a non-byte value in a non-ASCII unibyte string. + (unless (and (not mb) (> to #xff) + (not (string-match-p (rx bos (* ascii) eos) str))) + (let* ((in (copy-sequence str)) + (ref (if (and (not mb) (> from #xff)) + in ; nothing to replace + (string-replace + (if (and (not mb) (<= from #xff)) + (unibyte-string from) + (string from)) + (if (and (not mb) (<= to #xff)) + (unibyte-string to) + (string to)) + in))) + (out (subst-char-in-string from to in inplace))) + (should (equal out ref)) + (if inplace + (should (eq out in)) + (should (equal in str)))))))))))) + + ;; Verify that properties are preserved. + (dolist (str (list "cocoa" (string-to-multibyte "cocoa") "écalé")) + (dolist (from '(?a ?o ?c ?é)) + (dolist (to '(?i ?à ?☃)) + (let ((in (copy-sequence str))) + (put-text-property 0 5 'alpha 1 in) + (put-text-property 1 4 'beta 2 in) + (put-text-property 0 2 'gamma 3 in) + (put-text-property 1 4 'delta 4 in) + (put-text-property 2 3 'epsilon 5 in) + (let* ((props-in (copy-tree (object-intervals in))) + (out (subst-char-in-string from to in)) + (props-out (object-intervals out))) + (should (equal props-out props-in)))))))) + (provide 'subr-tests) ;;; subr-tests.el ends here commit 334fb0ddfe603097c3493297c3e78a185b22d1af Merge: be31c383593 af27ecbf155 Author: Michael Albinus Date: Mon May 13 10:31:45 2024 +0200 Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs commit be31c383593452c172ea6d470f400f64b5065874 Author: Michael Albinus Date: Mon May 13 10:31:13 2024 +0200 * doc/misc/tramp.texi: Adapt some markups. diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index e5e2f3b243f..d1c58d83aeb 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -454,7 +454,7 @@ optional, in case of a missing part a default value is assumed. The default value for an empty local file name part is the remote user's home directory. The shortest remote file name is thus @file{@trampfn{-,,}}. The @samp{-} notation for the default method is -used for syntactical reasons, @ref{Default Method}. +used for syntactical reasons, @pxref{Default Method}. The @code{method} part describes the connection method used to reach the remote host, see below. @@ -465,7 +465,7 @@ which case it is written as @code{user%domain}. The @code{host} part must be a host name which can be resolved on your local host. It could be a short host name, a fully qualified -domain name, an IPv4 or IPv6 address, @ref{File name syntax}. Some +domain name, an IPv4 or IPv6 address, @pxref{File name syntax}. Some connection methods also support a notation for the port to be used, in which case it is written as @code{host#port}. @@ -802,7 +802,7 @@ files between different @emph{user identities} on the same host. usability of one of the commands defined in @code{tramp-remote-coding-commands}. @value{tramp} uses the first reliable command it finds. @value{tramp}'s search path can be -customized, see @ref{Remote programs}. +customized, @pxref{Remote programs}. In case none of the commands are available, @value{tramp} first transfers a small Perl program to the remote host, and then tries to @@ -866,7 +866,7 @@ equivalent @option{androidsu} method is provided for that system with workarounds for its many idiosyncrasies, with the exception that multi-hops are unsupported. -This is an optional method, @ref{Optional methods}. It is enabled by +This is an optional method, @pxref{Optional methods}. It is enabled by default on @code{android} systems only. @item @option{sudo} @@ -877,8 +877,8 @@ Similar to @option{su} method, @option{sudo} uses @command{sudo}. @command{sudo} must have sufficient rights to start a shell. For security reasons, a @option{sudo} connection is disabled after a -predefined timeout (5 minutes by default). This can be changed, see -@ref{Predefined connection information}. +predefined timeout (5 minutes by default). This can be changed, +@pxref{Predefined connection information}. @item @option{doas} @cindex method @option{doas} @@ -896,7 +896,7 @@ This method is used on @code{systemd}-based hosts. Internally, it uses the @code{systemd-run} command. A @option{run0} connection is disabled after a predefined timeout as well. -This is an optional method, @ref{Optional methods}. +This is an optional method, @pxref{Optional methods}. @item @option{sg} @cindex method @option{sg} @@ -939,7 +939,7 @@ missing shell prompts that confuses @value{tramp}. This method is also similar to @option{ssh}. It uses the @command{krlogin -x} command only for remote host login. -This method is an optional method, @ref{Optional methods}. +This method is an optional method, @pxref{Optional methods}. @item @option{ksu} @cindex method @option{ksu} @@ -947,7 +947,7 @@ This method is an optional method, @ref{Optional methods}. @cindex kerberos (with @option{ksu} method) This is another method from the Kerberos suite. It behaves like -@option{su}. It is an optional method, @ref{Optional methods}. +@option{su}. It is an optional method, @pxref{Optional methods}. @item @option{plink} @cindex method @option{plink} @@ -1013,7 +1013,7 @@ a container's name or ID, as returned by @samp{toolbox list -c}. Without a host name, the default Toolbox container for the host will be used. -This is an optional method, @ref{Optional methods}. It does not +This is an optional method, @pxref{Optional methods}. It does not support user names. @item @option{flatpak} @@ -1024,7 +1024,7 @@ Integration of Flatpak sandboxes. The host name may be either an application ID, a sandbox instance ID, or a PID, as returned by @samp{flatpak ps}. -This is an optional method, @ref{Optional methods}. It does not +This is an optional method, @pxref{Optional methods}. It does not support user names. @item @option{apptainer} @@ -1034,7 +1034,7 @@ support user names. Integration of Apptainer instances. The host name is the instance name, as returned by @samp{apptainer instance list}. -This is an optional method, @ref{Optional methods}. It does not +This is an optional method, @pxref{Optional methods}. It does not support user names. @item @option{nspawn} @@ -1044,7 +1044,7 @@ support user names. Integration of @code{systemd-nspawn} instances. The host name is the instance name, as returned by @samp{machinectl list --all}. -This is an optional method, @ref{Optional methods}. +This is an optional method, @pxref{Optional methods}. @end table @@ -1183,7 +1183,7 @@ The command used for this connection is: @samp{fsh @var{host} -l not useful for @value{tramp}. @command{fsh} connects to remote host and @value{tramp} keeps that one connection open. -This is an optional method, @ref{Optional methods}. +This is an optional method, @pxref{Optional methods}. @item @option{nc} @cindex method @option{nc} @@ -1196,7 +1196,7 @@ NAS hosts. These dumb devices have severely restricted local shells, such as the @command{busybox} and do not host any other encode or decode programs. -This is an optional method, @ref{Optional methods}. +This is an optional method, @pxref{Optional methods}. @item @option{sudoedit} @cindex method @option{sudoedit} @@ -1414,7 +1414,7 @@ Media devices, like cell phones, tablets, cameras, can be accessed via the @option{mtp} method. Just the device name is needed in order to specify the host in the file name. However, the device must already be connected via USB, before accessing it. Possible device names are -visible via host name completion, @ref{File name completion}. +visible via host name completion, @pxref{File name completion}. Depending on the device type, the access could be read-only. Some devices are accessible under different names in parallel, offering @@ -1551,7 +1551,7 @@ properties, @xref{Setup of sshfs method}. @cindex default method In a remote file name, the use of a default method is indicated by the -pseudo method @option{-}, @ref{File name syntax}. +pseudo method @option{-}, @pxref{File name syntax}. @defopt tramp-default-method Default method is for transferring files. The user option @@ -2457,7 +2457,7 @@ be recomputed. To force @value{tramp} to recompute afresh, call By default, @value{tramp} uses the command @command{/bin/sh} for starting a shell on the remote host. This can be changed by setting -the connection property @t{"remote-shell"}; see @ref{Predefined +the connection property @t{"remote-shell"}; @pxref{Predefined connection information}. If you want, for example, use @command{/usr/bin/zsh} on a remote host, you might apply @@ -3064,7 +3064,7 @@ mounted, it will be used as it is. If the mount point does not exist yet, @value{tramp} creates this directory. The mount point can be overwritten by the connection property -@t{"mount-point"}, @ref{Predefined connection information}. +@t{"mount-point"}, @pxref{Predefined connection information}. Example: @lisp @@ -3453,7 +3453,7 @@ users. The command @command{encfsctl}, the workhorse for encryption / decryption, needs the configuration file password every call. Therefore, it is recommend to cache this password in Emacs. This can -be done using @code{auth-sources}, @ref{Using an authentication file}. +be done using @code{auth-sources}, @pxref{Using an authentication file}. An entry needs the url-encoded directory name as machine, your local user name as user, and the password. The port is optional, if given it must be the string @t{"crypt"}. The example above would require @@ -4518,7 +4518,7 @@ In order to gain even more performance, it is recommended to bind @code{start-file-process}. Furthermore, you might set @code{tramp-use-connection-share} to @code{nil} in order to bypass @value{tramp}'s handling of the @option{ControlMaster} options, and -use your own settings in @file{~/.ssh/config}, @ref{Using ssh +use your own settings in @file{~/.ssh/config}, @pxref{Using ssh connection sharing}. @@ -4700,7 +4700,7 @@ Whether renaming a buffer file name by @code{tramp-rename-files} or @value{tramp} offers also transparent access to files inside file archives. This is possible only on hosts which have installed -@acronym{GVFS, the GNOME Virtual File System}, @ref{GVFS-based +@acronym{GVFS, the GNOME Virtual File System}, @pxref{GVFS-based methods}. Internally, file archives are mounted via the @acronym{GVFS} @option{archive} method. @@ -4996,7 +4996,7 @@ help the development team find the best solution and avoid unrelated detours. To exclude cache-related problems, flush all caches before running the -test, @ref{Cleanup remote connections}. Alternatively, and often +test, @pxref{Cleanup remote connections}. Alternatively, and often better for analysis, reproduce the problem in a clean Emacs session started with @command{emacs -Q}. Then, @value{tramp} does not load the persistency file (@pxref{Connection caching}), and it does not use @@ -5520,7 +5520,7 @@ Where are remote files trashed to? @vindex remote-file-name-inhibit-delete-by-moving-to-trash Emacs can trash files instead of deleting @ifinfo -them, @ref{Misc File Ops, Trashing , , emacs}. +them, @pxref{Misc File Ops, Trashing , , emacs}. @end ifinfo @ifnotinfo them. @@ -6089,7 +6089,7 @@ can use the @code{without-remote-files} macro. @end lisp This improves performance, because many primitive file name operations -don't check any longer for Tramp file name regexps then. +don't check any longer for @value{tramp} file name regexps then. @item @findex tramp-unload-tramp commit af27ecbf1556af8a428b367cdc26ec4c706df4a0 Author: Basil L. Contovounesios Date: Mon May 13 09:58:50 2024 +0200 ; Tweak last docstring addition in lisp/imenu.el. diff --git a/lisp/imenu.el b/lisp/imenu.el index 93a544ff550..2b1d4f5ce85 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -100,7 +100,7 @@ If `on-mouse' use a popup menu when `imenu' was invoked with the mouse." (other :tag "Always" t))) (defcustom imenu-eager-completion-buffer t - "If non-nil, eagerly popup the completion buffer." + "If non-nil, eagerly pop up the completion buffer." :type 'boolean :version "22.1") @@ -148,7 +148,7 @@ Used for flattening nested indexes with name concatenation." (defcustom imenu-flatten nil "Whether to flatten the list of sections in an imenu or show it nested. If nil, use nested indexes. -If t, popup the completion buffer with a flattened menu. +If t, pop up the completion buffer with a flattened menu. If `annotation', use completion annotation as a suffix to append section names after the index names. commit af526f88562162ec053534eae510b9e7a85cb9eb Author: Michael Albinus Date: Mon May 13 09:23:58 2024 +0200 Fix bug#70900 * lisp/net/tramp.el (tramp-handle-unlock-file): Be quiet if user isn't interested in lock files. Bug#70900 diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 5bb1ab66175..f024ebecfc5 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -4660,8 +4660,11 @@ Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.") ((process-live-p (tramp-get-process v))) (lockname (tramp-compat-make-lock-file-name file))) (delete-file lockname) - ;; Trigger the unlock error. - (signal 'file-error `("Cannot remove lock file for" ,file))) + ;; Trigger the unlock error. Be quiet if user isn't + ;; interested in lock files. See Bug#70900. + (unless (or (not create-lockfiles) + (bound-and-true-p remote-file-name-inhibit-locks)) + (signal 'file-error `("Cannot remove lock file for" ,file)))) ;; `userlock--handle-unlock-error' exists since Emacs 28.1. It ;; checks for `create-lockfiles' since Emacs 30.1, we don't need ;; this check here, then. commit 66a12698ab934705f0379a9d789de565eac811f0 Merge: 41ec1d79602 431f8ff1e38 Author: Michael Albinus Date: Mon May 13 09:23:32 2024 +0200 Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs commit 41ec1d79602f9d1cadc543ccc4aff2f907d9cde3 Merge: e53e8b4cf44 f560e759338 Author: Michael Albinus Date: Mon May 13 07:24:30 2024 +0200 Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs commit e53e8b4cf44be0fac0eb92c816b2c7915533e283 Author: Michael Albinus Date: Sun May 12 19:40:08 2024 +0200 Add Tramp method "nspawn" * doc/misc/tramp.texi: Adapt some markups. (Inline methods) : Add. (Default Host): Mention default host for "nspawn". (Customizing Methods): Remove tramp-nspawn. (Password handling): Add "nspawn". * etc/NEWS: New Tramp method "nspawn". * lisp/net/tramp-compat.el (tramp-nspawn): Warn, if that package is used. * lisp/net/tramp-container.el (tramp-nspawn-program): New defcustom. (tramp-nspawn-method): New defconst. (tramp-nspawn--completion-function, tramp-enable-nspawn-method): New defuns. * lisp/net/tramp.el (tramp-local-host-regexp): Add OpenSUSE host names. diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 6c36429fb79..e5e2f3b243f 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -973,7 +973,12 @@ supports changing the remote login shell @command{/bin/sh}. Check the @samp{Share SSH connections if possible} control for that session. +@end table + +@noindent +The following methods allow to access containers in different ways: +@table @asis @item @option{docker} @cindex method @option{docker} @cindex @option{docker} method @@ -1032,6 +1037,14 @@ name, as returned by @samp{apptainer instance list}. This is an optional method, @ref{Optional methods}. It does not support user names. +@item @option{nspawn} +@cindex method @option{nspawn} +@cindex @option{nspawn} method + +Integration of @code{systemd-nspawn} instances. The host name is the +instance name, as returned by @samp{machinectl list --all}. + +This is an optional method, @ref{Optional methods}. @end table @@ -1256,9 +1269,9 @@ domain name). An example: @trampfn{smb,daniel%BIZARRE@@melancholia,/daniel$$/.emacs} @end example -where user @code{daniel} connects as a domain user to the SMB host -@code{melancholia} in the MS Windows domain @code{BIZARRE} to edit -@file{.emacs} located in the home directory (share @code{daniel$}). +where user @samp{daniel} connects as a domain user to the SMB host +@samp{melancholia} in the MS Windows domain @samp{BIZARRE} to edit +@file{.emacs} located in the home directory (share @samp{daniel$}). Alternatively, for local WINS users (as opposed to domain users), substitute the domain name with the name of the local host in @@ -1268,9 +1281,9 @@ UPPERCASE as shown here: @trampfn{smb,daniel%MELANCHOLIA@@melancholia,/daniel$$/.emacs} @end example -where user @code{daniel} connects as local user to the SMB host -@code{melancholia} in the local domain @code{MELANCHOLIA} to edit -@file{.emacs} located in the home directory (share @code{daniel$}). +where user @samp{daniel} connects as local user to the SMB host +@samp{melancholia} in the local domain @samp{MELANCHOLIA} to edit +@file{.emacs} located in the home directory (share @samp{daniel$}). The domain name and user name are optional for @command{smbclient} authentication. When user name is not specified, @command{smbclient} @@ -1702,8 +1715,8 @@ follows: @end group @end lisp -With all defaults set, @samp{@trampfn{-,,}} will connect @value{tramp} -to John's home directory on @code{target} via @code{ssh}. +With all defaults set, @file{@trampfn{-,,}} will connect @value{tramp} +to John's home directory on @samp{target} via method @option{ssh}. @end defopt @defopt tramp-default-host-alist @@ -1712,6 +1725,10 @@ allows multiple default host values based on access method or user name combinations. The alist can hold multiple values. While @code{tramp-default-host} is sufficient in most cases, some methods, like @option{adb}, require defaults overwritten. + +The default host name for @option{nspawn} is @samp{.host}. Therefore, +@file{@trampfn{nspawn,,}} and @file{@trampfn{sudo,,}} have the same +effect. @end defopt @@ -1938,17 +1955,6 @@ Access of a hadoop/hdfs file system. A file is accessed via the user that you want to use, and @samp{node} is the name of the hadoop server. -@item tramp-nspawn -@cindex method @option{nspawn} -@cindex @option{nspawn} method -Access to environments provided by systemd-nspawn. A file is accessed -via @file{@trampfn{nspawn,user@@container,/path/to/file}}, where -@samp{user} is the (optional) user that you want to use, and -@samp{container} is the container to connect to. systemd-nspawn and -its container utilities often require super user access to run, use -multi-hop file names with @option{doas} or @option{sudo} to raise your -privileges. - @item vagrant-tramp @cindex method @option{vagrant} @cindex @option{vagrant} method @@ -2118,11 +2124,12 @@ file name syntax, must be appended to the machine and login items: machine melancholia#4711 port davs login daniel%BIZARRE password geheim @end example -For the methods @option{doas}, @option{sudo} and @option{sudoedit} the -password of the user requesting the connection is needed, and not the -password of the target user@footnote{On the local host, @code{run0} -uses a graphical password agent.}. If these connections happen on the -local host, an entry with the local user and local host is used: +For the methods @option{doas}, @option{sudo}, @option{sudoedit} and +@option{nspawn} the password of the user requesting the connection is +needed, and not the password of the target user@footnote{On the local +host, @code{run0} uses a graphical password agent.}. If these +connections happen on the local host, an entry with the local user and +local host is used: @example machine @var{host} port sudo login @var{user} password secret @@ -2701,8 +2708,8 @@ its execution of @command{/bin/sh} on the remote host because Bourne shell does not recognize the export command as entered in @file{.profile}. -Likewise, (@code{~}) character in paths will cause errors because -Bourne shell does not do (@code{~}) character expansions. +Likewise, (@samp{~}) character in paths will cause errors because +Bourne shell does not do (@samp{~}) character expansions. One approach to avoiding these incompatibilities is to make all commands in @file{~/.shrc} and @file{~/.profile} Bourne shell @@ -3417,7 +3424,7 @@ configuration option will be selected, it can be @t{"--standard"} or @t{"--paranoia"}. See the @samp{encfs(1)} man page for details. However, @value{tramp} must adapt these configuration sets. The -@code{chainedNameIV} configuration option must be disabled; otherwise +@option{chainedNameIV} configuration option must be disabled; otherwise @value{tramp} couldn't handle file name encryption transparently. @end defopt @@ -3536,7 +3543,7 @@ on the remote host @var{host}, using the method @var{method}. @table @file @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}.emacs For the file @file{.emacs} located in the home directory, on the host -@code{melancholia}, using method @code{ssh}. +@samp{melancholia}, using method @option{ssh}. @item @value{prefix}ssh@value{postfixhop}melancholia.danann.net@value{postfix}.emacs For the file @file{.emacs} specified using the fully qualified domain name of @@ -3546,12 +3553,12 @@ the host. For the file @file{.emacs} specified using the @file{~}, which is expanded. @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}~daniel/.emacs -For the file @file{.emacs} located in @code{daniel}'s home directory -on the host, @code{melancholia}. The @file{~} construct is +For the file @file{.emacs} located in @samp{daniel}'s home directory +on the host, @samp{melancholia}. The @file{~} construct is expanded to the home directory of that user on the remote host. @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}/etc/squid.conf -For the file @file{/etc/squid.conf} on the host @code{melancholia}. +For the file @file{/etc/squid.conf} on the host @samp{melancholia}. @end table @@ -3569,8 +3576,8 @@ different name using the proper syntax will override this default behavior: @file{@trampfn{method,user@@host,path/to/file}}. @file{@trampfn{ssh,daniel@@melancholia,.emacs}} is for file -@file{.emacs} in @code{daniel}'s home directory on the host, -@code{melancholia}, accessing via method @code{ssh}. +@file{.emacs} in @samp{daniel}'s home directory on the host, +@samp{melancholia}, accessing via method @option{ssh}. For specifying port numbers, affix @file{#} to the host name. For example: @file{@trampfn{ssh,daniel@@melancholia#42,.emacs}}. @@ -3603,8 +3610,8 @@ names. Beside the @code{default} value, @var{syntax} can be This remote file name syntax is similar to the syntax used by Ange FTP@. A remote file name has the form -@code{@value{prefix}user@@host@value{postfix}path/to/file}. The -@code{user@@} part is optional, and the method is determined by +@file{@value{prefix}user@@host@value{postfix}path/to/file}. The +@samp{user@@} part is optional, and the method is determined by @ref{Default Method}. @item @code{separate} @@ -3615,8 +3622,8 @@ A remote file name has the form @include trampver.texi This remote file name syntax originated in the XEmacs text editor. A remote file name has the form -@code{@trampfn{method,user@@host,path/to/file}}. The @code{method} -and @code{user@@} parts are optional. +@file{@trampfn{method,user@@host,path/to/file}}. The @samp{method} +and @samp{user@@} parts are optional. @clear separate @set unified @include trampver.texi @@ -3799,12 +3806,12 @@ Ad-hoc proxies can take patterns @code{%h} or @code{%u} like in @code{tramp-default-proxies-alist}. The following file name expands to user @samp{root} on host @samp{remotehost}, starting with an @option{ssh} session on host @samp{remotehost}: -@samp{@trampfn{ssh@value{postfixhop}%h|su,remotehost,}}. +@file{@trampfn{ssh@value{postfixhop}%h|su,remotehost,}}. On the other hand, if a trailing hop does not specify a host name, the host name of the previous hop is reused. Therefore, the following file name is equivalent to the previous example: -@samp{@trampfn{ssh@value{postfixhop}remotehost|su,,}}. +@file{@trampfn{ssh@value{postfixhop}remotehost|su,,}}. @defopt tramp-completion-multi-hop-methods When this list includes the last method in a multi-hop connection, the @@ -3831,8 +3838,8 @@ The buffer must either visit a file, or a directory @defopt tramp-file-name-with-method The method @code{tramp-revert-buffer-with-sudo} shows an alternate -buffer. It defaults to @code{sudo}, other valid methods are -@code{su}, @code{doas}, @code{run0}, and @code{ksu}. +buffer. It defaults to @option{sudo}, other valid methods are +@option{su}, @option{doas}, @option{run0}, and @option{ksu}. @lisp (customize-set-variable 'tramp-file-name-with-method "doas") @@ -4066,7 +4073,7 @@ follows in the local @file{.emacs} file: local host that the remote host can redirect X11 window interactions. If querying for a recognizable name is not possible for whatever reason, then replace @code{(getenv "DISPLAY")} with a -hard-coded, fixed name. Note that using @code{:0} for X11 display name +hard-coded, fixed name. Note that using @samp{:0} for X11 display name here will not work as expected. @vindex ForwardX11@r{, ssh option} @@ -4638,7 +4645,7 @@ specifies the target to be applied for renaming buffer file names from source via @code{tramp-rename-files}. @code{source} is a regular expressions, which matches a remote file name. @code{target} must be a directory name, which could be remote (including remote directories -@value{tramp} infers by default, such as @samp{@trampfn{method,user@@host,}}). +@value{tramp} infers by default, such as @file{@trampfn{method,user@@host,}}). @code{target} can contain the patterns @code{%m}, @code{%u} or @code{%h}, which are replaced by the method name, user name or host @@ -4667,7 +4674,7 @@ ssh@value{postfixhop}%h@value{postfix}") @end lisp routes all connections to a host in @samp{company.org} via -@samp{@trampfn{ssh,multi.hop,}}, which might be useful when using +@file{@trampfn{ssh,multi.hop,}}, which might be useful when using Emacs outside the company network. @lisp diff --git a/etc/NEWS b/etc/NEWS index 846bf759995..cb7c62a7876 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1079,9 +1079,11 @@ This connection method is similar to "sudo", but it uses the These are the external methods counterparts of "docker" and "podman". +++ -*** New optional connection methods "toolbox", "flatpak" and "apptainer". -They allow accessing system containers provided by Toolbox, sandboxes -provided by Flatpak, or instances managed by Apptainer. +*** New optional connection methods for containers. +Tere are new optional connection methods "toolbox", "flatpak", +"apptainer" and "nspawn". They allow accessing system containers +provided by Toolbox, sandboxes provided by Flatpak, instances managed by +Apptainer, or accessing systemd-based light-weight containers.. +++ *** Connection method "kubernetes" supports now optional container name. diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index d7492be63f2..26c2049fbae 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -55,6 +55,9 @@ (with-eval-after-load 'kubernetes-tramp (warn (concat "Package `kubernetes-tramp' has been obsoleted, " "please use integrated package `tramp-container'"))) +(with-eval-after-load 'tramp-nspawn + (warn (concat "Package `tramp-nspawn' has been obsoleted, " + "please use integrated package `tramp-container'"))) ;; For not existing functions, obsolete functions, or functions with a ;; changed argument list, there are compiler warnings. We want to diff --git a/lisp/net/tramp-container.el b/lisp/net/tramp-container.el index 902fc6a451b..3d15d71d709 100644 --- a/lisp/net/tramp-container.el +++ b/lisp/net/tramp-container.el @@ -81,8 +81,8 @@ ;; C-x C-f /flatpak:SANDBOX:/path/to/file ;; ;; Where: -;; SANDBOX is the running sandbox to connect to. -;; It could be an application ID, an instance ID, or a PID. +;; SANDBOX is the running sandbox to connect to. +;; It could be an application ID, an instance ID, or a PID. ;; ;; ;; @@ -91,7 +91,17 @@ ;; C-x C-f /apptainer:INSTANCE:/path/to/file ;; ;; Where: -;; INSTANCE is the running instance to connect to. +;; INSTANCE is the running instance to connect to. +;; +;; +;; +;; Open a file on a running systemd-nspawn container: +;; +;; C-x C-f /nspawn:USER@CONTAINER:/path/to/file +;; +;; Where: +;; USER is the user on the container to connect as (optional) +;; CONTAINER is the container to connect to ;;; Code: @@ -159,6 +169,13 @@ If it is nil, the default context will be used." :type '(choice (const "apptainer") (string))) +(defcustom tramp-nspawn-program "machinectl" + "Name of the machinectl program." + :group 'tramp + :version "30.1" + :type '(choice (const "machinectl") + (string))) + ;;;###tramp-autoload (defconst tramp-docker-method "docker" "Tramp method name to use to connect to Docker containers.") @@ -193,6 +210,10 @@ This is for out-of-band connections.") (defconst tramp-apptainer-method "apptainer" "Tramp method name to use to connect to Apptainer instances.") +;;;###tramp-autoload +(defconst tramp-nspawn-method "nspawn" + "Tramp method name to use to connect to systemd-nspawn containers.") + ;;;###tramp-autoload (defmacro tramp-skeleton-completion-function (method &rest body) "Skeleton for `tramp-*-completion-function' with multi-hop support. @@ -416,6 +437,21 @@ see its function help for a description of the format." lines))) (mapcar (lambda (name) (list nil name)) names)))) +(defun tramp-nspawn--completion-function (method) + "List systemd-nspawn containers available for connection. + +This function is used by `tramp-set-completion-function', please +see its function help for a description of the format." + (tramp-skeleton-completion-function method + (when-let ((raw-list + (shell-command-to-string (concat program " list --all -q"))) + ;; Ignore header line. + (lines (cdr (split-string raw-list "\n"))) + (first-words (mapcar (lambda (line) (car (split-string line))) + lines)) + (machines (seq-take-while (lambda (name) name) first-words))) + (mapcar (lambda (m) (list nil m)) machines)))) + ;;;###tramp-autoload (defvar tramp-default-remote-shell) ;; Silence byte compiler. @@ -580,6 +616,28 @@ see its function help for a description of the format." tramp-apptainer-method `((tramp-apptainer--completion-function ,tramp-apptainer-method)))) +;; todo: check tramp-async-args and tramp-direct-async +;;;###tramp-autoload +(defun tramp-enable-nspawn-method () + "Enable connection to nspawn containers." + (add-to-list 'tramp-methods + `(,tramp-nspawn-method + (tramp-login-program ,tramp-nspawn-program) + (tramp-login-args (("shell") + ("-q") + ("--uid" "%u") + ("%h"))) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-i" "-c")))) + + (add-to-list 'tramp-default-host-alist `(,tramp-nspawn-method nil ".host")) + (add-to-list 'tramp-completion-multi-hop-methods tramp-nspawn-method) + + (tramp-set-completion-function + tramp-nspawn-method + `((tramp-nspawn--completion-function ,tramp-nspawn-method)))) + ;; Default connection-local variables for Tramp. (defconst tramp-kubernetes-connection-local-default-variables diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 02a493f0a78..5bb1ab66175 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -562,11 +562,13 @@ host runs a restricted shell, it shall be added to this list, too." ;; Fedora. "localhost4" "localhost6" ;; Ubuntu. - "ip6-localhost" "ip6-loopback")) + "ip6-localhost" "ip6-loopback" + ;; OpenSUSE. + "ipv6-localhost" "ipv6-loopback")) eos) "Host names which are regarded as local host. If the local host runs a chrooted environment, set this to nil." - :version "29.3" + :version "30.1" :type '(choice (const :tag "Chrooted environment" nil) (regexp :tag "Host regexp")))