unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Test for `save-abbrevs' improvement
@ 2006-02-16 14:39 Juanma Barranquero
  2006-02-16 20:46 ` Kevin Rodgers
  0 siblings, 1 reply; 6+ messages in thread
From: Juanma Barranquero @ 2006-02-16 14:39 UTC (permalink / raw)


Often it is said here that it is best to check for features, and not
for specific Emacs versions.

What about changes to allowed values for a variable?

`save-abbrevs' now accepts the value `silently', but that feature has
neither new variables nor functions to test for. And I don't want to
simply set `save-abbrevs' to `silently' because then, 21.1 asks me
every time about saving the abbreviations.

What would be the wisest way to check for it?

  (string-match "`silently'"
                (documentation-property 'save-abbrevs
                                        'variable-documentation))

seems hardly elegant...

--
                    /L/e/k/t/u

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Test for `save-abbrevs' improvement
  2006-02-16 14:39 Test for `save-abbrevs' improvement Juanma Barranquero
@ 2006-02-16 20:46 ` Kevin Rodgers
  2006-02-17  9:41   ` Juanma Barranquero
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Rodgers @ 2006-02-16 20:46 UTC (permalink / raw)


Juanma Barranquero wrote:
> Often it is said here that it is best to check for features, and not
> for specific Emacs versions.
> 
> What about changes to allowed values for a variable?
> 
> `save-abbrevs' now accepts the value `silently', but that feature has
> neither new variables nor functions to test for. And I don't want to
> simply set `save-abbrevs' to `silently' because then, 21.1 asks me
> every time about saving the abbreviations.
> 
> What would be the wisest way to check for it?
> 
>   (string-match "`silently'"
>                 (documentation-property 'save-abbrevs
>                                         'variable-documentation))
> 
> seems hardly elegant...

How about:

(member '(const silently) (custom-variable-type 'save-abbrevs))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Test for `save-abbrevs' improvement
  2006-02-16 20:46 ` Kevin Rodgers
@ 2006-02-17  9:41   ` Juanma Barranquero
  2006-02-17 10:27     ` Juanma Barranquero
  0 siblings, 1 reply; 6+ messages in thread
From: Juanma Barranquero @ 2006-02-17  9:41 UTC (permalink / raw)
  Cc: emacs-devel

On 2/16/06, Kevin Rodgers <ihs_4664@yahoo.com> wrote:

> How about:
>
> (member '(const silently) (custom-variable-type 'save-abbrevs))

That would require loading cus-edit.el (which I usually don't load, as
I don't use Customize), but I think I'll end using

  (rassoc '(silently) (get 'save-abbrevs 'custom-type))

Nice idea, thanks.

--
                    /L/e/k/t/u

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Test for `save-abbrevs' improvement
  2006-02-17  9:41   ` Juanma Barranquero
@ 2006-02-17 10:27     ` Juanma Barranquero
  2006-02-17 17:41       ` Kevin Rodgers
  0 siblings, 1 reply; 6+ messages in thread
From: Juanma Barranquero @ 2006-02-17 10:27 UTC (permalink / raw)
  Cc: emacs-devel

On 2/17/06, Juanma Barranquero <lekktu@gmail.com> wrote:

> I don't use Customize), but I think I'll end using
>
>   (rassoc '(silently) (get 'save-abbrevs 'custom-type))

  (and (listp (get 'save-abbrevs 'custom-type)) 'silently)

really, as the custom-type is 'boolean in 21.1. Oh well.

All in all, though the "test for functionality, not Emacs version"
mantra is a good suggestion, it breaks sometimes. In my .emacs I
advise `list-faces-display' to add to it the "C-u means ask for
regexp" feature of 22.X, but only if it is not there already. I didn't
find any way easier than:

(let ((code (symbol-function #'list-faces-display)))
  (when (and (byte-code-function-p code)
             (null (aref code 0)))
    ;; Stuff for pre-22.X versions
    ;; ...
    ))

Ugh.

--
                    /L/e/k/t/u

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Test for `save-abbrevs' improvement
  2006-02-17 10:27     ` Juanma Barranquero
@ 2006-02-17 17:41       ` Kevin Rodgers
  2006-02-17 20:31         ` Juanma Barranquero
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Rodgers @ 2006-02-17 17:41 UTC (permalink / raw)
  Cc: emacs-devel

Juanma Barranquero <lekktu@gmail.com> wrote:
> On 2/17/06, Juanma Barranquero <lekktu@gmail.com> wrote:
> 
> > I don't use Customize), but I think I'll end using
> >
> >   (rassoc '(silently) (get 'save-abbrevs 'custom-type))

No, you don't want to match (function silently), only (const silently),
and then only if it is actually a choice widget:

(let ((custom-type (get 'save-abbrevs 'custom-type)))
  (and (consp custom-type)
       (eq (car custom-type) 'choice)
       (member '(const silently) custom-type)))

>   (and (listp (get 'save-abbrevs 'custom-type)) 'silently)

That looks completely wrong to me.  What are you trying to express?

> really, as the custom-type is 'boolean in 21.1. Oh well.

What?  I thought your goal was to determine whether or not save-abbrevs
could be meaningfully set to silently.  If it has type boolean, nil is
the only distinguished value and silently is just another non-nil value.

> All in all, though the "test for functionality, not Emacs version"
> mantra is a good suggestion, it breaks sometimes. In my .emacs I
> advise `list-faces-display' to add to it the "C-u means ask for
> regexp" feature of 22.X, but only if it is not there already. I didn't
> find any way easier than:
> 
> (let ((code (symbol-function #'list-faces-display)))
>   (when (and (byte-code-function-p code)
>              (null (aref code 0)))
>     ;; Stuff for pre-22.X versions
>     ;; ...
>     ))
> 
> Ugh.

Isn't there something like:

(and (fboundp 'function-arity)
     (> (function-arity 'list-faces-display) 0))

-- 
Kevin


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Test for `save-abbrevs' improvement
  2006-02-17 17:41       ` Kevin Rodgers
@ 2006-02-17 20:31         ` Juanma Barranquero
  0 siblings, 0 replies; 6+ messages in thread
From: Juanma Barranquero @ 2006-02-17 20:31 UTC (permalink / raw)
  Cc: emacs-devel

On 2/17/06, Kevin Rodgers <ihs_4664@yahoo.com> wrote:

> No, you don't want to match (function silently), only (const silently),
> and then only if it is actually a choice widget:

Yes, of course. If I were writing code for a generally useful package,
I'd do all the tests. This is only for my .emacs, though, so quick &
not-too-dirty is fine.

> >   (and (listp (get 'save-abbrevs 'custom-type)) 'silently)
>
> That looks completely wrong to me.  What are you trying to express?

Is not wrong. It tries to express: "if the custom type is a list,
return 'silently; otherwise, return nil". Which it does.

> What?  I thought your goal was to determine whether or not save-abbrevs
> could be meaningfully set to silently.  If it has type boolean, nil is
> the only distinguished value and silently is just another non-nil value.

In Emacs 21.1, save-abbrevs was boolean. In 22.0.50, it is not; t and
nil mean the same thing that back in 21.1, but 'silently means (as
expected) "save quietly".

So, if you put

  (setq save-abbrevs 'silently)

on your .emacs and use it with 21.1, it will ask you *every time*
whether you do want to save the abbreviations (because, as you say, it
takes 'silently as non-nil, and hence true). I do not want to be asked
always, so I resort to setting it to 'silently on 22.0 and nil in
21.1. That's what my code does.

My original question could be formulated like this: "How can you know
when a variable accepts new values, other than checking the Emacs
version". Obviously there's no generic answer, so I was making do with
checking the docstring. Your answer, for which I am grateful, is: "if
the variable is a customization var, its custom-type *could* have the
relevant info". Good idea. :)

> Isn't there something like:
>
> (and (fboundp 'function-arity)
>      (> (function-arity 'list-faces-display) 0))

No, there isn't a `function-arity'. There's a `subr-arity' for
builtins, the trick I use for compiled functions, and asorted other
tricks for other kinds of functions or function-lookalikes (for
example, `ad-arglist' for advised functions, etc.).

--
                    /L/e/k/t/u

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-02-17 20:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-16 14:39 Test for `save-abbrevs' improvement Juanma Barranquero
2006-02-16 20:46 ` Kevin Rodgers
2006-02-17  9:41   ` Juanma Barranquero
2006-02-17 10:27     ` Juanma Barranquero
2006-02-17 17:41       ` Kevin Rodgers
2006-02-17 20:31         ` Juanma Barranquero

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