unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Making hide-ifdef-use-define-alist more user friendly
@ 2005-02-21  9:03 Juan-Leon Lahoz Garcia
  2005-02-21 10:28 ` Kim F. Storm
  0 siblings, 1 reply; 6+ messages in thread
From: Juan-Leon Lahoz Garcia @ 2005-02-21  9:03 UTC (permalink / raw)



Hi,

`hide-ifdef-use-define-alist', when invoked interactivelly, does not
know how to complete to the symbols in alist `hide-ifdef-define-alist',
despite it is mandatory to enter one of them.

This is an incovenience because when you use several list is hard to
remember the exact names for them.

Since I can see in CVS this file is untouched for a lot of time, here
goes a patch so solve this (you might find a more elegant solution, I
suppose), just for the case of anyone here with time to review it and
maybe modify and/or apply.

--- hideif.el.ori	Mon Feb 21 09:33:58 2005
+++ hideif.el	Mon Feb 21 10:08:52 2005
@@ -1061,9 +1061,16 @@
 	(cons (cons name (hif-compress-define-list hide-ifdef-env))
 	      hide-ifdef-define-alist)))
 
-(defun hide-ifdef-use-define-alist (name)
+(defun hide-ifdef-use-define-alist (&optional name)
   "Set `hide-ifdef-env' to the define list specified by NAME."
