[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4c99ec6 107/272: counsel.el: Shuffle functions
From: |
Oleh Krehel |
Subject: |
[elpa] master 4c99ec6 107/272: counsel.el: Shuffle functions |
Date: |
Mon, 25 Apr 2016 10:13:19 +0000 |
branch: master
commit 4c99ec6ee59a132ac26611f381a9c343d1246bf3
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el: Shuffle functions
---
counsel.el | 181 ++++++++++++++++++++++++++++++------------------------------
1 file changed, 92 insertions(+), 89 deletions(-)
diff --git a/counsel.el b/counsel.el
index 83ade93..08ff61f 100644
--- a/counsel.el
+++ b/counsel.el
@@ -40,6 +40,27 @@
(list ""
(format "%d chars more" (- n (length ivy-text)))))
+(defun counsel-unquote-regex-parens (str)
+ (replace-regexp-in-string
+ "\\\\)" ")"
+ (replace-regexp-in-string
+ "\\\\(" "("
+ str)))
+
+(defun counsel-directory-parent (dir)
+ "Return the directory parent of directory DIR."
+ (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))
+
;;* Completion at point
;;** Elisp
;;;###autoload
@@ -141,6 +162,22 @@
;;** Clojure
(declare-function cider-sync-request:complete "ext:cider-client")
+(defun counsel--generic (completion-fn)
+ "Complete thing at point with COMPLETION-FN."
+ (let* ((bnd (bounds-of-thing-at-point 'symbol))
+ (str (if bnd
+ (buffer-substring-no-properties
+ (car bnd) (cdr bnd))
+ ""))
+ (candidates (funcall completion-fn str))
+ (ivy-height 7)
+ (res (ivy-read (format "pattern (%s): " str)
+ candidates)))
+ (when (stringp res)
+ (when bnd
+ (delete-region (car bnd) (cdr bnd)))
+ (insert res))))
+
;;;###autoload
(defun counsel-clj ()
"Clojure completion at point."
@@ -324,6 +361,54 @@
(require 'info-look)
(info-lookup 'symbol symbol mode))
+;;;###autoload
+(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-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-val (gethash short-name cands))
+ (progn
+ ;; assume going up directory once will resolve name clash
+ (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 (x)
+ (load-library
+ (get-text-property 0 'full-name x)))
+ :keymap counsel-describe-map)))
+
;;* Git completion
;;** Find file in git project
(defvar counsel--git-dir nil
@@ -611,6 +696,7 @@ When INITIAL-INPUT is non-nil, use it in the minibuffer
during completion."
(format "http://debbugs.gnu.org/cgi/bugreport.cgi?bug=%s"
(substring url 1)))))))
+;;* Async Utility
(defvar counsel--async-time nil
"Store the time when a new process was started.
Or the time of the last minibuffer update.")
@@ -682,6 +768,12 @@ Update the minibuffer with the amount of lines collected
every
(ivy--format ivy--all-candidates)))
(setq counsel--async-time (current-time)))))
+(defun counsel-delete-process ()
+ (let ((process (get-process " *counsel*")))
+ (when process
+ (delete-process process))))
+
+;;* Locate
(defun counsel-locate-action-extern (x)
"Use xdg-open shell command on X."
(call-process shell-file-name nil
@@ -713,12 +805,6 @@ Update the minibuffer with the amount of lines collected
every
'(("x" counsel-locate-action-extern "xdg-open")
("d" counsel-locate-action-dired "dired")))
-(defun counsel-unquote-regex-parens (str)
- (replace-regexp-in-string
- "\\\\)" ")"
- (replace-regexp-in-string
- "\\\\(" "("
- str)))
(defun counsel-locate-function (str)
(if (< (length str) 3)
@@ -730,11 +816,6 @@ Update the minibuffer with the amount of lines collected
every
(ivy--regex str))))
'("" "working...")))
-(defun counsel-delete-process ()
- (let ((process (get-process " *counsel*")))
- (when process
- (delete-process process))))
-
;;;###autoload
(defun counsel-locate (&optional initial-input)
"Call the \"locate\" shell command.
@@ -751,84 +832,6 @@ INITIAL-INPUT can be given as the initial minibuffer
input."
:unwind #'counsel-delete-process
:caller 'counsel-locate))
-(defun counsel--generic (completion-fn)
- "Complete thing at point with COMPLETION-FN."
- (let* ((bnd (bounds-of-thing-at-point 'symbol))
- (str (if bnd
- (buffer-substring-no-properties
- (car bnd) (cdr bnd))
- ""))
- (candidates (funcall completion-fn str))
- (ivy-height 7)
- (res (ivy-read (format "pattern (%s): " str)
- candidates)))
- (when (stringp res)
- (when bnd
- (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-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))
-
-;;;###autoload
-(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-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-val (gethash short-name cands))
- (progn
- ;; assume going up directory once will resolve name clash
- (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 (x)
- (load-library
- (get-text-property 0 'full-name x)))
- :keymap counsel-describe-map)))
-
(defvar counsel-gg-state nil
"The current state of candidates / count sync.")
- [elpa] master 05a7b61 070/272: ivy.el (ivy--reset-state): Support a list of symbols as collection, (continued)
- [elpa] master 05a7b61 070/272: ivy.el (ivy--reset-state): Support a list of symbols as collection, Oleh Krehel, 2016/04/25
- [elpa] master 65ec32c 080/272: README.md: mention the manual more prominently, Oleh Krehel, 2016/04/25
- [elpa] master 4af5c2e 115/272: Add `counsel-locate-cmd-mdfind`, Oleh Krehel, 2016/04/25
- [elpa] master 022e658 090/272: When in prog-mode, "M-n" should wrap input with "\b", Oleh Krehel, 2016/04/25
- [elpa] master 9db8308 103/272: counsel.el: Organize the file with outlines, Oleh Krehel, 2016/04/25
- [elpa] master 1c04fb8 126/272: Add ivy-fixed-height-minibuffer, Oleh Krehel, 2016/04/25
- [elpa] master 7a0b243 130/272: Give ivy-read-read-action enough minibuffer space, Oleh Krehel, 2016/04/25
- [elpa] master 708ca11 141/272: ivy.el: Fix a few face declarations, Oleh Krehel, 2016/04/25
- [elpa] master f647bca 136/272: Simplify the ivy-format-function interface, Oleh Krehel, 2016/04/25
- [elpa] master c2b330b 091/272: doc/ivy.org: Add @vindex and @kindex automatically, Oleh Krehel, 2016/04/25
- [elpa] master 4c99ec6 107/272: counsel.el: Shuffle functions,
Oleh Krehel <=
- [elpa] master 0fd6a75 142/272: Move switch-to-buffer to :display-transformer-fn, Oleh Krehel, 2016/04/25
- [elpa] master f5a21db 157/272: ivy.el: define setq-local and defvar-local unless defined, Oleh Krehel, 2016/04/25
- [elpa] master 71644d9 190/272: ivy.el (ivy-read): Remove code that sets action index to 1, Oleh Krehel, 2016/04/25
- [elpa] master 220fd38 079/272: doc/ivy.org: Improve the markup, Oleh Krehel, 2016/04/25
- [elpa] master 50f3092 169/272: counsel.el (counsel--async-sentinel): Start refactor, Oleh Krehel, 2016/04/25
- [elpa] master 41b8b0d 113/272: ivy.el (ivy-occur): Add a warning, Oleh Krehel, 2016/04/25
- [elpa] master b39e449 228/272: counsel.el (counsel-ag-map): Add, Oleh Krehel, 2016/04/25
- [elpa] master 79f9cda 165/272: counsel-ag: Fix escaping problem, Oleh Krehel, 2016/04/25
- [elpa] master f1c7233 164/272: swiper.el (swiper-occur): Bind ivy--regex-function, Oleh Krehel, 2016/04/25
- [elpa] master 1de78f3 160/272: Improve window handling for ivy-occur, Oleh Krehel, 2016/04/25