* Little help with defcustom
@ 2020-11-09 9:12 Jean Louis
2020-11-09 13:41 ` Joost Kremers
0 siblings, 1 reply; 5+ messages in thread
From: Jean Louis @ 2020-11-09 9:12 UTC (permalink / raw)
To: GNU Emacs Help
I need little help with defcustom. I would like to define defcustom
structure for:
Multiple inserts INS DEL:
- Server name
- Host name
- User name
- Password
- Port number (integer up to 65535)
- Activated (boolean)
And then to define second defcustom structure with multiple inserts
INS DEL:
- Server name (referencing the above server name)
- Set name (belonging to this server)
- Node ID (integer, by default empty)
- Updatable (boolean)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Little help with defcustom
2020-11-09 9:12 Little help with defcustom Jean Louis
@ 2020-11-09 13:41 ` Joost Kremers
2020-11-09 16:35 ` Jean Louis
0 siblings, 1 reply; 5+ messages in thread
From: Joost Kremers @ 2020-11-09 13:41 UTC (permalink / raw)
To: help-gnu-emacs
On Mon, Nov 09 2020, Jean Louis wrote:
> I need little help with defcustom. I would like to define defcustom
> structure for:
>
> Multiple inserts INS DEL:
>
> - Server name
> - Host name
> - User name
> - Password
> - Port number (integer up to 65535)
> - Activated (boolean)
>
> And then to define second defcustom structure with multiple inserts
> INS DEL:
>
> - Server name (referencing the above server name)
> - Set name (belonging to this server)
> - Node ID (integer, by default empty)
> - Updatable (boolean)
You can get the multiple inserts with the customisation type `repeat'. Other
than that, it's hard to give you any specific advice because you're not saying
what you're having trouble with. Have you looked at the documentation (info
"(elisp) Customization")? There are also tons of defcustoms in the Emacs source,
so you could take a user option in a Customize buffer that looks like what you
want and then check out how it's defined.
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Little help with defcustom
2020-11-09 13:41 ` Joost Kremers
@ 2020-11-09 16:35 ` Jean Louis
2020-11-09 19:14 ` Joost Kremers
0 siblings, 1 reply; 5+ messages in thread
From: Jean Louis @ 2020-11-09 16:35 UTC (permalink / raw)
To: Joost Kremers; +Cc: help-gnu-emacs
* Joost Kremers <joostkremers@fastmail.fm> [2020-11-09 16:48]:
> On Mon, Nov 09 2020, Jean Louis wrote:
> > I need little help with defcustom. I would like to define defcustom
> > structure for:
> >
> > Multiple inserts INS DEL:
> >
> > - Server name
> > - Host name
> > - User name
> > - Password
> > - Port number (integer up to 65535)
> > - Activated (boolean)
:type '(repeat
(list :tag "Dynamical User Sets"
(string :tag " Server")
(string :tag "Set name")
(string :tag " Node ID"))))
Thank you.
I have succeeded randomly with the above. I know that is not best
style of programming (too nicely said) and I do read documentation but
I do not read enough.
I see that to achieve best formatting I have to pad with spaces those
strings. Is there maybe better way?
> Other than that, it's hard to give you any specific advice because
> you're not saying what you're having trouble with. Have you looked
> at the documentation (info "(elisp) Customization")? There are also
> tons of defcustoms in the Emacs source, so you could take a user
> option in a Customize buffer that looks like what you want and then
> check out how it's defined.
Before sending email I have read documentation and I searching similar
example to what I was thinking should be similar. And did not finish
searching examples. Most similar example was for accounts set in
jabber.el XMPP chat client.
Is there a way to make sure that field is not empty?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Little help with defcustom
2020-11-09 16:35 ` Jean Louis
@ 2020-11-09 19:14 ` Joost Kremers
2020-11-09 20:31 ` Jean Louis
0 siblings, 1 reply; 5+ messages in thread
From: Joost Kremers @ 2020-11-09 19:14 UTC (permalink / raw)
To: help-gnu-emacs
On Mon, Nov 09 2020, Jean Louis wrote:
> :type '(repeat
> (list :tag "Dynamical User Sets"
> (string :tag " Server")
> (string :tag "Set name")
> (string :tag " Node ID"))))
[...]
> I see that to achieve best formatting I have to pad with spaces those
> strings. Is there maybe better way?
Not that I know of, no. I never bother, but it would be nice to be able to align
the fields.
> Is there a way to make sure that field is not empty?
Honestly, I don't know. The Elisp manual says there's a `:validate' keyword that
can be used to provide a function for validating the input. I've never used it,
but here's an example from the Emacs sources (`lisp/calendar/todo.el`):
```
(defcustom todo-prefix ""
"String prefixed to todo items for visual distinction."
:type '(string :validate
(lambda (widget)
(when (string= (widget-value widget) todo-item-mark)
(widget-put
widget :error
(format-message
"Invalid value: must be distinct from `todo-item-mark'"))
widget)))
:initialize 'custom-initialize-default
:set 'todo-reset-prefix
:group 'todo-display)
```
You could even test whether a field has the correct format.
HTH
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Little help with defcustom
2020-11-09 19:14 ` Joost Kremers
@ 2020-11-09 20:31 ` Jean Louis
0 siblings, 0 replies; 5+ messages in thread
From: Jean Louis @ 2020-11-09 20:31 UTC (permalink / raw)
To: Joost Kremers; +Cc: help-gnu-emacs
Thank you for taking references and finding :validate, I will use it.
Jean
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-09 20:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-09 9:12 Little help with defcustom Jean Louis
2020-11-09 13:41 ` Joost Kremers
2020-11-09 16:35 ` Jean Louis
2020-11-09 19:14 ` Joost Kremers
2020-11-09 20:31 ` Jean Louis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).