-  (interactive "SUse define list: ")
+  (interactive)
+  (unless name
+    (setq name
+          (completing-read "Use define list: "
+                           (mapcar (lambda (arg)
+                                     (cons (symbol-name (car arg)) t))
+                                   hide-ifdef-define-alist) nil t)))
+  (if (stringp name) (setq name (intern name)))
   (let ((define-list (assoc name hide-ifdef-define-alist)))
     (if define-list
 	(setq hide-ifdef-env

--
Regards
juanleon

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

* Re: Making hide-ifdef-use-define-alist more user friendly
  2005-02-21  9:03 Making hide-ifdef-use-define-alist more user friendly Juan-Leon Lahoz Garcia
@ 2005-02-21 10:28 ` Kim F. Storm
  2005-02-21 11:13   ` Juan LEON Lahoz Garcia
  2005-02-22 18:11   ` Richard Stallman
  0 siblings, 2 replies; 6+ messages in thread
From: Kim F. Storm @ 2005-02-21 10:28 UTC (permalink / raw)
  Cc: emacs-devel

Juan-Leon Lahoz Garcia <juanleon1@gmail.com> writes:

> Hi,
>
> `hide-ifdef-use-define-alist', when invoked interactivelly, does not
> know how to complete to the symbols in alist `hide-ifdef-define-alist',
> despite it is mandatory to enter one of them.

Good point.

>
> --- hideif.el.ori	Mon Feb 21 09:33:58 2005
> +++ hideif.el	Mon Feb 21 10:08:52 2005
> @@ -1061,9 +1061,16 @@
>  	(cons (cons name (hif-compress-define-list hide-ifdef-env))
>  	      hide-ifdef-define-alist)))
>  
> -(defun hide-ifdef-use-define-alist (name)
> +(defun hide-ifdef-use-define-alist (&optional name)
>    "Set `hide-ifdef-env' to the define list specified by NAME."
> -  (interactive "SUse define list: ")
> +  (interactive)
> +  (unless name
> +    (setq name
> +          (completing-read "Use define list: "
> +                           (mapcar (lambda (arg)
> +                                     (cons (symbol-name (car arg)) t))
> +                                   hide-ifdef-define-alist) nil t)))
> +  (if (stringp name) (setq name (intern name)))
>    (let ((define-list (assoc name hide-ifdef-define-alist)))
>      (if define-list
>  	(setq hide-ifdef-env

This looked more complex than needed at first sight, so I tried this:

*** hideif.el	01 Sep 2003 17:45:35 +0200	1.48
--- hideif.el	21 Feb 2005 11:00:21 +0100	
***************
*** 958,964 ****
  
  (defun hide-ifdef-use-define-alist (name)
    "Set `hide-ifdef-env' to the define list specified by NAME."
!   (interactive "SUse define list: ")
    (let ((define-list (assoc name hide-ifdef-define-alist)))
      (if define-list
  	(setq hide-ifdef-env
--- 958,967 ----
  
  (defun hide-ifdef-use-define-alist (name)
    "Set `hide-ifdef-env' to the define list specified by NAME."
!   (interactive
!    (list (completing-read "Use define list: "
! 			  hide-ifdef-define-alist nil t)))
!   (if (stringp name) (setq name (intern name)))
    (let ((define-list (assoc name hide-ifdef-define-alist)))
      (if define-list
  	(setq hide-ifdef-env

But as you had already discovered, completing-read requires that
the alist keys are strings, not symbols.

Looking at try-completion and all-completions, there is a strange
inconsistency between alists, vectors, and hash tables:

In alists and hash tables, the key must be a string, while in vectors,
the key must be a symbol...  

The following patch changes this to accept both strings and symbols as
keys in all cases.  

With this, my simpler patch to hide-ifdef-use-define-alist works.

Any objections to installing this ?


*** minibuf.c	12 Dec 2004 23:25:36 +0100	1.278
--- minibuf.c	21 Feb 2005 11:15:49 +0100	
***************
*** 1257,1263 ****
  	  if (!EQ (bucket, zero))
  	    {
  	      elt = bucket;
! 	      eltstring = Fsymbol_name (elt);
  	      if (XSYMBOL (bucket)->next)
  		XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
  	      else
--- 1257,1263 ----
  	  if (!EQ (bucket, zero))
  	    {
  	      elt = bucket;
! 	      eltstring = elt;
  	      if (XSYMBOL (bucket)->next)
  		XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
  	      else
***************
*** 1284,1289 ****
--- 1284,1292 ----
  
        /* Is this element a possible completion? */
  
+       if (SYMBOLP (eltstring))
+ 	eltstring = Fsymbol_name (eltstring);
+ 
        if (STRINGP (eltstring)
  	  && SCHARS (string) <= SCHARS (eltstring)
  	  && (tem = Fcompare_strings (eltstring, zero,
***************
*** 1512,1518 ****
  	  if (!EQ (bucket, zero))
  	    {
  	      elt = bucket;
! 	      eltstring = Fsymbol_name (elt);
  	      if (XSYMBOL (bucket)->next)
  		XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
  	      else
--- 1515,1521 ----
  	  if (!EQ (bucket, zero))
  	    {
  	      elt = bucket;
! 	      eltstring = elt;
  	      if (XSYMBOL (bucket)->next)
  		XSETSYMBOL (bucket, XSYMBOL (bucket)->next);
  	      else
***************
*** 1539,1544 ****
--- 1542,1550 ----
  
        /* Is this element a possible completion? */
  
+       if (SYMBOLP (eltstring))
+ 	eltstring = Fsymbol_name (eltstring);
+ 
        if (STRINGP (eltstring)
  	  && SCHARS (string) <= SCHARS (eltstring)
  	  /* If HIDE_SPACES, reject alternatives that start with space

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: Making hide-ifdef-use-define-alist more user friendly
  2005-02-21 10:28 ` Kim F. Storm
@ 2005-02-21 11:13   ` Juan LEON Lahoz Garcia
  2005-02-22 18:12     ` Richard Stallman
  2005-02-22 18:11   ` Richard Stallman
  1 sibling, 1 reply; 6+ messages in thread
From: Juan LEON Lahoz Garcia @ 2005-02-21 11:13 UTC (permalink / raw)
  Cc: emacs-devel

On Mon, 21 Feb 2005 11:28:08 +0100, Kim F. Storm <storm@cua.dk> wrote:
> Juan-Leon Lahoz Garcia <juanleon1@gmail.com> writes:
> 
> Looking at try-completion and all-completions, there is a strange
> inconsistency between alists, vectors, and hash tables:
> 
> In alists and hash tables, the key must be a string, while in vectors,
> the key must be a symbol...

Thanks for looking into this.

I had found another strange behaviour in completing-read that I do not
know if is a bug or my ignorance.

Following code:

(completing-read "Use define list: " (vconcat (mapcar 'car
hide-ifdef-define-alist)))

Allows me to complete more things that those found in:

(vconcat (mapcar 'car hide-ifdef-define-alist))

This happens for me in emacs 21.2, and completing-read offers the 8 symbols I
have in the alist plus about 60 more like format-annotate-value,
fortune-add-fortune, hs-flag-region, invert-face,
islamic-diary-entry-symbol, iso-2022-jp-unix, iso-8859-7-dos. Maybe in
22.x this is not happening...

Regards
--
juanleon

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

* Re: Making hide-ifdef-use-define-alist more user friendly
  2005-02-21 10:28 ` Kim F. Storm
  2005-02-21 11:13   ` Juan LEON Lahoz Garcia
@ 2005-02-22 18:11   ` Richard Stallman
  2005-02-22 20:54     ` Kim F. Storm
  1 sibling, 1 reply; 6+ messages in thread
From: Richard Stallman @ 2005-02-22 18:11 UTC (permalink / raw)
  Cc: juanleon1, emacs-devel

    In alists and hash tables, the key must be a string, while in vectors,
    the key must be a symbol...  

    The following patch changes this to accept both strings and symbols as
    keys in all cases.  

It sounds good to me.  Thanks for thinking of it.

Could you also mention this in NEWS, and update the Lisp manual?

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

* Re: Making hide-ifdef-use-define-alist more user friendly
  2005-02-21 11:13   ` Juan LEON Lahoz Garcia
@ 2005-02-22 18:12     ` Richard Stallman
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2005-02-22 18:12 UTC (permalink / raw)
  Cc: emacs-devel, storm

    (completing-read "Use define list: " (vconcat (mapcar 'car
    hide-ifdef-define-alist)))

    Allows me to complete more things that those found in:

    (vconcat (mapcar 'car hide-ifdef-define-alist))

The reason for that is that a vector is treated as an obarray.
Obarrays are a special mechanism and they use hidden data structures.
A vector of symbols is not a legitimate argument.

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

* Re: Making hide-ifdef-use-define-alist more user friendly
  2005-02-22 18:11   ` Richard Stallman
@ 2005-02-22 20:54     ` Kim F. Storm
  0 siblings, 0 replies; 6+ messages in thread
From: Kim F. Storm @ 2005-02-22 20:54 UTC (permalink / raw)
  Cc: juanleon1, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     In alists and hash tables, the key must be a string, while in vectors,
>     the key must be a symbol...  
>
>     The following patch changes this to accept both strings and symbols as
>     keys in all cases.  
>
> It sounds good to me.  Thanks for thinking of it.
>
> Could you also mention this in NEWS, and update the Lisp manual?

Done.

I also installed the change to hide-ifdef-use-define-alist.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

end of thread, other threads:[~2005-02-22 20:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-21  9:03 Making hide-ifdef-use-define-alist more user friendly Juan-Leon Lahoz Garcia
2005-02-21 10:28 ` Kim F. Storm
2005-02-21 11:13   ` Juan LEON Lahoz Garcia
2005-02-22 18:12     ` Richard Stallman
2005-02-22 18:11   ` Richard Stallman
2005-02-22 20:54     ` Kim F. Storm

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