;;; vj-sql-complete-ui.el --- Use completion-ui with sqlplus ;; Copyright (C) 2008 Vagn Johansen ;; Author: Vagn Johansen ;; Keywords: completion, ui, user interface, sql, sqlplus ;; URL: http://www.ozymandias.dk/emacs/emacs.html ;; This file is NOT part of Emacs. ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License ;; as published by the Free Software Foundation; either version 2 ;; of the License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, write to the Free Software ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, ;; MA 02110-1301, USA. ;;; Commentary: ;; ;; Installation: ;; ;; (require 'vj-complete-completion-ui) ;; ;; Enable the completion-ui interface in he sqlplus buffer with ;; ;; M-x auto-completion-mode ;; ;; NOTE! When writing SQL then columns must be written in uppercase and ;; tables and views in lowercase. ;;; Code: (require 'completion-ui) (require 'sqlplus) (defvar vj-sqlplus-names nil) (defadvice sqlplus-my-handler (around vj-sqlplus-my-handler-advice (connect-string table-data)) (setq vj-sqlplus-names '("select" "from" "where" "TO_DATE" "desc" "insert" "update" "column")) (let ((column-infos (car table-data)) (rows (cadr table-data)) (msg (caddr table-data))) (dolist (name-and-type rows) (if (equal (cadr name-and-type) "TABLE") (add-to-list 'vj-sqlplus-names (downcase (car name-and-type)))) (if (equal (cadr name-and-type) "VIEW") (add-to-list 'vj-sqlplus-names (downcase (car name-and-type)))) (if (equal (cadr name-and-type) "COLUMN") (add-to-list 'vj-sqlplus-names (upcase (car name-and-type)))))) (message "vj-sqlplus-my-handler-advice") ad-do-it) (ad-activate 'sqlplus-my-handler) (defun vj-sqlplus-completion-function (prefix max) "" (let (result (case-fold-search nil)) (dolist (name vj-sqlplus-names) (if (and (< (length result) max) (string-match (concat "^" (regexp-quote prefix)) name)) (add-to-list 'result (substring name (length prefix))))) result)) (add-hook 'sqlplus-mode-hook (lambda () (setq completion-function 'vj-sqlplus-completion-function))) (provide 'vj-sqlplus-complete)