From: Xah Lee <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: implementing language keyword completion with ido/icicles
Date: Mon, 9 Mar 2009 19:16:07 -0700 (PDT) [thread overview]
Message-ID: <6a181a6a-f0d4-4d08-a6ee-bac5f46fce84@x29g2000prf.googlegroups.com> (raw)
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/
☄
reply other threads:[~2009-03-10 2:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6a181a6a-f0d4-4d08-a6ee-bac5f46fce84@x29g2000prf.googlegroups.com \
--to=xahlee@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.