* completing-read() on list of vectors
@ 2008-09-12 10:30 Nordlöw
2008-09-12 11:19 ` Nordlöw
2008-09-12 17:58 ` Nikolaj Schumacher
0 siblings, 2 replies; 3+ messages in thread
From: Nordlöw @ 2008-09-12 10:30 UTC (permalink / raw
To: help-gnu-emacs
If I have the following association list (alist):
(defvar c++-stl-algorithms
'(
("adjacent_difference" "<numeric>" "Compute the differences
between adjacent elements in a range")
("adjacent_find" "<algorithm>" "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:
(defvar c++-stl-algorithms
'(
["adjacent_difference" "<numeric>" "Compute the differences
between adjacent elements in a range"]
["adjacent_find" "<algorithm>" "Finds two items that are adjacent
to eachother"]
))
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).
Why doesn't completing-read() already work on list of vectors where
first vector element is a string aswell?
Thanks in advance,
Nordlöw
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: completing-read() on list of vectors
2008-09-12 10:30 completing-read() on list of vectors Nordlöw
@ 2008-09-12 11:19 ` Nordlöw
2008-09-12 17:58 ` Nikolaj Schumacher
1 sibling, 0 replies; 3+ messages in thread
From: Nordlöw @ 2008-09-12 11:19 UTC (permalink / raw
To: help-gnu-emacs
On 12 Sep, 12:30, Nordlöw <per.nord...@gmail.com> wrote:
> If I have the following association list (alist):
>
> (defvar c++-stl-algorithms
> '(
> ("adjacent_difference" "<numeric>" "Compute the differences
> between adjacent elements in a range")
> ("adjacent_find" "<algorithm>" "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:
>
> (defvar c++-stl-algorithms
> '(
> ["adjacent_difference" "<numeric>" "Compute the differences
> between adjacent elements in a range"]
> ["adjacent_find" "<algorithm>" "Finds two items that are adjacent
> to eachother"]
> ))
>
> 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).
>
> Why doesn't completing-read() already work on list of vectors where
> first vector element is a string aswell?
>
> Thanks in advance,
> Nordlöw
It believe it boils down to the search for a function like assoc()
that takes a list of vectors as arguments.
/Nordlöw
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: completing-read() on list of vectors
2008-09-12 10:30 completing-read() on list of vectors Nordlöw
2008-09-12 11:19 ` Nordlöw
@ 2008-09-12 17:58 ` Nikolaj Schumacher
1 sibling, 0 replies; 3+ messages in thread
From: Nikolaj Schumacher @ 2008-09-12 17:58 UTC (permalink / raw
To: Nordlöw; +Cc: help-gnu-emacs
Nordlöw <per.nordlow@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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-12 17:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-12 10:30 completing-read() on list of vectors Nordlöw
2008-09-12 11:19 ` Nordlöw
2008-09-12 17:58 ` Nikolaj Schumacher
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.