[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master fb3fce9 13/57: Add parents using 'display for `counsel-loa
From: |
Oleh Krehel |
Subject: |
[elpa] master fb3fce9 13/57: Add parents using 'display for `counsel-load-library' |
Date: |
Tue, 19 May 2015 14:21:24 +0000 |
branch: master
commit fb3fce911751228af8f78b3524d1ca18c615d11b
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add parents using 'display for `counsel-load-library'
* counsel.el (counsel--find-symbol): The argument string may have a
'full-name property.
(counsel-string-compose): New defun.
(counsel-load-library): Make libraries unique through text properties.
Re #79
---
counsel.el | 75 +++++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 52 insertions(+), 23 deletions(-)
diff --git a/counsel.el b/counsel.el
index a0e6813..ce64c3a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -52,18 +52,22 @@
(ivy-done))
(defun counsel--find-symbol ()
- (let ((sym (read ivy--current)))
- (cond ((boundp sym)
- (find-variable sym))
- ((fboundp sym)
- (find-function sym))
- ((or (featurep sym)
- (locate-library
+ (let ((full-name (get-text-property 0 'full-name ivy--current)))
+ (if full-name
+ (find-library full-name)
+ (let ((sym (read ivy--current)))
+ (cond ((boundp sym)
+ (find-variable sym))
+ ((fboundp sym)
+ (find-function sym))
+ ((or (featurep sym)
+ (locate-library
+ (prin1-to-string sym)))
+ (find-library
(prin1-to-string sym)))
- (find-library (prin1-to-string sym)))
- (t
- (error "Couldn't fild definition of %s"
- sym)))))
+ (t
+ (error "Couldn't fild definition of %s"
+ sym)))))))
(defvar counsel-describe-symbol-history nil
"History for `counsel-describe-variable' and `counsel-describe-function'.")
@@ -265,6 +269,15 @@
(concat (file-name-nondirectory
(directory-file-name dir)) "/"))
+(defun counsel-string-compose (prefix str)
+ "Make PREFIX the display prefix of STR though text properties."
+ (let ((str (copy-sequence str)))
+ (put-text-property
+ 0 1 'display
+ (concat prefix (substring str 0 1))
+ str)
+ str))
+
(defun counsel-load-library ()
"Load a selected the Emacs Lisp library.
The libraries are offered from `load-path'."
@@ -273,27 +286,43 @@ The libraries are offered from `load-path'."
(suffix (concat (regexp-opt '(".el" ".el.gz") t) "\\'"))
(cands (make-hash-table :test #'equal))
short-name
- old-dir)
+ old-val
+ dir-parent
+ res)
(dolist (dir dirs)
(when (file-directory-p dir)
(dolist (file (file-name-all-completions "" dir))
(when (string-match suffix file)
(unless (string-match "pkg.elc?$" file)
(setq short-name (substring file 0 (match-beginning 0)))
- (if (setq old-dir (gethash short-name cands))
+ (if (setq old-val (gethash short-name cands))
(progn
- (remhash short-name cands)
;; assume going up directory once will resolve name clash
- (puthash (concat (counsel-directory-parent old-dir)
- short-name)
- old-dir cands)
- (puthash (concat (counsel-directory-parent dir)
- short-name)
- dir cands))
- (puthash short-name dir cands)))))))
- (ivy-read "Load library: " (hash-table-keys cands)
+ (setq dir-parent (counsel-directory-parent (cdr old-val)))
+ (puthash short-name
+ (cons
+ (counsel-string-compose dir-parent (car old-val))
+ (cdr old-val))
+ cands)
+ (setq dir-parent (counsel-directory-parent dir))
+ (puthash (concat dir-parent short-name)
+ (cons
+ (propertize
+ (counsel-string-compose
+ dir-parent short-name)
+ 'full-name (expand-file-name file dir))
+ dir)
+ cands))
+ (puthash short-name
+ (cons (propertize
+ short-name
+ 'full-name (expand-file-name file dir))
+ dir) cands)))))))
+ (maphash (lambda (_k v) (push (car v) res)) cands)
+ (ivy-read "Load library: " (nreverse res)
:action (lambda ()
- (load-library ivy--current))
+ (load-library
+ (get-text-property 0 'full-name ivy--current)))
:keymap counsel-describe-map)))
(provide 'counsel)
- [elpa] master 2c39e10 04/57: "TAB" shouldn't delete input when no candidate, (continued)
- [elpa] master 2c39e10 04/57: "TAB" shouldn't delete input when no candidate, Oleh Krehel, 2015/05/19
- [elpa] master 2d7f287 09/57: Improve "TAB" interaction with `confirm-nonexistent-file-or-buffer', Oleh Krehel, 2015/05/19
- [elpa] master 03ab827 07/57: Merge ivy--collection into ivy-last, Oleh Krehel, 2015/05/19
- [elpa] master dc219b3 12/57: Add counsel-load-library, Oleh Krehel, 2015/05/19
- [elpa] master 8b08cc0 08/57: ivy.el (ivy-done): Simplify and improve, Oleh Krehel, 2015/05/19
- [elpa] master cd083cc 18/57: Add swiper -> avy finalizer, Oleh Krehel, 2015/05/19
- [elpa] master f2a0966 16/57: Add ivy-partial: partial complete without exiting, Oleh Krehel, 2015/05/19
- [elpa] master 386184b 14/57: Merge ivy--update-fn into ivy-last, Oleh Krehel, 2015/05/19
- [elpa] master c5fce64 05/57: Make "TAB" switch directories properly, Oleh Krehel, 2015/05/19
- [elpa] master 6784185 17/57: Allow to use "^" in swiper, Oleh Krehel, 2015/05/19
- [elpa] master fb3fce9 13/57: Add parents using 'display for `counsel-load-library',
Oleh Krehel <=
- [elpa] master 5601653 06/57: Require dired when completing file names, Oleh Krehel, 2015/05/19
- [elpa] master 4a7ba2f 15/57: Try to prevent the resize of minibuffer window, Oleh Krehel, 2015/05/19
- [elpa] master 5a451a9 26/57: ivy.el (ivy-read): Add a re-builder argument, Oleh Krehel, 2015/05/19
- [elpa] master f7fc3ad 11/57: Work around grep-read-files, Oleh Krehel, 2015/05/19
- [elpa] master 056614d 22/57: Rename avy-swiper to swiper-avy, Oleh Krehel, 2015/05/19
- [elpa] master cf292da 23/57: Declare swiper-map, Oleh Krehel, 2015/05/19
- [elpa] master a953af0 19/57: Simplify ivy-partial-or-done, Oleh Krehel, 2015/05/19
- [elpa] master fe34d2c 10/57: ivy.el (ivy-partial-or-done): Handle empty input, Oleh Krehel, 2015/05/19
- [elpa] master 77abf00 25/57: ivy.el (ivy-backward-kill-word): Add and bind to "M-DEL", Oleh Krehel, 2015/05/19
- [elpa] master 8c936bc 21/57: ivy.el (ivy-use-virtual-buffers): New defcustom, Oleh Krehel, 2015/05/19