Tôi đang làm việc về triển khai tự động hoàn thành trong các emacs cho ngôn ngữ lập trình haxe.Làm thế nào để hiển thị các lựa chọn tự động hoàn thành trong các emacs?
Tôi đã tìm ra cách lấy danh sách các tự động hoàn thành mà tôi muốn trình bày. Danh sách này là ở định dạng:
'((name1 type1 desc1)
(name2 type2 desc2) ...
Tôi muốn hiển thị danh sách người dùng chứa văn bản ở định dạng "name1 type1" sau khi vị trí con trỏ (như trong autocomplete-mode) và desc cho mặt hàng đang được chọn trong minibuffer. Người dùng có thể chọn hoàn thành hoặc bỏ cuộc như ở chế độ tự động hoàn thành.
Khi người dùng chọn thứ gì đó, tên1 sẽ được chèn vào vị trí con trỏ.
Cách tốt nhất/dễ nhất để thực hiện việc này là gì? Có một số cách emacs tiêu chuẩn để làm điều này, hoặc tôi nên mã một cái gì đó của riêng tôi?
EDIT: Tôi có các chức năng để nhận danh sách các ứng viên tự động điền dựa trên bộ đệm. Bây giờ tôi đang đấu tranh làm thế nào để tích hợp vào chế độ tự động hoàn thành. Vì get-completes là hoạt động nặng, tôi chỉ muốn kích hoạt nó khi con trỏ đang bật "." tính cách.
Đây là mã tôi có.
(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))
Tôi đã thấy điều đó, nhưng không thể tìm ra cách hiển thị chú giải công cụ và tài liệu với nó. Tất cả nó cung cấp là vim như tự động hoàn thành, mà không phải là những gì tôi muốn. – Marko
Hình như ở chế độ tự động, chức năng ac-select-ứng cử viên được sử dụng để hiển thị lựa chọn hiện tại của ứng cử viên, bạn có thể xác định lời khuyên cho chức năng đó để hiển thị desc trong minibuffer – user49117