fix(emacs/lean-company): use lean-grab-hname for findp auto-completion
fix #214
This commit is contained in:
parent
2730e5163e
commit
3775d07d5f
2 changed files with 48 additions and 23 deletions
|
@ -170,32 +170,10 @@
|
|||
nil)
|
||||
(t t)))
|
||||
|
||||
(defun lean-find-id-beg ()
|
||||
(save-excursion
|
||||
(let ((initial-pos (point))
|
||||
(mode 'backward)
|
||||
stop char-at-pos success)
|
||||
(while (not stop)
|
||||
(setq char-at-pos (char-after))
|
||||
(cl-case mode
|
||||
('backward
|
||||
(cond
|
||||
((lean-id-rest-p char-at-pos) (backward-char 1))
|
||||
(t (forward-char 1)
|
||||
(setq mode 'forward))))
|
||||
('forward
|
||||
(cond
|
||||
((lean-id-first-p char-at-pos) (setq stop t)
|
||||
(setq success t))
|
||||
((< (point) initial-pos) (forward-char 1))
|
||||
(t (setq stop t))))))
|
||||
(when success
|
||||
(point)))))
|
||||
|
||||
(defun company-lean--findp-prefix ()
|
||||
"Returns the symbol to complete. Also, if point is on a dot,
|
||||
triggers a completion immediately."
|
||||
(let ((prefix (lean-grab-id)))
|
||||
(let ((prefix (lean-grab-hname)))
|
||||
(when (and
|
||||
prefix
|
||||
(company-lean--need-autocomplete)
|
||||
|
|
|
@ -108,6 +108,42 @@
|
|||
(= c ?_)
|
||||
(lean-letter-like-unicode-p c))))
|
||||
|
||||
(defun lean-find-id-beg ()
|
||||
(save-excursion
|
||||
(let ((initial-pos (point))
|
||||
(mode 'backward)
|
||||
stop char-at-pos success)
|
||||
(while (not stop)
|
||||
(setq char-at-pos (char-after))
|
||||
(cl-case mode
|
||||
('backward
|
||||
(cond
|
||||
((lean-id-rest-p char-at-pos) (backward-char 1))
|
||||
(t (forward-char 1)
|
||||
(setq mode 'forward))))
|
||||
('forward
|
||||
(cond
|
||||
((lean-id-first-p char-at-pos) (setq stop t)
|
||||
(setq success t))
|
||||
((< (point) initial-pos) (forward-char 1))
|
||||
(t (setq stop t))))))
|
||||
(when success
|
||||
(point)))))
|
||||
|
||||
(defun lean-find-hname-beg ()
|
||||
(save-excursion
|
||||
(let* ((new-id-beg (lean-find-id-beg))
|
||||
old-id-beg)
|
||||
(while new-id-beg
|
||||
(setq old-id-beg new-id-beg)
|
||||
(goto-char old-id-beg)
|
||||
(cond ((looking-back ".[.]")
|
||||
(backward-char 2)
|
||||
(setq new-id-beg (lean-find-id-beg)))
|
||||
(t
|
||||
(setq new-id-beg nil))))
|
||||
old-id-beg)))
|
||||
|
||||
(defun lean-grab-id ()
|
||||
(interactive)
|
||||
(when (not (bolp))
|
||||
|
@ -119,4 +155,15 @@
|
|||
(when id-beg
|
||||
(buffer-substring id-beg cur-pos))))))
|
||||
|
||||
(defun lean-grab-hname ()
|
||||
(interactive)
|
||||
(when (not (bolp))
|
||||
(save-excursion
|
||||
(let ((cur-pos (point))
|
||||
id-beg)
|
||||
(backward-char 1)
|
||||
(setq id-beg (lean-find-hname-beg))
|
||||
(when id-beg
|
||||
(buffer-substring id-beg cur-pos))))))
|
||||
|
||||
(provide 'lean-util)
|
||||
|
|
Loading…
Reference in a new issue