Mar*_*rko 7 emacs elisp haxe autocomplete
我正在使用emacs中的自动完成实现haxe编程语言.
我已经想出如何获得我想要呈现的自动填充列表.列表格式如下:
'((name1 type1 desc1)
(name2 type2 desc2) ...
Run Code Online (Sandbox Code Playgroud)
我希望在光标位置之后显示包含格式为"name1 type1"的文本的用户列表(如在自动完成模式下)和用于迷你缓冲区中当前所选项目的desc.用户应该能够选择完成或放弃自动完成模式.
当用户选择某些内容时,应在光标位置插入name1.
最好/最简单的方法是什么?是否有一些标准的emacs方法可以做到这一点,或者我应该自己编写代码?
编辑:我有函数来获取基于缓冲区的自动完成候选列表.现在我正在努力如何将其集成到自动完成模式.由于get-completion是繁重的操作,我想只在游标"on"时触发它.字符.
这是我的代码.
(defun get-completes-from-haxe (hxml-file file pos)
(let* ((completion-buffer (get-buffer-create "*haxe-completions*"))
(cmd (concat "cd " (file-name-directory hxml-file) "; haxe " hxml-file " --display " file "@" (number-to-string pos))))
(ignore-errors
(shell-command cmd completion-buffer)
(let ((clist (xml-parse-region 1 (buffer-size completion-buffer) completion-buffer))
(completes nil))
(dolist (s (cddar clist))
(when (listp s)
(let* ((item (cdr s))
(name (cdaar item))
(type (car (cddadr item)))
(desc (cdddr item)))
(setf completes (cons name completes)))))
completes))))
(defun file-find-upwards (buffer file-name)
;; Chase links in the source file and search in the dir where it points.
(setq dir-name (or (and (buffer-file-name buffer)
(file-name-directory (file-chase-links
(buffer-file-name buffer))))
default-directory))
;; Chase links before visiting the file. This makes it easier to
;; use a single file for several related directories.
(setq dir-name (file-chase-links dir-name))
(setq dir-name (expand-file-name dir-name))
;; Move up in the dir hierarchy till we find a change log file.
(let ((file1 (concat dir-name file-name))
parent-dir)
(while (and (not (file-exists-p file1))
(progn (setq parent-dir
(file-name-directory
(directory-file-name
(file-name-directory file1))))
;; Give up if we are already at the root dir.
(not (string= (file-name-directory file1)
parent-dir))))
;; Move up to the parent dir and try again.
(setq file1 (expand-file-name file-name parent-dir)))
;; If we found the file in a parent dir, use that. Otherwise,
;; return nil
(if (or (get-file-buffer file1) (file-exists-p file1))
file1
nil)))
(defun get-candidate-list (buffer pos)
(get-completes-from-haxe
(file-find-upwards buffer "compile.hxml")
(buffer-file-name buffer)
pos))
Run Code Online (Sandbox Code Playgroud)