all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* implementing language keyword completion with ido/icicles
@ 2009-03-10  2:16 Xah Lee
  0 siblings, 0 replies; only message in thread
From: Xah Lee @ 2009-03-10  2:16 UTC (permalink / raw)
  To: help-gnu-emacs

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?

Thanks.

Here's my implementation of the traditional completion:

;; this is your lang's keywords
(setq xyz-kwdList '
      ("touch"
       "touch_start"
       "touch_end"
       "for"
       "foreach"
       "forall"
       ))

The following is the code that does the completion.

(defun xyz-complete-symbol ()
  "Perform completion on word under cursor."
  (interactive)
  (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)
             (ding))
            ((not (string= meat maxMatchResult))
             (delete-region (- cusorPoint (length meat)) cusorPoint)
             (insert maxMatchResult))
            (t (message "Making completion list...")
               (with-output-to-temp-buffer "*Completions*"
                 (display-completion-list
                  (all-completions meat xyz-kwdList)
                  meat))
               (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
  http://xahlee.org/emacs/elisp_keyword_completion.html

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?

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-03-10  2:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-10  2:16 implementing language keyword completion with ido/icicles Xah Lee

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.