Hello!
Phillip Lord writes:
> I've been using muse-get-keywords to extract information
> from
> muse-project-alist.
>
> So, something like this...
>
> (muse-get-keyword :trail (muse-project "project"))
>
> :trail being a keyword for one of my packages.
>
> This all works fine.
I am using muse version "3.12". As far as I understand `muse-get-keyword'
only operates on flat list '(keyword el keword el ...). As a consequence the
above code returns nil when I apply it with a keyword (such as :path or
:default) on a list returned by `muse-project'.
> I need a function that adds :trail and a value if it's not
> there, and replaces the existing value if it is.
A function that sets values on the type of lists `muse-get-keyword' works on
(at least muse version "3.12") in the way you require may look like this:
(defun my-muse-set-keyword (keyword list new-el &optional direct)
"Replace the element EL that immediately follows KEYWORD in the list LIST to
NEW-EL if KEYWORD is present, otherwise prepend KEYWORD and NEW-EL to LIST.
Return the modified LIST.
It is assumed that LIST is a flat list of the following
structure: '(keyword element keyword element ...). If NEW-EL is a
symbol set EL to the value of EL by default. If DIRECT is not nil
and NEW-EL is a symbol set E to the name of NEW-EL."
(let ((list-rest (cdr (memq keyword list)))
(new-el (if (and (not direct) (symbolp new-el))
(symbol-value new-el)
new-el)))
(if list-rest
(progn
(setcar list-rest new-el)
list)
(setq list (cons keyword (cons new-el list))))))
Note: Contra to the well reputed practice of (e)lisp programs this code
_modifies_ the list in place and does not merely returen a modified copy. I do
not know if this fits your requirements.
Kind regards
Stefan
_______________________________________________
Muse-el-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/muse-el-discuss