emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master dc219b3 12/57: Add counsel-load-library


From: Oleh Krehel
Subject: [elpa] master dc219b3 12/57: Add counsel-load-library
Date: Tue, 19 May 2015 14:21:23 +0000

branch: master
commit dc219b312075f65d6987071352a663d526b3320c
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Add counsel-load-library
    
    * counsel.el (counsel-directory-parent): New defun.
    (counsel-load-library): New command.
    
    Improve on `load-library':
    
    - don't consider .*elc or .*pkg.elc?, they're usually useless
    - resolve duplicates in a similar way to uniquify (prepend parent directory)
    - allow to jump-to-library with "C-." (see `counsel-describe-map')
---
 counsel.el |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/counsel.el b/counsel.el
index 7ee63fc..a0e6813 100644
--- a/counsel.el
+++ b/counsel.el
@@ -260,6 +260,42 @@
         (delete-region (car bnd) (cdr bnd)))
       (insert res))))
 
+(defun counsel-directory-parent (dir)
+  "Return the directory parent of directory DIR."
+  (concat (file-name-nondirectory
+           (directory-file-name dir)) "/"))
+
+(defun counsel-load-library ()
+  "Load a selected the Emacs Lisp library.
+The libraries are offered from `load-path'."
+  (interactive)
+  (let ((dirs load-path)
+        (suffix (concat (regexp-opt '(".el" ".el.gz") t) "\\'"))
+        (cands (make-hash-table :test #'equal))
+        short-name
+        old-dir)
+    (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))
+                  (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)
+              :action (lambda ()
+                        (load-library ivy--current))
+              :keymap counsel-describe-map)))
+
 (provide 'counsel)
 
 ;;; counsel.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]