GNU bug report logs - #75170
add-to-alist: new function

Previous Next

Package: emacs;

Reported by: Roland Winkler <winkler <at> gnu.org>

Date: Sun, 29 Dec 2024 05:35:02 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: Roland Winkler <winkler <at> gnu.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, Eli Zaretskii <eliz <at> gnu.org>, 75170 <at> debbugs.gnu.org
Subject: bug#75170: add-to-alist: new function
Date: Sun, 19 Jan 2025 15:17:56 -0600
On Sun, Jan 19 2025, Juri Linkov wrote:
> Isn't NO-REPLACE equivalent to this:
>
>   (cl-pushnew "statement2" (alist-get 'sentence (alist-get 'c treesit-thing-settings)))
>
> that results in
>
>   ((c (sexp (not "[](),[{}]"))
>       (sentence "statement2" "statement")
>       (text "\\(?:comment\\|raw_string_literal\\)")))

I am not sure how to read the above example.  But it seems to me, it is
different from what NO-REPLACE does.  (Anyway, it is a piece of code
that I would not want to suggest to users to put into their init file.)

With NO-REPLACE non-nil, add-to-list will add a new association for KEY,
if KEY is not yet a key in the alist.  But if the alist already contains
an association for KEY, this association will not be modified.

Stephen's original proposal illustrated how this can be useful in a
user's init file in the context of auto-mode-alist:

On Mon, 12 Feb 2001, Stephen Gildea wrote:
> The no-replace argument is useful for setting auto-mode-alist when you
> don't know whether Emacs supports a particular programming language.
> For example, the following suppresses using text-mode for m4 files in
> Emacs 19 but doesn't override using m4-mode in Emacs 20.
> 
> (setq default-major-mode 'text-mode)
> (add-to-alist 'auto-mode-alist '("\\.m4\\'" . fundamental-mode) t)




This bug report was last modified 142 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.