branch: master commit 5036f23055436acb171e9cfb1b5ad5ad3578ed76 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Make counsel-el work with "C-M-n" and "C-M-p" * counsel.el (counsel-el): Use the whole obarray if no initial input is given. Filter out only function when appropriate. (counsel-completion-beg): New defvar. (counsel-completion-end): New defvar. (counsel--el-action): New defun. * ivy.el (ivy--reset-state): Set `ivy--full-length' to nil. --- counsel.el | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- ivy.el | 1 + 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/counsel.el b/counsel.el index c2d67d6..acc4ca5 100644 --- a/counsel.el +++ b/counsel.el @@ -38,8 +38,61 @@ (defun counsel-el () "Elisp completion at point." (interactive) - (counsel--generic - (lambda (str) (all-completions str obarray)))) + (let* ((bnd (unless (and (looking-at ")") + (eq (char-before) ?\()) + (bounds-of-thing-at-point + 'symbol))) + (str (if bnd + (buffer-substring-no-properties + (car bnd) + (cdr bnd)) + "")) + (ivy-height 7) + (funp (eq (char-before (car bnd)) ?\()) + symbol-names) + (if bnd + (progn + (setq counsel-completion-beg + (move-marker (make-marker) (car bnd))) + (setq counsel-completion-end + (move-marker (make-marker) (cdr bnd)))) + (setq counsel-completion-beg nil) + (setq counsel-completion-end nil)) + (if (string= str "") + (mapatoms + (lambda (x) + (when (symbolp x) + (push (symbol-name x) symbol-names)))) + (setq symbol-names + (all-completions str obarray + (and funp + (lambda (x) + (or (functionp x) + (macrop x) + (special-form-p x))))))) + (ivy-read "Symbol name: " symbol-names + :predicate (and funp #'functionp) + :initial-input str + :action #'counsel--el-action))) + +(defvar counsel-completion-beg nil + "Completion bounds start.") + +(defvar counsel-completion-end nil + "Completion bounds end.") + +(defun counsel--el-action (symbol) + "Insert SYMBOL, erasing the previous one." + (when (stringp symbol) + (when counsel-completion-beg + (delete-region + counsel-completion-beg + counsel-completion-end)) + (setq counsel-completion-beg + (move-marker (make-marker) (point))) + (insert symbol) + (setq counsel-completion-end + (move-marker (make-marker) (point))))) (defvar counsel-describe-map (let ((map (make-sparse-keymap))) diff --git a/ivy.el b/ivy.el index 12b1ad2..f64782c 100644 --- a/ivy.el +++ b/ivy.el @@ -815,6 +815,7 @@ This is useful for recursive `ivy-read'." (setq ivy--subexps 0) (setq ivy--regexp-quote 'regexp-quote) (setq ivy--old-text "") + (setq ivy--full-length nil) (setq ivy-text "") (setq ivy-calling nil) (let (coll sort-fn)