completing-read() on list of vectors
  Home FAQ Contact Sign in
gnu.emacs.help only
 
Advanced search
POPULAR GROUPS

more...

gnu.emacs.help Profile…
 Up
completing-read() on list of vectors         


Author: Nordlöw
Date: Sep 12, 2008 03:30

If I have the following association list (alist):

(defvar c++-stl-algorithms
'(
("adjacent_difference" "" "Compute the differences
between adjacent elements in a range")
("adjacent_find" "" "Finds two items that are adjacent
to eachother")
))

how can I modify the use of completing-read() to make the function

(defun read-c++-stl-algorithm ()
(let* ((sym (thing-at-point 'symbol))
(cont (completing-read (concat "C++ STL Algorithm (default "
sym "): ")
c++-stl-algorithms nil t nil nil
sym)))
(list cont)))

to instead work on this list of vectors:
Show full article (1.23Kb)
2 Comments
Re: completing-read() on list of vectors         


Author: Nordlöw
Date: Sep 12, 2008 04:19

On 12 Sep, 12:30, Nordlöw gmail.com> wrote:
> If I have the following association list (alist):
>
> (defvar c++-stl-algorithms
>   '(
>     ("adjacent_difference" "" "Compute the differences
> between adjacent elements in a range")
>     ("adjacent_find" "" "Finds two items that are adjacent
> to eachother")
>   ))
>
> how can I modify the use of completing-read() to make the function
>
> (defun read-c++-stl-algorithm ()
>   (let* ((sym (thing-at-point 'symbol))
>          (cont (completing-read (concat "C++ STL Algorithm (default "
> sym "): ")
>                                 c++-stl-algorithms nil t nil nil
> sym)))
>     (list cont))) ...
Show full article (1.51Kb)
no comments
Re: completing-read() on list of vectors         


Author: Nikolaj Schumacher
Date: Sep 12, 2008 10:58

Nordlöw gmail.com> wrote:
> I guess I need to give it an explicit completion function (as second
> argument) to achieve lookups of list of vectors where for example
> "accumulate" is used as key and the return value is the whole list
> element (vector).

The easiest way would be just to duplicate the first element in a cons.

(a . [a b c d])

Or use a hash map.

Certainly, you could also write your own completion functions, but it
will be significantly slower, because it's written in lisp. (If speed
that's of any concern...)
> Why doesn't completing-read() already work on list of vectors where
> first vector element is a string aswell?

Unfortunately, there are few functions capable of working with vectors.
Consequently, They are rarely used. (Consequently, there are few
functions capable of working with them.)

regards,
Nikolaj Schumacher
no comments