Re: Using the :set to make an alist

[email protected]
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
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")))

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:

   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.

-- 
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.