Re: Using the :set to make an alist
Heime <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <hsived7nJSRc2D4k5LmFpvpAsHyIUaVltLt3fS5e1oAEjPeFj9xy2J_i-K8Il_8NXiK6OO2sNsZl3qibfEgTCoBcDJKmcemo_GSx3T0jKcw=@protonmail.com> |
On Wednesday, August 19th, 2026 at 11:52 AM, [email protected] <[email protected]> wrote: > Heime <[email protected]> writes: > > > I want a customisable variable that is an alist with elements (key . directory-path). > > > > Have made the :set function to set the list by appending sub-directories using orellana-fpln base directories. Because usually one uses (set-default symbol value) to set the value, I do not understand how this can be applied to a list. > > > > (defcustom galaxiakos-fpln nil > > "Association List (alist) specifying a flight plan, where each element is > > a cons cell (WAYPT . DIRECTORY-PATH) linking a waypoint code to its > > associated directory path for different Galaxiakos components." > > :group 'galaxiakos > > :type '(alist :key-type (symbol :tag "Code") > > :value-type (string :tag "Path")) > > :set (lambda (symbol value) > > (set-default symbol value) > > (let ( (glxks-waypt (assoc-default 'GLXKS orellana-fpln) ) > > (when glxks-waypt > > (setq galaxiakos-fpln > > `((GLXKS . ,glxks-waypt) > > (OMNIX . ,(concat glxks-waypt "/omniskon")) > > (PROTL . ,(concat glxks-waypt "/protilus")) > > (GRGRS . ,(concat glxks-waypt "/gregers"))) )) )) ) > > > > > > 1. Using ‘setopt’, the value of ‘galaxiakos-fpln’ can be set to > the alist '((PROTL . "path1") (OMNIX . "path2")) as follows: > > (setopt galaxiakos-fpln '((PROTL . "path1") (OMNIX . "path2"))) > > C-h v galaxiakos-fpln RET > > galaxiakos-fpln’s value is ((PROTL . "path1") (OMNIX . "path2")) > > 2. If ‘orellana-fpln’ is set to an association list with an > entry for ‘GLXKS’, then the value of ‘galaxiakos-fpln’ will > be set according the value that corresponds to the ‘GLXKS’ entry. > > So, if the entry is, say, (GLXKS . "my-path"), then > > (setopt galaxiakos-fpln '((PROTL . "path1") (OMNIX . "path2"))) Where should I call setopt exactly? > will *NOT* add these values to ‘galaxiakos-fpln’. Instead, > its value will be: > > ((GLXKS . "my-path") > (OMNIX . "my-path/omniskon") > (PROTL . "my-path/protilus") > (GRGRS . "my-path/gregers")) > > 3. Your question does not describe what you want the :set > function to do. If you want it to add/change/delete a set > of key/value pairs, then you will need to change your > function to update the association list. See: I want users to change the paths should they prefer. > M-x shortdoc alist > > and > > (info "(elisp) Association Lists") > > 4. You might want to write the :set function as a separate > function outside of the (defcustom ...) form to define what > you want it to do, and then add the function definition to > (defcustom ...) after you have worked out the details. Have made the separate function (defun galaxiakos-fpln-update (symbol value) "Custom setter for `galaxiakos-fpln'. Updates the variable's value and refreshes internal path associations." (set-default symbol value) (let ((glxks-waypt (assoc-default 'GLXKS orellana-fpln))) (when glxks-waypt (set symbol `((GLXKS . ,glxks-waypt) (OMNIX . ,(concat glxks-waypt "/omniskon")) (PROTL . ,(concat glxks-waypt "/protilus")) (GRGRS . ,(concat glxks-waypt "/gregers"))))))) (defcustom galaxiakos-fpln nil "Association List (alist) specifying a flight plan, where each element is a cons cell (WAYPT . DIRECTORY-PATH) linking a waypoint code to its associated directory path for different Galaxiakos components." :group 'galaxiakos :type '(alist :key-type (symbol :tag "Code") :value-type (string :tag "Path")) :set #'galaxiakos-fpln-update) > The lyf so short, the craft so long to lerne. > - Geoffrey Chaucer, The Parliament of Birds. > >