Skip to content

Commit cf183ca

Browse files
committed
Completion methods aplenty
* lispy.el (lispy-completion-method): New custom var. (lispy--tag-name-and-file): Give only a plain name for `ido', unless `ido-vertical-mode'. (lispy--select-candidate): Dispatch on `lispy-completion-method'. You can now jump to tags with: - helm - ido - ido-vertical - icomplete-mode - icy-mode - plain-old completing-read Fixes #44.
1 parent 611f2f1 commit cf183ca

File tree

1 file changed

+69
-47
lines changed

1 file changed

+69
-47
lines changed

lispy.el

+69-47
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,16 @@ The hint will consist of the possible nouns that apply to the verb."
226226
:type 'boolean
227227
:group 'lispy)
228228

229+
(defcustom lispy-completion-method 'helm
230+
"Method to select a candidate from a list of strings."
231+
:type '(choice
232+
;; sensible choice for many tags
233+
(const :tag "Helm" helm)
234+
;; `ido-vertical-mode' is highly recommended here
235+
(const :tag "Ido" ido)
236+
;; `icomplete-mode' and `icy-mode' will affect this
237+
(const :tag "Default" default)))
238+
229239
(defface lispy-command-name-face
230240
'((t (:inherit font-lock-function-name-face)))
231241
"Face for Elisp commands."
@@ -4128,25 +4138,28 @@ For example, a `setq' statement is amended with variable name that it uses."
41284138

41294139
(defun lispy--tag-name-and-file (x)
41304140
"Add file name to (`lispy--tag-name' X)."
4131-
(or
4132-
(catch 'break
4133-
(cons
4134-
(concat
4135-
(lispy--pad-string
4136-
(lispy--tag-name x)
4137-
(nth 1 lispy-helm-columns))
4138-
(make-string (- (nth 2 lispy-helm-columns)
4139-
(nth 1 lispy-helm-columns))
4140-
?\ )
4141-
(let ((v (nth 4 x)))
4142-
(file-name-nondirectory
4143-
(cond ((overlayp v)
4144-
(buffer-file-name (overlay-buffer v)))
4145-
((vectorp v)
4146-
(aref v 2))
4147-
(t (error "Unexpected"))))))
4148-
(cdr x)))
4149-
x))
4141+
(if (and (eq lispy-completion-method 'ido)
4142+
(not (bound-and-true-p ido-vertical-mode)))
4143+
x
4144+
(or
4145+
(catch 'break
4146+
(cons
4147+
(concat
4148+
(lispy--pad-string
4149+
(lispy--tag-name x)
4150+
(nth 1 lispy-helm-columns))
4151+
(make-string (- (nth 2 lispy-helm-columns)
4152+
(nth 1 lispy-helm-columns))
4153+
?\ )
4154+
(let ((v (nth 4 x)))
4155+
(file-name-nondirectory
4156+
(cond ((overlayp v)
4157+
(buffer-file-name (overlay-buffer v)))
4158+
((vectorp v)
4159+
(aref v 2))
4160+
(t (error "Unexpected"))))))
4161+
(cdr x)))
4162+
x)))
41504163

41514164
(defun lispy--pad-string (str n)
41524165
"Make STR at most length N."
@@ -4861,34 +4874,43 @@ Try to refresh if nil is returned."
48614874
(defun lispy--select-candidate (candidates action)
48624875
"Select from CANDIDATES list with `helm'.
48634876
ACTION is called for the selected candidate."
4864-
(require 'helm-help)
4865-
;; allows restriction with space
4866-
(require 'helm-match-plugin)
4867-
(let (helm-update-blacklist-regexps)
4868-
(helm :sources
4869-
`((name . "semantic tags")
4870-
(candidates . ,(mapcar
4871-
(lambda (x)
4872-
(if (listp x)
4873-
(if (stringp (cdr x))
4874-
(cons (cdr x) (car x))
4875-
(cons (car x) x))
4876-
x))
4877-
candidates))
4878-
(action . ,action))
4879-
:preselect
4880-
(let ((stag (semantic-current-tag))
4881-
(tag (ignore-errors
4882-
(lispy--current-tag))))
4883-
(if tag
4884-
(if (eq (semantic-tag-class
4885-
stag)
4886-
'function)
4887-
(format "\\_<%s\\_>"
4888-
(semantic-tag-name stag))
4889-
tag)
4890-
""))
4891-
:buffer "*lispy-goto*")))
4877+
(if (eq lispy-completion-method 'helm)
4878+
(progn
4879+
(require 'helm-help)
4880+
;; allows restriction with space
4881+
(require 'helm-match-plugin)
4882+
(let (helm-update-blacklist-regexps)
4883+
(helm :sources
4884+
`((name . "semantic tags")
4885+
(candidates . ,(mapcar
4886+
(lambda (x)
4887+
(if (listp x)
4888+
(if (stringp (cdr x))
4889+
(cons (cdr x) (car x))
4890+
(cons (car x) x))
4891+
x))
4892+
candidates))
4893+
(action . ,action))
4894+
:preselect
4895+
(let ((stag (semantic-current-tag))
4896+
(tag (ignore-errors
4897+
(lispy--current-tag))))
4898+
(if tag
4899+
(if (eq (semantic-tag-class
4900+
stag)
4901+
'function)
4902+
(format "\\_<%s\\_>"
4903+
(semantic-tag-name stag))
4904+
tag)
4905+
""))
4906+
:buffer "*lispy-goto*")))
4907+
(let ((res
4908+
(funcall
4909+
(if (eq lispy-completion-method 'ido)
4910+
#'ido-completing-read
4911+
#'completing-read)
4912+
"tag " (mapcar #'car candidates) nil t)))
4913+
(funcall action (assoc res candidates)))))
48924914

48934915
(defun lispy--action-jump (tag)
48944916
"Jump to TAG."

0 commit comments

Comments
 (0)