Here is function I wrote to do completion using the minibuffer.  You
just have to copy all of the functions below into your
~/.xemacs/init.el or ~/.emacs file and bind the command jde-tmpl-completion
to a key.  I am not sure if this works on emacs, as I only use xemacs.

This is not exactly what I originally wanted, but it turns out to be just as
nice.  Right now it currently only looks through the
jde-gen-abbrev-templates list for completion values.  I have included
an example template to get anybody wanting to use it started.  If
anybody sees anywhere I can make improvements, fixes, don't hesitate
to point them out.  Enjoy!


(defun jde-tmpl-expand (abbrev-name)
  "JDE generates a symbol name prefixed with jde-gen- that can be called
as a function.  This function just uses this to call the function to generate
the expanded form."
  (interactive "sEnter JDE template abbreviation: ")
  (let ((tmpl-name (intern (concat "jde-gen-" abbrev-name))))
    (funcall tmpl-name)
    ))

(defun jde-tmpl-abbrev-alist ()
  "Build an alist of possible JDE abbrevs from the variable
jde-gen-abbrev-templates."
  (let ((tmpl-list jde-gen-abbrev-templates)
        (tmpl-item nil)
        (abbrev-alist nil)
        (abbrev-item nil)
        (index 1)
        )

    (progn
      (while (not (eq (car tmpl-list) nil))
        (setq tmpl-item (car tmpl-list))
        (setq abbrev-item (list (car tmpl-item) index))
        (setq abbrev-alist (cons abbrev-item abbrev-alist))
      
        ;; increment the list
        (setq tmpl-list (cdr tmpl-list))
        )
   
      ;; So we can return our list
      abbrev-alist
      )))

(defun jde-tmpl-completion ()
  "Function that provides completion ala the minibuffer complete stuff.
Just bind this function to a key, and when you use the key you will be
prompted to enter an abbreviated name of the templates you have defined.
Hitting TAB will give you the entire list which you will eventually narrow
down to a single result, at which time the abbrev will expand."
  (interactive)
  (let* ((possible-abbrevs (jde-tmpl-abbrev-alist))
         (abbrev-name (completing-read "Enter a JDE abbrev to expand: "
                                       possible-abbrevs nil t nil)))
    (message (format "Expanding abbrev: %s" abbrev-name))
    (jde-tmpl-expand abbrev-name)
    ))

;; Bind to a key C-3
(global-set-key [(control ?3)]          'jde-tmpl-completion)

;; Example template
(jde-gen-define-abbrev-template
 "addaction"
 '("addActionListener (new ActionListener()" '>'n "{" '>'n "public void 
actionPerformed (Action e)" '>'n "{" '>'n "}" '>'n"});" '>'n))

Reply via email to