commit d6bcb39ba9d46f7dc29e01551a1d35fe250695a9 (HEAD, refs/remotes/origin/master) Author: Alan Mackenzie Date: Wed Jun 28 18:29:39 2023 +0000 Fontify C, C++, Objective C identifiers containing $ Optionally, fontify them with font-lock-warning-face. This fixes bug#64204. * lisp/progmodes/cc-fonts.el (c-font-lock-ids-with-dollar): New function. (c-simple-decl-matchers, c-complex-decl-matchers): invoke c-font-lock-ids-with-dollar for pertinent languages. * lisp/progmodes/cc-langs.el (c-symbol-start): Add `$' to the character list. (c-dollar-in-ids): New lang const. (c-symbol-key): For the Pike value, use the AWK value rather than the C value as the basis, as the latter is no longer suitable. * lisp/progmodes/cc-vars.el (c-warn-ids-with-dollar): New customizable option. * doc/misc/cc-mode.texi ("Miscellaneous Font Locking"): Add a section on the new optional fontification of identifiers with 'font-lock-warning-face'. diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi index 5f905be09d5..4ab95798468 100644 --- a/doc/misc/cc-mode.texi +++ b/doc/misc/cc-mode.texi @@ -2169,6 +2169,23 @@ Misc Font Locking @section Miscellaneous Font Locking @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +Some compilers, notably GCC, allow the character @samp{$} to be a +constituent of identifiers in the languages C, C++, and Objective C. +CC Mode defaults to accepting these @samp{$} characters and fontifying +the identifiers in which they appear like any others. + +However, the compiler you're using, or your project coding standards +may disallow such use. In such cases, you can set +@code{c-warn-ids-with-dollar} to non-@code{nil}. This causes these +invalid identifiers to be fontified distinctively. + +@defvar c-warn-ids-with-dollar +@vindex warn-ids-with-dollar (c-) +When this customization option is non-@code{nil}, identifiers +containing the @samp{$} character are fontified with +@code{font-lock-warning-face}. +@end defvar + In some languages, particularly in C++, there are constructs which are syntactically ambiguous---they could be either declarations or expressions, and @ccmode{} cannot tell for sure which. Often such a diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index baf57d6839a..afbf841bcb1 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1890,6 +1890,38 @@ c-font-lock-enclosing-decls (c-font-lock-declarators limit t in-typedef (not (c-bs-at-toplevel-p (point))))))))))) +(defun c-font-lock-ids-with-dollar (limit) + ;; Maybe fontify identifiers with a dollar using `font-lock-warning-face'. + ;; This is done only for languages which tolerate a $ in ids, and only when + ;; the flag variable `c-warn-ids-with-dollar' is set to non-nil. This + ;; function only works after functions such as `c-font-lock-declarations' + ;; have already been run. + ;; + ;; This function will be called from font-lock for a region bounded by POINT + ;; and LIMIT, as though it were to identify a keyword for + ;; font-lock-keyword-face. It always returns NIL to inhibit this and + ;; prevent a repeat invocation. See elisp/lispref page "Search-based + ;; Fontification". + (when c-warn-ids-with-dollar + (let (id-start) + (while (and (< (point) limit) + (skip-chars-forward "^$" limit) + (< (point) limit) + (eq (char-after) ?$)) + (if (and (memq (c-get-char-property (point) 'face) + '(font-lock-variable-name-face + font-lock-function-name-face + font-lock-type-face)) + (setq id-start (c-on-identifier))) + (progn + (goto-char id-start) + (looking-at c-identifier-key) + (c-put-font-lock-face (match-beginning 0) (match-end 0) + 'font-lock-warning-face) + (goto-char (match-end 0))) + (forward-char))) + nil))) + (defun c-font-lock-ml-strings (limit) ;; Fontify multi-line strings. ;; @@ -2290,7 +2322,12 @@ c-simple-decl-matchers ;; Fontify generic colon labels in languages that support them. ,@(when (c-lang-const c-recognize-colon-labels) - '(c-font-lock-labels)))) + '(c-font-lock-labels)) + + ;; Maybe fontify identifiers containing a dollar sign with + ;; `font-lock-warning-face'. + ,@(when (c-lang-const c-dollar-in-ids) + `(c-font-lock-ids-with-dollar)))) (c-lang-defconst c-complex-decl-matchers "Complex font lock matchers for types and declarations. Used on level @@ -2366,7 +2403,11 @@ c-complex-decl-matchers ;; (see Elisp page "Search-based Fontification"). '(("\\" (c-font-lock-c++-new)))) - )) + + ;; Maybe fontify identifiers containing a dollar sign with + ;; `font-lock-warning-face'. + ,@(when (c-lang-const c-dollar-in-ids) + `(c-font-lock-ids-with-dollar)))) (defun c-font-lock-labels (limit) ;; Fontify all statement labels from the point to LIMIT. Assumes diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index d56366e1755..2422cf3deb0 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -834,8 +834,9 @@ c-symbol-start keyword. It's unspecified how far it matches. Does not contain a \\| operator at the top level." t (concat "[" c-alpha "_]") + (c c++) (concat "[" c-alpha "_$]") java (concat "[" c-alpha "_@]") - objc (concat "[" c-alpha "_@]") + objc (concat "[" c-alpha "_@$]") pike (concat "[" c-alpha "_`]")) (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start)) @@ -848,6 +849,10 @@ c-symbol-chars objc (concat c-alnum "_$@")) (c-lang-defvar c-symbol-chars (c-lang-const c-symbol-chars)) +(c-lang-defconst c-dollar-in-ids + "Non-nil when a dollar (can be) a non-standard constituent of an identifier." + t (string-match (c-lang-const c-symbol-start) "$")) + (c-lang-defconst c-symbol-char-key "Regexp matching a sequence of at least one identifier character." t (concat "[" (c-lang-const c-symbol-chars) "]+")) @@ -859,9 +864,9 @@ c-symbol-key t (concat (c-lang-const c-symbol-start) "[" (c-lang-const c-symbol-chars) "]\\{,1000\\}") pike (concat - ;; Use the value from C here since the operator backquote is + ;; Use the value from AWK here since the operator backquote is ;; covered by the other alternative. - (c-lang-const c-symbol-key c) + (c-lang-const c-symbol-key awk) "\\|" (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))) diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el index 286d569aaca..c7b66f040cd 100644 --- a/lisp/progmodes/cc-vars.el +++ b/lisp/progmodes/cc-vars.el @@ -280,6 +280,14 @@ c-report-syntactic-errors :type 'boolean :group 'c) +(defcustom c-warn-ids-with-dollar nil + "Fontify identifiers with a dollar character in font-lock-warn-face. +This has effect only for languages in which `c-dollar-in-ids' is +non-nil, e.g. C, C++, Objective C. It covers languages where +\"$\" is permitted in ids \"informally\", but only by some compilers." + :type 'boolean + :group 'c) + (defcustom-c-stylevar c-basic-offset 4 "Amount of basic offset used by + and - symbols in `c-offsets-alist'. Also used as the indentation step when `c-syntactic-indentation' is commit c5d6102313076b83526dc79bfb563621671fb70b Author: Michael Albinus Date: Wed Jun 28 16:53:01 2023 +0200 Adapt Tramp's kubernetes integration * doc/misc/tramp.texi (Inline methods): Shorten kubernetes entry. (Kubernetes setup): New node. (Top, Configuration): Add it to the menu. * lisp/net/tramp-container.el (tramp-kubernetes--context-namespace): Adapt dpcstring. (tramp-kubernetes-connection-local-default-profile) (tramp-kubernetes-connection-local-default-variables) (tramp-flatpak-connection-local-default-profile) (tramp-flatpak-connection-local-default-variables): Rename. * lisp/net/tramp.el (tramp-expand-args): Use `tramp-compat-take'. * test/lisp/net/tramp-tests.el (tramp-test34-connection-local-variables) (tramp-test34-explicit-shell-file-name): Don't let-bind `connection-local-profile-alist' and `connection-local-criteria-alist'. diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 01f46865a39..27145c3cca1 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -142,6 +142,7 @@ Top * Ssh setup:: Ssh setup hints. * FUSE setup:: @acronym{FUSE} setup hints. * Android shell setup:: Android shell setup hints. +* Kubernetes setup:: Kubernetes setup hints. * Auto-save File Lock and Backup:: Auto-save, File Lock and Backup. * Keeping files encrypted:: Protect remote files by encryption. @@ -700,6 +701,7 @@ Configuration * Ssh setup:: Ssh setup hints. * FUSE setup:: @acronym{FUSE} setup hints. * Android shell setup:: Android shell setup hints. +* Kubernetes setup:: Kubernetes setup hints. * Auto-save File Lock and Backup:: Auto-save, File Lock and Backup. * Keeping files encrypted:: Protect remote files by encryption. @@ -921,16 +923,10 @@ Inline methods @cindex method @option{kubernetes} @cindex @option{kubernetes} method -Integration for containers in Kubernetes pods. The host name is a pod -name returned by @samp{kubectl get pods}, or -@samp{@var{container}.@var{pod}} if an explicit container name shall -be used. Otherwise, the first container in a pod is used. - -@vindex tramp-kubernetes-context -@vindex tramp-kubernetes-namespace -If another Kubernetes context or namespace shall be used, configure -the user options @code{tramp-kubernetes-context} and -@code{tramp-kubernetes-namespace}. +Integration for containers in Kubernetes pods. The host name is +@samp{@var{pod}}, or @samp{@var{container}.@var{pod}} if an +explicit container name shall be used. Otherwise, the first container +in a pod is used. This method does not support user names. @@ -3122,6 +3118,29 @@ Android shell setup @end itemize +@node Kubernetes setup +@section Kubernetes setup hints + +With the @option{kubernetes} method, containers in Kubernetes pods can +be accessed. The host name is a pod name returned by @samp{kubectl +get pods}, or @samp{@var{container}.@var{pod}} if an explicit +container name shall be used. Otherwise, the first container in a pod +is used. + +Sometimes, asynchronous processes for a host without a dedicated +container name show a warning like @samp{Defaulted container +"container1" out of: container1, container2}. This can be mitigated +by setting the pod annotation +@samp{kubectl.kubernetes.io/default-container} to a proper value +(@samp{container1} in this example). + +@vindex tramp-kubernetes-context +@vindex tramp-kubernetes-namespace +@value{tramp} uses the default Kubernetes context and namespace. If +another context or namespace shall be used, configure the user options +@code{tramp-kubernetes-context} and @code{tramp-kubernetes-namespace}. + + @node Auto-save File Lock and Backup @section Auto-save, File Lock and Backup configuration @cindex auto-save diff --git a/lisp/net/tramp-container.el b/lisp/net/tramp-container.el index 6e8d28a3016..7f8d4473ad7 100644 --- a/lisp/net/tramp-container.el +++ b/lisp/net/tramp-container.el @@ -256,7 +256,7 @@ tramp-kubernetes--current-context-data ;;;###tramp-autoload (defun tramp-kubernetes--context-namespace (vec) - "The kubectl options for context and namespace." + "The kubectl options for context and namespace as string." (mapconcat #'identity `(,(when-let ((context (tramp-kubernetes--current-context vec))) @@ -404,7 +404,7 @@ tramp-default-remote-shell ;; Default connection-local variables for Tramp. - (defconst tramp-container-connection-local-default-kubernetes-variables + (defconst tramp-kubernetes-connection-local-default-variables '((tramp-config-check . tramp-kubernetes--current-context-data) ;; This variable will be eval'ed in `tramp-expand-args'. (tramp-extra-expand-args @@ -414,24 +414,24 @@ tramp-default-remote-shell "Default connection-local variables for remote kubernetes connections.") (connection-local-set-profile-variables - 'tramp-container-connection-local-default-kubernetes-profile - tramp-container-connection-local-default-kubernetes-variables) + 'tramp-kubernetes-connection-local-default-profile + tramp-kubernetes-connection-local-default-variables) (connection-local-set-profiles `(:application tramp :protocol ,tramp-kubernetes-method) - 'tramp-container-connection-local-default-kubernetes-profile) + 'tramp-kubernetes-connection-local-default-profile) - (defconst tramp-container-connection-local-default-flatpak-variables + (defconst tramp-flatpak-connection-local-default-variables `((tramp-remote-path . ,(cons "/app/bin" tramp-remote-path))) "Default connection-local variables for remote flatpak connections.") (connection-local-set-profile-variables - 'tramp-container-connection-local-default-flatpak-profile - tramp-container-connection-local-default-flatpak-variables) + 'tramp-flatpak-connection-local-default-profile + tramp-flatpak-connection-local-default-variables) (connection-local-set-profiles `(:application tramp :protocol ,tramp-flatpak-method) - 'tramp-container-connection-local-default-flatpak-profile)) + 'tramp-flatpak-connection-local-default-profile)) (add-hook 'tramp-unload-hook (lambda () diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index cbd4e1611eb..f64abbcf06e 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -4968,7 +4968,8 @@ tramp-expand-args ;; Merge both spec lists. Remove duplicate entries. (while spec-list (unless (member (car spec-list) extra-spec-list) - (setq extra-spec-list (append (take 2 spec-list) extra-spec-list))) + (setq extra-spec-list + (append (tramp-compat-take 2 spec-list) extra-spec-list))) (setq spec-list (cddr spec-list))) (setq spec (apply #'format-spec-make extra-spec-list)) ;; Expand format spec. diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index a2e57e468c1..45bcf23f790 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -6136,8 +6136,7 @@ tramp-test34-connection-local-variables (inhibit-message t) kill-buffer-query-functions (clpa connection-local-profile-alist) - (clca connection-local-criteria-alist) - connection-local-profile-alist connection-local-criteria-alist) + (clca connection-local-criteria-alist)) (unwind-protect (progn (make-directory tmp-name1) @@ -6219,8 +6218,7 @@ tramp-test34-explicit-shell-file-name (let ((default-directory ert-remote-temporary-file-directory) explicit-shell-file-name kill-buffer-query-functions (clpa connection-local-profile-alist) - (clca connection-local-criteria-alist) - connection-local-profile-alist connection-local-criteria-alist) + (clca connection-local-criteria-alist)) (unwind-protect (progn (connection-local-set-profile-variables commit dcd92090950929eeea3040fcac0294b7a4d839f0 Author: Stefan Monnier Date: Wed Jun 28 09:24:30 2023 -0400 * lisp/emacs-lisp/cl-macs.el (cl--slet): Fix bug#64315 diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index aadb498609a..0a3181561bd 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -246,10 +246,10 @@ cl--bind-lets (defun cl--slet (bindings body &optional nowarn) "Like `cl--slet*' but for \"parallel let\"." (let ((dyns nil)) ;Vars declared as dynbound among the bindings? - ;; `seq-some' lead to bootstrap problems. - (dolist (binding bindings) - (when (macroexp--dynamic-variable-p (car binding)) - (push (car binding) dyns))) + (when lexical-binding + (dolist (binding bindings) ;; `seq-some' lead to bootstrap problems. + (when (macroexp--dynamic-variable-p (car binding)) + (push (car binding) dyns)))) (cond (dyns (let ((form `(funcall (lambda (,@(mapcar #'car bindings)) commit 85335157dd4a8bf6a0c92525360ec35362750c30 Author: Mattias EngdegÄrd Date: Wed Jun 28 14:36:39 2023 +0200 Speed up duplicate-dwim and duplicate-line by another factor 10 * lisp/misc.el (duplicate--insert-copies): New. (duplicate-line, duplicate-dwim): Call it. diff --git a/lisp/misc.el b/lisp/misc.el index de82b97fa6f..ab083728a69 100644 --- a/lisp/misc.el +++ b/lisp/misc.el @@ -63,6 +63,10 @@ copy-from-above-command (+ n (point))))))) (insert string))) +(defun duplicate--insert-copies (n string) + "Insert N copies of STRING at point." + (insert (mapconcat #'identity (make-list n string)))) + ;;;###autoload (defun duplicate-line (&optional n) "Duplicate the current line N times. @@ -78,8 +82,7 @@ duplicate-line (forward-line 1) (unless (bolp) (insert "\n")) - (dotimes (_ n) - (insert line))))) + (duplicate--insert-copies n line)))) (declare-function rectangle--duplicate-right "rect" (n)) @@ -111,8 +114,7 @@ duplicate-dwim (text (buffer-substring beg end))) (save-excursion (goto-char end) - (dotimes (_ n) - (insert text)))) + (duplicate--insert-copies n text))) (setq deactivate-mark nil)) ;; Duplicate line.