all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: [External] : Re: Appending lists
Date: Sun, 20 Jun 2021 18:09:52 -0400	[thread overview]
Message-ID: <jwvzgvk19dw.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 87im28gvsx.fsf@zoho.eu

>   ;; (setq completion-ignored-extensions
>   ;;       (nconc completion-ignored-extensions '(".bcf" ".elc" ".run.xml")) )
> can be changed into (should be changed, since the above makes
> no difference - ?) it can be changed into
>   (nconc completion-ignored-extensions '(".bcf" ".run.xml"))

That will fail to do what you want if `completion-ignored-extensions`
was empty just before executing the code.
And it will have undesirable side effects if
`completion-ignored-extensions` happened to hold a list some parts of
which are also used elsewhere, e.g. if it was by a code such as

    (setq completion-ignored-extensions '("some" "constant" "list"))

Since you probably don't perform this operation inside a tight loop
where performance could be significant I'd recommend you just use
`append` instead.

>   ;; (let ((modes (list
>   ;;               '("\\.bal\\'"     . balance-mode)
>   ;;               '("\\.grm\\'"     . sml-mode)
>   ;;               '("\\.lu\\'"      . lua-mode)
>   ;;               '("\\.nqp\\'"     . perl-mode)
>   ;;               '("\\.php\\'"     . html-mode)
>   ;;               '("\\.pic\\'"     . nroff-mode)
>   ;;               '("\\.pl\\'"      . prolog-mode)
>   ;;               '("\\.sed\\'"     . conf-mode)
>   ;;               '("\\.service\\'" . conf-mode)
>   ;;               '("\\.tex\\'"     . latex-mode)
>   ;;               '("\\.xr\\'"      . conf-xdefaults-mode)
>   ;;               '("*"             . text-mode) )))
>   ;;   (setq auto-mode-alist (nconc modes auto-mode-alist)) )
>
> might as well be
>
>   (nconc (list
>           '("\\.bal\\'"     . balance-mode)
>           '("\\.grm\\'"     . sml-mode)
>           '("\\.lu\\'"      . lua-mode)
>           '("\\.nqp\\'"     . perl-mode)
>           '("\\.php\\'"     . html-mode)
>           '("\\.pic\\'"     . nroff-mode)
>           '("\\.pl\\'"      . prolog-mode)
>           '("\\.sed\\'"     . conf-mode)
>           '("\\.service\\'" . conf-mode)
>           '("\\.tex\\'"     . latex-mode)
>           '("\\.xr\\'"      . conf-xdefaults-mode)
>           '("*"             . text-mode) )
>          auto-mode-alist)

Here `nconc` is a safe replace for `append` because indeed the first arg
is a list you just constructed by `list` so you know for sure it's not
shared with anything else.

But the second above code is just an expensive no-op because your
`nconc` will modify its first argument and not its second, so it will
construct a new list, will add the content of `auto-mode-alist` to its
end and then throw away the result.

Here's another way you could write the code:

    (setq auto-mode-alist 
          `(("\\.bal\\'"     . balance-mode)
            ("\\.grm\\'"     . sml-mode)
            ("\\.lu\\'"      . lua-mode)
            ("\\.nqp\\'"     . perl-mode)
            ("\\.php\\'"     . html-mode)
            ("\\.pic\\'"     . nroff-mode)
            ("\\.pl\\'"      . prolog-mode)
            ("\\.sed\\'"     . conf-mode)
            ("\\.service\\'" . conf-mode)
            ("\\.tex\\'"     . latex-mode)
            ("\\.xr\\'"      . conf-xdefaults-mode)
            ("*"             . text-mode)
            ,@auto-mode-alist))


-- Stefan




  parent reply	other threads:[~2021-06-20 22:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-17  3:18 Appending lists Drew Adams
2021-06-17  7:48 ` tomas
2021-06-18 23:38   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-18 23:50   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-19  6:57     ` tomas
2021-06-19 21:31       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-19 22:07         ` [External] : " Drew Adams
2021-06-20 19:50           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-20 19:58             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-20 20:10               ` Jean Louis
2021-06-20 20:27                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-20 19:59             ` Jean Louis
2021-06-20 20:22               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-20 20:42               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-20 20:49                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-20 21:49                   ` Jean Louis
2021-06-20 22:54                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-20 23:30                       ` Jean Louis
2021-06-21  0:29                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-20 21:46                 ` Jean Louis
2021-06-20 22:09             ` Stefan Monnier via Users list for the GNU Emacs text editor [this message]
2021-06-20 23:04               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-20 23:10                 ` Emanuel Berg via Users list for the GNU Emacs text editor
  -- strict thread matches above, loose matches on Subject: below --
2021-06-16 14:16 Drew Adams
2021-06-16 17:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 18:00   ` Drew Adams
2021-06-14 16:36 Pierpaolo Bernardi
2021-06-14 16:40 ` henri-biard
2021-06-14 18:21   ` Alexandr Vityazev
2021-06-15  0:46     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  8:27       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  9:18         ` tomas
2021-06-16  1:11           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16  7:28             ` tomas
2021-06-16 16:42               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 16:55                 ` [External] : " Drew Adams
2021-06-16 17:06                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 17:54                     ` Drew Adams
2021-06-16 23:49                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-17  7:54                         ` tomas
2021-06-18 23:55                           ` Emanuel Berg via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvzgvk19dw.fsf-monnier+emacs@gnu.org \
    --to=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.