guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add helper for .desktop file creation?


From: Pierre Neidhardt
Subject: Re: Add helper for .desktop file creation?
Date: Mon, 27 May 2019 18:45:49 +0200

Nicolas Goaziou <address@hidden> writes:

> Not what you're asking for, but I had a few comments about the
> implementation:

Thanks for the feedback!

>> --8<---------------cut here---------------start------------->8---
>> (define* (make-desktop-entry-file destination #:key
>>                                   (type "Application") ; One of 
>> "Application", "Link" or "Directory".
>>                                   (version "1.1")
>>                                   name
>>                                   (generic-name name)
>>                                   (no-display #f)
>
> What about only providing default values only for mandatory keys, i.e.,
> only "type" (name is also mandatory, but it has no default value).
> I think the function currently adds entries that are not necessary.

Nope, the current function only forces "Type" (the only mandatory
field), everything else is omitted unless the key is explicitly set by
the user.  This is because I looped over ALL-ARGS (the #:rest argument)
and I force-added #:type to it.

>>   (define* (parse key value #:optional locale)
>>     (set! value (match value
>>                   (#t "true")
>>                   (#f "false")
>>                   ((?  number? n) n)
>>                   ((?  string? s) (escape-semicolon s))
>>                   ((?  list? value)
>>                    (catch 'wrong-type-arg
>>                      (lambda () (string-join (map escape-semicolon value) 
>> ";"))
>>                      (lambda args (error "List arguments can only contain 
>> strings: ~a" args))))
>>                   (_ (error "Value must be a boolean, number, string or list 
>> of strings"))))
>>     (format #t "~a=~a~%"
>>             (if locale
>>                 (format #f "~a[~a]" key locale)
>>                 key)
>>             value))
>
> I wonder if it wouldn't be better to stick to the specification. For
> example :comment expects a string, or an alist: shouldn't the function
> return an error if its value is something else?

True, but that's more work ;)

I did not implement the full specs simply because I decided to draw an
arbitrary line between short code, convenience and completeness.  This
is debatable of course and maybe a simple type-checking would not cost much.

Supporting the full specs would require a significant amount of work however.

>>            (set! key
>>                  (string-join (map string-titlecase
>>                                    (string-split (symbol->string
>>                                                   (keyword->symbol key))
>>                                                  #\-))
>>                               ""))
>
> The docstring may explain that, e.g., compound :mime-type key becomes
> MimeType.

Hmm, OK but why?  The procedure produces the expected behaviour with
#:mime-type, is there anything else to clarify?

> In any case, it looks nice and useful.

Thanks!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]