unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: general-purpose Gnus-style matching in a list function?
       [not found] <87zjocvvd9.fsf@flea.lifelogs.com>
@ 2013-12-08 16:17 ` Ted Zlatanov
  0 siblings, 0 replies; only message in thread
From: Ted Zlatanov @ 2013-12-08 16:17 UTC (permalink / raw)
  To: ding; +Cc: emacs-devel

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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-12-08 16:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87zjocvvd9.fsf@flea.lifelogs.com>
2013-12-08 16:17 ` general-purpose Gnus-style matching in a list function? Ted Zlatanov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).