branch: master commit 315be361d904e33e8a9693f423ac72711307ebbf Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
counsel.el: Add --- counsel.el | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-) diff --git a/counsel.el b/counsel.el new file mode 100644 index 0000000..ecb183b --- /dev/null +++ b/counsel.el @@ -0,0 +1,54 @@ +;;; consel.el --- Elisp completion at point -*- lexical-binding: t -*- + +;; Copyright (C) 2015 Oleh Krehel + +;; Author: Oleh Krehel <ohwoeo...@gmail.com> +;; URL: https://github.com/abo-abo/swiper +;; Version: 0.1.0 +;; Package-Requires: ((emacs "24.1")) +;; Keywords: completion + +;; This file is not part of GNU Emacs + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; For a full copy of the GNU General Public License +;; see <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; Just call `counsel' to start completing the `obarray'. +;; The initial (optional) input is thing-at-point. + +;;; Code: + +(require 'ivy) + +(defun counsel () + "Elisp completion at point." + (interactive) + (let* ((bnd (bounds-of-thing-at-point 'symbol)) + (str (if bnd + (buffer-substring-no-properties + (car bnd) (cdr bnd)) + "")) + (candidates (all-completions str obarray)) + (ivy-height 7) + (res (ivy-read (format "pattern (%s): " str) + candidates))) + (when (stringp res) + (when bnd + (delete-region (car bnd) (cdr bnd))) + (insert res)))) + +(provide 'counsel) + +;;; counsel.el ends here