unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Setting numecir values according to symbol
@ 2022-10-30  4:31 Heime
  2022-10-30 12:54 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 5+ messages in thread
From: Heime @ 2022-10-30  4:31 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

Am currently implementing a system that sets the minibuffer completion framework for emacs.
I set the numeric value of "mbcomplt" according the value of a variable "armg" which is a symbol.

Perhaps I can implement the setting of "mbcomplt" in a much more straightforward manner than
using the following implementation.

  (defvar mbcomplt 0)

  (cond
   ((eq armg 'auto) (setq mbcomplt 0)
   ((eq armg 'icomplt-horz) (setq mbcomplt 1)
   ((eq armg 'icomplt-vert) (setq mbcomplt 2)
   ((eq armg 'ivy) (setq mbcomplt 3)
   ((eq armg 'vertico) (setq mbcomplt 4)
   ((eq armg 'helm) (setq mbcomplt 5)))





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

* Re: Setting numecir values according to symbol
  2022-10-30  4:31 Setting numecir values according to symbol Heime
@ 2022-10-30 12:54 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-10-30 13:01   ` Emanuel Berg
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-10-30 12:54 UTC (permalink / raw)
  To: help-gnu-emacs

Heime [2022-10-30 04:31:34] wrote:

> Am currently implementing a system that sets the minibuffer completion
> framework for emacs.  I set the numeric value of "mbcomplt" according
> the value of a variable "armg" which is a symbol.
>
> Perhaps I can implement the setting of "mbcomplt" in a much more
> straightforward manner than using the following implementation.
>
>   (defvar mbcomplt 0)
>
>   (cond
>    ((eq armg 'auto) (setq mbcomplt 0)
>    ((eq armg 'icomplt-horz) (setq mbcomplt 1)
>    ((eq armg 'icomplt-vert) (setq mbcomplt 2)
>    ((eq armg 'ivy) (setq mbcomplt 3)
>    ((eq armg 'vertico) (setq mbcomplt 4)
>    ((eq armg 'helm) (setq mbcomplt 5)))

Without giving more info about how you're using those two vars, it's hard
to tell, but my crystal ball tells that you're probably better off
getting rid of `mbcomplt` and using `armg` instead.


        Stefan




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

* Re: Setting numecir values according to symbol
  2022-10-30 12:54 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-10-30 13:01   ` Emanuel Berg
  2022-10-30 22:12     ` Heime
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2022-10-30 13:01 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

>>   (defvar mbcomplt 0)
>>
>>   (cond
>>    ((eq armg 'auto) (setq mbcomplt 0)
>>    ((eq armg 'icomplt-horz) (setq mbcomplt 1)
>>    ((eq armg 'icomplt-vert) (setq mbcomplt 2)
>>    ((eq armg 'ivy) (setq mbcomplt 3)
>>    ((eq armg 'vertico) (setq mbcomplt 4)
>>    ((eq armg 'helm) (setq mbcomplt 5)))
>
> Without giving more info about how you're using those two
> vars, it's hard to tell, but my crystal ball tells that
> you're probably better off getting rid of `mbcomplt` and
> using `armg` instead.

Because one variable shouldn't be functionally dependent on
another ...

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Setting numecir values according to symbol
  2022-10-30 13:01   ` Emanuel Berg
@ 2022-10-30 22:12     ` Heime
  2022-10-31 11:25       ` Emanuel Berg
  0 siblings, 1 reply; 5+ messages in thread
From: Heime @ 2022-10-30 22:12 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


------- Original Message -------
On Sunday, October 30th, 2022 at 1:01 PM, Emanuel Berg <incal@dataswamp.org> wrote:


> Stefan Monnier via Users list for the GNU Emacs text editor wrote:
> 
> > > (defvar mbcomplt 0)
> > > 
> > > (cond
> > > ((eq armg 'auto) (setq mbcomplt 0)
> > > ((eq armg 'icomplt-horz) (setq mbcomplt 1)
> > > ((eq armg 'icomplt-vert) (setq mbcomplt 2)
> > > ((eq armg 'ivy) (setq mbcomplt 3)
> > > ((eq armg 'vertico) (setq mbcomplt 4)
> > > ((eq armg 'helm) (setq mbcomplt 5)))

I did simplify this with the following "cl-case".  Am interested in seeing
how a can implement the equivalent using "pcase".

(setq mbcomplt
  (cl-case armg
    ('auto 0)
    ('icomplt-horz 1)
    ('icomplt-vert 2)
    ('ivy 3)
    ('vertico 4)
    ('helm 5)))

Would this be all, as below?

(setq mbcomplt
  (pcase armg
    ('auto 0)
    ('icomplt-horz 1)
    ('icomplt-vert 2)
    ('ivy 3)
    ('vertico 4)
    ('helm 5)))






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

* Re: Setting numecir values according to symbol
  2022-10-30 22:12     ` Heime
@ 2022-10-31 11:25       ` Emanuel Berg
  0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2022-10-31 11:25 UTC (permalink / raw)
  To: help-gnu-emacs

Heime wrote:

> I did simplify this with the following "cl-case".
> Am interested in seeing how a can implement the equivalent
> using "pcase".
>
> (setq mbcomplt
>   (cl-case armg
>     ('auto 0)
>     ('icomplt-horz 1)
>     ('icomplt-vert 2)
>     ('ivy 3)
>     ('vertico 4)
>     ('helm 5)))

Again, that's not a good idea to do, to just set one variable
to something depending on some other, it's error-prone and it
doesn't bring anything, really, the information is already
there and does not increase from that (what you just did).

Also, what you have done looks like an enumeration from C,
actually I don't know if that is any better since its
a variation of what I just said one shouldn't do, but if it's
just a matter of doing that you can do

(setq mbcomplt-armg
  (list 'auto 'icomplt-horz 'icomplt-vert 'ivy 'vertico 'helm) )

(cl-position 'auto         mbcomplt-armg) ; 0
(cl-position 'icomplt-horz mbcomplt-armg) ; 1
                                          ; etc

Well, it's a little bit better since the information is
"built-in", but the so-called position should still not be
used unless the list has some order one has decided to uphold
(and has some meaning).

> Would this be all, as below?
>
> (setq mbcomplt
>   (pcase armg
>     ('auto 0)
>     ('icomplt-horz 1)
>     ('icomplt-vert 2)
>     ('ivy 3)
>     ('vertico 4)
>     ('helm 5)))

Yes, but I don't see any reason to use `pcase' here, even less
than `cl-case' ...

-- 
underground experts united
https://dataswamp.org/~incal




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

end of thread, other threads:[~2022-10-31 11:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-30  4:31 Setting numecir values according to symbol Heime
2022-10-30 12:54 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-30 13:01   ` Emanuel Berg
2022-10-30 22:12     ` Heime
2022-10-31 11:25       ` Emanuel Berg

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