* COMPLETING-READ Problem
@ 2008-03-09 12:51 Volkan YAZICI
2008-03-09 16:03 ` Thierry Volpiatto
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Volkan YAZICI @ 2008-03-09 12:51 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
While trying to implement a family of SQL identifier search functions,
I want to offer tab completion to previously searched SQL identifiers
-- besides builtin history functionality binded to M-p. For this
purpose, I try to use COMPLETING-READ. Here's the related code
snippet:
(defvar searched-sql-items nil
"Association list of previously searched SQL items.")
(defun make-local-searched-sql-items ()
"Creates per-buffer SEARCHED-SQL-ITEMS association list."
(make-local-variable 'searched-sql-items))
(add-hook 'sql-mode-hook 'make-local-searched-sql-items)
(defun search-sql-table (table-name)
"Search for specified TABLE-NAME in the current buffer."
(interactive
(let ((previously-searched-tables (assoc 'table searched-sql-
items)))
(list
(completing-read
(if previously-searched-tables
(format "Table name (default: %s): "
(first previously-searched-tables))
"Table name: ")
previously-searched-tables)))
;; Insert specified TABLE-NAME to SEARCHED-SQL-ITEMS.
(let ((previously-searched-tables (assoc 'table searched-sql-
items)))
(setf (assoc 'table searched-sql-items)
;; Move TABLE-NAME to top.
(cons table-name (remove table-name previously-searched-
tables))))
;; Search table.
(search-forward (format "CREATE TABLE %s" table-name))))
But for some reason, function doesn't work. (Does nothing during
execution.) I tried to place a (warn "TABLE-NAME: %s" table-name) just
after (interactive ...) block, but there doesn't appear anything in
the *Messages* buffer. Any ideas?
Regards.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: COMPLETING-READ Problem
2008-03-09 12:51 COMPLETING-READ Problem Volkan YAZICI
@ 2008-03-09 16:03 ` Thierry Volpiatto
2008-03-09 16:15 ` Thierry Volpiatto
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Thierry Volpiatto @ 2008-03-09 16:03 UTC (permalink / raw)
To: Volkan YAZICI; +Cc: help-gnu-emacs
Volkan YAZICI <volkan.yazici@gmail.com> writes:
> Hi,
>
> While trying to implement a family of SQL identifier search functions,
> I want to offer tab completion to previously searched SQL identifiers
> -- besides builtin history functionality binded to M-p. For this
> purpose, I try to use COMPLETING-READ. Here's the related code
> snippet:
>
> (defvar searched-sql-items nil
> "Association list of previously searched SQL items.")
>
> (defun make-local-searched-sql-items ()
> "Creates per-buffer SEARCHED-SQL-ITEMS association list."
> (make-local-variable 'searched-sql-items))
>
> (add-hook 'sql-mode-hook 'make-local-searched-sql-items)
>
> (defun search-sql-table (table-name)
> "Search for specified TABLE-NAME in the current buffer."
> (interactive
> (let ((previously-searched-tables (assoc 'table searched-sql-
> items)))
> (list
> (completing-read
> (if previously-searched-tables
> (format "Table name (default: %s): "
> (first previously-searched-tables))
> "Table name: ")
> previously-searched-tables)))
> ;; Insert specified TABLE-NAME to SEARCHED-SQL-ITEMS.
> (let ((previously-searched-tables (assoc 'table searched-sql-
> items)))
> (setf (assoc 'table searched-sql-items)
> ;; Move TABLE-NAME to top.
> (cons table-name (remove table-name previously-searched-
> tables))))
> ;; Search table.
> (search-forward (format "CREATE TABLE %s" table-name))))
>
> But for some reason, function doesn't work. (Does nothing during
> execution.) I tried to place a (warn "TABLE-NAME: %s" table-name) just
> after (interactive ...) block, but there doesn't appear anything in
> the *Messages* buffer. Any ideas?
>
>
> Regards.
>
I think you have to put your completing-read outside of the let body.
--
A + Thierry
Pub key: http://pgp.mit.edu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: COMPLETING-READ Problem
2008-03-09 12:51 COMPLETING-READ Problem Volkan YAZICI
2008-03-09 16:03 ` Thierry Volpiatto
@ 2008-03-09 16:15 ` Thierry Volpiatto
2008-03-09 19:05 ` Drew Adams
[not found] ` <mailman.8610.1205089639.18990.help-gnu-emacs@gnu.org>
3 siblings, 0 replies; 5+ messages in thread
From: Thierry Volpiatto @ 2008-03-09 16:15 UTC (permalink / raw)
To: Volkan YAZICI; +Cc: help-gnu-emacs
Volkan YAZICI <volkan.yazici@gmail.com> writes:
> Hi,
>
> While trying to implement a family of SQL identifier search functions,
> I want to offer tab completion to previously searched SQL identifiers
> -- besides builtin history functionality binded to M-p. For this
> purpose, I try to use COMPLETING-READ. Here's the related code
> snippet:
>
> (defvar searched-sql-items nil
> "Association list of previously searched SQL items.")
>
> (defun make-local-searched-sql-items ()
> "Creates per-buffer SEARCHED-SQL-ITEMS association list."
> (make-local-variable 'searched-sql-items))
>
> (add-hook 'sql-mode-hook 'make-local-searched-sql-items)
>
> (defun search-sql-table (table-name)
> "Search for specified TABLE-NAME in the current buffer."
> (interactive
> (let ((previously-searched-tables (assoc 'table searched-sql-
> items)))
> (list
> (completing-read
> (if previously-searched-tables
> (format "Table name (default: %s): "
> (first previously-searched-tables))
> "Table name: ")
> previously-searched-tables)))
> ;; Insert specified TABLE-NAME to SEARCHED-SQL-ITEMS.
> (let ((previously-searched-tables (assoc 'table searched-sql-
> items)))
> (setf (assoc 'table searched-sql-items)
> ;; Move TABLE-NAME to top.
> (cons table-name (remove table-name previously-searched-
> tables))))
> ;; Search table.
> (search-forward (format "CREATE TABLE %s" table-name))))
>
> But for some reason, function doesn't work. (Does nothing during
> execution.) I tried to place a (warn "TABLE-NAME: %s" table-name) just
> after (interactive ...) block, but there doesn't appear anything in
> the *Messages* buffer. Any ideas?
>
>
> Regards.
>
Or use let* to be able to reuse previously-searched-tables in completing-read.
--
A + Thierry
Pub key: http://pgp.mit.edu
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: COMPLETING-READ Problem
2008-03-09 12:51 COMPLETING-READ Problem Volkan YAZICI
2008-03-09 16:03 ` Thierry Volpiatto
2008-03-09 16:15 ` Thierry Volpiatto
@ 2008-03-09 19:05 ` Drew Adams
[not found] ` <mailman.8610.1205089639.18990.help-gnu-emacs@gnu.org>
3 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2008-03-09 19:05 UTC (permalink / raw)
To: 'Volkan YAZICI', help-gnu-emacs
> While trying to implement a family of SQL identifier search functions,
> I want to offer tab completion to previously searched SQL identifiers
> -- besides builtin history functionality binded to M-p. For this
> purpose, I try to use COMPLETING-READ. Here's the related code
> snippet:
>
> (defvar searched-sql-items nil
> "Association list of previously searched SQL items.")
>
> (defun make-local-searched-sql-items ()
> "Creates per-buffer SEARCHED-SQL-ITEMS association list."
> (make-local-variable 'searched-sql-items))
>
> (add-hook 'sql-mode-hook 'make-local-searched-sql-items)
>
> (defun search-sql-table (table-name)
> "Search for specified TABLE-NAME in the current buffer."
> (interactive
> (let ((previously-searched-tables (assoc 'table searched-sql-
> items)))
> (list
> (completing-read
> (if previously-searched-tables
> (format "Table name (default: %s): "
> (first previously-searched-tables))
> "Table name: ")
> previously-searched-tables)))
> ;; Insert specified TABLE-NAME to SEARCHED-SQL-ITEMS.
> (let ((previously-searched-tables (assoc 'table searched-sql-
> items)))
> (setf (assoc 'table searched-sql-items)
> ;; Move TABLE-NAME to top.
> (cons table-name (remove table-name previously-searched-
> tables))))
> ;; Search table.
> (search-forward (format "CREATE TABLE %s" table-name))))
>
> But for some reason, function doesn't work. (Does nothing during
> execution.) I tried to place a (warn "TABLE-NAME: %s" table-name) just
> after (interactive ...) block, but there doesn't appear anything in
> the *Messages* buffer. Any ideas?
You pass `completing-read' an empty TABLE argument: you never fill
`previously-searched-tables', so it is nil.
And you never add any alist entry (table . <something) to
`searched-sql-items'. See
http://www.groupsrv.com/computers/about240758.html.
You need to think about or debug your code piece by piece.
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <mailman.8610.1205089639.18990.help-gnu-emacs@gnu.org>]
* Re: COMPLETING-READ Problem
[not found] ` <mailman.8610.1205089639.18990.help-gnu-emacs@gnu.org>
@ 2008-03-10 7:34 ` Volkan YAZICI
0 siblings, 0 replies; 5+ messages in thread
From: Volkan YAZICI @ 2008-03-10 7:34 UTC (permalink / raw)
To: help-gnu-emacs
On 9 Mart, 21:05, "Drew Adams" <drew.ad...@oracle.com> wrote:
> You pass `completing-read' an empty TABLE argument: you never fill
> `previously-searched-tables', so it is nil.
>
> And you never add any alist entry (table . <something) to
> `searched-sql-items'. Seehttp://www.groupsrv.com/computers/about240758.html.
(I totally missed the scope of LET block inside INTERACTIVE call.)
Thanks for your (setf (assoc ...) ...) pointer. It appears to be I
completely forgot how to use ASSOC. Anyway, after facing with some
other problems, I decided to continue with hash tables. Here is the
latest code:
(defun search-sql-table (table-name)
"Search for specified TABLE-NAME in the current buffer."
(interactive
(let ((previously-searched-tables
(and (hash-table-p searched-sql-items)
(gethash 'table searched-sql-items))))
(list
(completing-read
(if previously-searched-tables
(format "Table name (default: %s): "
(first previously-searched-tables))
"Table name: ")
previously-searched-tables))))
;; Insert specified TABLE-NAME to SEARCHED-SQL-ITEMS.
(unless (hash-table-p searched-sql-items)
(setq searched-sql-items (make-hash-table)))
(setf (gethash 'table searched-sql-items)
;; Move TABLE-NAME to top.
(cons table-name (remove table-name (gethash 'table searched-
sql-items))))
;; Search table.
(search-forward (format "CREATE TABLE %s" table-name)))
It seems to be working for now. If you see any other problems, I'd be
appreciated if you can report them. Thanks so much for your kindly
replies.
Regards.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-03-10 7:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-09 12:51 COMPLETING-READ Problem Volkan YAZICI
2008-03-09 16:03 ` Thierry Volpiatto
2008-03-09 16:15 ` Thierry Volpiatto
2008-03-09 19:05 ` Drew Adams
[not found] ` <mailman.8610.1205089639.18990.help-gnu-emacs@gnu.org>
2008-03-10 7:34 ` Volkan YAZICI
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.