unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Cc: emacs-devel@gnu.org
Subject: Re: Making hide-ifdef-use-define-alist more user friendly
Date: Mon, 21 Feb 2005 11:28:08 +0100	[thread overview]
Message-ID: <m3650m437r.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <200502210903.j1L933jt024808@il06exr01.mot.com> (Juan-Leon Lahoz Garcia's message of "Mon, 21 Feb 2005 03:03:03 -0600 (CST)")

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

  reply	other threads:[~2005-02-21 10:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=m3650m437r.fsf@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    --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.
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).