[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

implementing language keyword completion with ido/icicles

From: Xah Lee
Subject: implementing language keyword completion with ido/icicles
Date: Mon, 9 Mar 2009 19:16:07 -0700 (PDT)
User-agent: G2/1.0

recently i implemented a keyword completion feature in xlsl-mode for
lindent scripting lang. (see code below)

however, the conventional emacs completion feature provide the
completion of a given starting string.

I know that ido-mode and icicles provide completion, where the given
string needs not to be the starting string but can be any substring or
even regex.

My question is, can anyone show me a simple example?


Here's my implementation of the traditional completion:

;; this is your lang's keywords
(setq xyz-kwdList '

The following is the code that does the completion.

(defun xyz-complete-symbol ()
  "Perform completion on word under cursor."
  (let* (
         (cusorPoint (point))
         (meat (thing-at-point 'symbol))
         (maxMatchResult (try-completion meat xyz-kwdList))
    (when meat
      (cond ((eq maxMatchResult t))
            ((null maxMatchResult)
             (message "Can't find completion for “%s”" meat)
            ((not (string= meat maxMatchResult))
             (delete-region (- cusorPoint (length meat)) cusorPoint)
             (insert maxMatchResult))
            (t (message "Making completion list...")
               (with-output-to-temp-buffer "*Completions*"
                  (all-completions meat xyz-kwdList)
               (message "Making completion list...%s" "done"))))

it actually took me quite some days to finally figure this out (on and
off in the past months).

• How To Implement Keyword Completion in Emacs

i've been wondering, shouldn't emacs provide something more high
level, so that something like:

(keyword-completion-feature inputString keywordList)

and the function takes care of all the display, buffer, etc by itself?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]