Authentication-Results: mail-b.sr.ht; dkim=pass header.d=phundrak.com header.i=@phundrak.com Received: from mail.phundrak.com (105.ip-51-83-47.eu [51.83.47.105]) by mail-b.sr.ht (Postfix) with ESMTPS id E904411EF48 for <~bzg/emacsfr@lists.sr.ht>; Wed, 15 Jun 2022 12:45:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 78052C00A8 for <~bzg/emacsfr@lists.sr.ht>; Wed, 15 Jun 2022 14:45:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=phundrak.com; s=dkim; t=1655297145; h=from:subject:date:message-id:to:mime-version:content-type; bh=3u+VQtHVOGDZESSsY+kwhzylFIr0N4WcmGIWVTkAUOw=; b=bRWP8O0maTy2Y63ZwFJYpdvVzqD5BD4BWYGJPmuhcANVhz1N+LrgFCO/XL02FbGDtFAny9 UTwUi9SBMN1p1Di5h5hSjFV+C3ZWhoMNn2HF8XfPuRE7ujTLiBCTiFu0kmvj1TEG3Ncn/R YsGWYRNmeqaKPpC7OvWGe5EhQyRSyGI= From: Lucien Cartier-Tilet To: ~bzg/emacsfr@lists.sr.ht Subject: Macro pour les variables custom Date: Wed, 15 Jun 2022 14:34:21 +0200 User-agent: mu4e 1.6.11; emacs 29.0.50 Message-ID: <87tu8m6qog.fsf@phundrak.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="===-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Last-TLS-Session-Version: TLSv1.3 --===-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: multipart/mixed; boundary="==-=-=" --==-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello=E2=80=AF! Je suis en train de bosser sur une petite macro qui permettrait de r=C3=A9soudre chez moi un probl=C3=A8me assez p=C3=A9nible=E2=80=AF: g=C3= =A9rer simplement la valeur des variables custom (d=C3=A9clar=C3=A9es avec `defcustom'). Le truc est que les variables custom peuvent avoir leur propre setter afin de modifier d=E2=80=99autres valeus ailleurs et ex=C3=A9cuter du code = lorsque la valeur de la variable est chang=C3=A9e, chose qui ne se produit pas lorsqu=E2=80=99on utilise `setq'. La solution =C3=A9vidente serait d=E2=80= =99utiliser `custom-set-variables', mais je ne trouve pas cette fonction agr=C3=A9able = =C3=A0 utiliser face =C3=A0 la simplicit=C3=A9 de `setq'. Du coup, inspir=C3=A9 par [cet article], je vous pr=C3=A9sente ma solution = pour une macro ayant une syntaxe similaire =C3=A0 `setq' mais appliquant correctement (je l=E2=80=99esp=C3=A8re) les nouvelles valeurs aux variables= custom. Ma contribution principale =C3=A0 la macro originale est de pouvoir lui donner plus qu=E2=80=99un couple forme/valeur =C3=A0 la fois, comme avec `s= etq'. ,---- | (defmacro csetq (&rest forms) | "Bind each custom variable FORM to the value of its VAL. |=20 | FORMS is a list of pairs of values [FORM VAL]. |=20 | If FORM has a custom setter, use it to set FORM to VAL. | Otherwise, use `set-default'. |=20 | \(fn [FORM VAL]...)" | (declare (debug (&rest sexp form)) | (indent 1)) | ;; Check if we have an even number of arguments | (when (=3D (mod (length forms) 2) 1) | (signal 'wrong-number-of-arguments (list 'csetq (1+ (length forms))))) | (let* (forms-and-values form value) | ;; Transform FORMS into a list of pairs (FORM . VALUE) | (while forms | (setq form (pop forms)) | (setq value (pop forms)) | (add-to-list 'forms-and-values `(,form . ,value) t)) | ;; Apply VAL to FORM | `(progn ,@(mapcar (lambda (form) | `(,(or (get `,(car form) 'custom-set) | 'set-default) | ',(car form) | ,(cdr form))) | forms-and-values)))) `---- Si jamais vous avez des retours pour des am=C3=A9liorations du code, je suis preneur. =2D- Lucien =E2=80=9CPhundrak=E2=80=9D Cartier-Tilet (Fran=C3=A7ais) (English) Sent from GNU/Emacs [cet article] --==-=-=-- --=-=-=-- --===-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJIBAEBCAAyFiEEViv9D3b9mE+uAC3AvXeJ5wXLjcoFAmKp1G8UHGx1Y2llbkBw aHVuZHJhay5jb20ACgkQvXeJ5wXLjcpRmA/9FeuV+IQQl12AfbAuC2lTb4xAhqVQ brxJdFyjqa0ucxwJ2L1dEiLr7P69AutZLiLeKefmwwTZ7CaGA6rSeAk+mJA4XnoJ owSJeRK27XYeBdAxfkseowhBxktaEp1QDzZt/v10R+CnSxI7mm1WTyfPvt+cKPLO DZPyyIvGxW2lI8kJbauOxuEB7AwFKcFu2UpXdGGAtZZbT71OeAEjNrbKyjbGnsfG uIqZplzSV98qmvwrg85Dj/n6xnnaJ8NOjRUNBZsHHXid45+4/RuOg3HySmGWfQ7x 6iMJVikZ7Oq/th2mgITe/BGXR8a2aeTgV/cNHIrZ+27KYocBXrCjj+zQUZl+azRD LiTa00U75waoWvRP1En5S4PbHxcUeOK+JAZz8i3T/kcoUI3wmNfEmiIHN1pNKoc/ 9djRQYi7fyijgNm1P77CYNiabV8Y1INXt8YwUwv8Lh5/9p0qnF1o2HNLn1PXmFs/ pNnjIewPKWlFO9+sEdWGsq+pLhmxnHVdI/xYqTqnpj0QnJ96jN+RPtsaCf6upzo2 tLk+2/wVsLuGjq5XvOM+/WxqxFkVScNOubxoTwlEd6PNx4OnCDMwqZERh/4sdkx9 PZt84CZFVoSfWPJiK8Yc5l1AJCkgY51gp+E4bqCjJT+HI9xb2wmXisaJxw4M8+DT WtMGhG5IRhLkBuQ= =NvQA -----END PGP SIGNATURE----- --===-=-=--