Gnus development mailing list
 help / color / mirror / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: ding@gnus.org
Cc: emacs-devel@gnu.org
Subject: Re: general-purpose Gnus-style matching in a list function?
Date: Sun, 08 Dec 2013 11:17:07 -0500	[thread overview]
Message-ID: <87haajwc58.fsf@flea.lifelogs.com> (raw)
In-Reply-To: <87zjocvvd9.fsf@flea.lifelogs.com>

On Sat, 07 Dec 2013 23:07:14 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote: 

TZ> `gnus-posting-styles' is a good example of a very flexible defcustom
TZ> that gets special treatment so the keys and the values can be almost
TZ> anything: functions, regexps, strings, etc.

TZ> It's processed in a special way by `gnus-configure-posting-styles' and I
TZ> was wondering if Gnus has a general-purpose function to do this.  If
TZ> not, it should... I would shadow it in the Emacs core actually, it's a
TZ> very common usage pattern.

Following up to emacs-devel as well for any suggestions.

Here's the common use case: I have some options that may change based on
some context (group name, in the case of `gnus-posting-styles').  This
comes up very often in all parts of Emacs, where you want to customize
things per file name, per hostname, and so on.

It's essentially a form of pattern matching, right?  Kind of like
`pcase' but for defcustoms.  So Gnus ends up with something like this
(again, this is an example, there are many other such defcustoms):

#+begin_src lisp
(defcustom gnus-posting-styles nil
  "*Alist of styles to use when posting.
See Info node `(gnus)Posting Styles'."
  :group 'gnus-message
  :link '(custom-manual "(gnus)Posting Styles")
  :type '(repeat (cons (choice (regexp)
			       (variable)
			       (list (const header)
				     (string :tag "Header")
				     (regexp :tag "Regexp"))
			       (function)
			       (sexp))
		       (repeat (list
				(choice (const signature)
					(const signature-file)
					(const organization)
					(const address)
					(const x-face-file)
					(const name)
					(const body)
					(symbol)
					(string :tag "Header"))
				(choice (string)
					(function)
					(variable)
					(sexp)))))))

#+end_src

This is really nice for the users, who can go wild with customizations.
But to extract the parameters, you end up writing complicated functions
like `gnus-configure-posting-styles'.  So my question was, does this
exist already, or do I have to reinvent it?  And is `pcase' the right
style, in which case it should be better integrated with the defcustom
facilities?

Thanks
Ted




  reply	other threads:[~2013-12-08 16:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-08  4:07 Ted Zlatanov
2013-12-08 16:17 ` Ted Zlatanov [this message]
2013-12-26 16:17 ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87haajwc58.fsf@flea.lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=ding@gnus.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).