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

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

[elpa] master 2f4c2c1 18/18: Merge commit 'efa18eca10e5a0e05043f872cf994


From: Oleh Krehel
Subject: [elpa] master 2f4c2c1 18/18: Merge commit 'efa18eca10e5a0e05043f872cf9945842bb3a034' from swiper
Date: Mon, 20 Apr 2015 12:39:09 +0000

branch: master
commit 2f4c2c1b7de390b2135bbc2b2795014f3e73e771
Merge: d4a79d3 efa18ec
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Merge commit 'efa18eca10e5a0e05043f872cf9945842bb3a034' from swiper
---
 packages/swiper/counsel.el  |   53 +++++++++++++++++++-
 packages/swiper/ivy-test.el |    1 +
 packages/swiper/ivy.el      |  114 ++++++++++++++++++++++++++++++++-----------
 packages/swiper/swiper.el   |   15 ++++--
 4 files changed, 146 insertions(+), 37 deletions(-)

diff --git a/packages/swiper/counsel.el b/packages/swiper/counsel.el
index c1b90d6..4a97913 100644
--- a/packages/swiper/counsel.el
+++ b/packages/swiper/counsel.el
@@ -5,7 +5,7 @@
 ;; Author: Oleh Krehel <address@hidden>
 ;; URL: https://github.com/abo-abo/swiper
 ;; Version: 0.1.0
-;; Package-Requires: ((emacs "24.1") (swiper "0.2.1"))
+;; Package-Requires: ((emacs "24.1") (swiper "0.3.0"))
 ;; Keywords: completion, matching
 
 ;; This file is part of GNU Emacs.
@@ -40,6 +40,32 @@
   (counsel--generic
    (lambda (str) (all-completions str obarray))))
 
+(defvar counsel-describe-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "C-.") 'counsel-find-symbol)
+    map))
+
+(defun counsel-find-symbol ()
+  "Jump to the definition of the current symbol."
+  (interactive)
+  (setq ivy--action 'counsel--find-symbol)
+  (setq ivy-exit 'done)
+  (exit-minibuffer))
+
+(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
+                (prin1-to-string sym)))
+           (find-library (prin1-to-string sym)))
+          (t
+           (error "Couldn't fild definition of %s"
+                  sym)))))
+
 (defun counsel-describe-variable (variable &optional buffer frame)
   "Forward to (`describe-variable' VARIABLE BUFFER FRAME)."
   (interactive
@@ -59,7 +85,7 @@
                                (and (boundp vv) (not (keywordp vv))))
                        (push (symbol-name vv) cands))))
                   cands)
-                nil nil nil preselect))
+                nil nil counsel-describe-map preselect))
      (list (if (equal val "")
                v
              (intern val)))))
@@ -81,7 +107,7 @@
                               (when (fboundp x)
                                 (push (symbol-name x) cands))))
                            cands)
-                         nil nil nil preselect))
+                         nil nil counsel-describe-map preselect))
      (list (if (equal val "")
                fn (intern val)))))
   (describe-function function))
@@ -149,6 +175,27 @@
     (when file
       (find-file file))))
 
+(defun counsel-git-grep-function (string &optional _pred &rest _unused)
+  "Grep in the current git repository for STRING."
+  (split-string
+   (shell-command-to-string
+    (format "git --no-pager grep --full-name -n --no-color -i -e \"%s\"" 
string))
+   "\n"
+   t))
+
+(defun counsel-git-grep ()
+  "Grep for a string in the current git repository."
+  (interactive)
+  (let ((default-directory (locate-dominating-file
+                             default-directory ".git"))
+        (val (ivy-read "pattern: " 'counsel-git-grep-function))
+        lst)
+    (when val
+      (setq lst (split-string val ":"))
+      (find-file (car lst))
+      (goto-char (point-min))
+      (forward-line (1- (string-to-number (cadr lst)))))))
+
 (defun counsel--generic (completion-fn)
   "Complete thing at point with COMPLETION-FN."
   (let* ((bnd (bounds-of-thing-at-point 'symbol))
diff --git a/packages/swiper/ivy-test.el b/packages/swiper/ivy-test.el
index a33f886..957f824 100644
--- a/packages/swiper/ivy-test.el
+++ b/packages/swiper/ivy-test.el
@@ -20,6 +20,7 @@
 ;; see <http://www.gnu.org/licenses/>.
 
 (require 'ert)
+(require 'ivy)
 
 (defvar ivy-expr nil
   "Holds a test expression to evaluate with `ivy-eval'.")
diff --git a/packages/swiper/ivy.el b/packages/swiper/ivy.el
index 78a50a3..2802f07 100644
--- a/packages/swiper/ivy.el
+++ b/packages/swiper/ivy.el
@@ -48,6 +48,10 @@
   '((t (:inherit highlight)))
   "Face used by Ivy for highlighting first match.")
 
+(defface ivy-subdir
+  '((t (:weight bold)))
+  "Face used by Ivy for highlighting subdirs in the alternatives.")
+
 (defcustom ivy-height 10
   "Number of lines for the minibuffer window."
   :type 'integer)
@@ -89,6 +93,8 @@ Only \"./\" and \"../\" apply here. They appear in reverse 
order."
     (define-key map (kbd "M-n") 'ivy-next-history-element)
     (define-key map (kbd "M-p") 'ivy-previous-history-element)
     (define-key map (kbd "C-g") 'minibuffer-keyboard-quit)
+    (define-key map (kbd "C-v") 'ivy-scroll-up-command)
+    (define-key map (kbd "M-v") 'ivy-scroll-down-command)
     map)
   "Keymap used in the minibuffer.")
 
@@ -147,14 +153,25 @@ When non-nil, it should contain one %d.")
   "Exit the minibuffer with the selected candidate."
   (interactive)
   (delete-minibuffer-contents)
-  (if (zerop ivy--length)
-      (when (memq ivy-require-match '(nil confirm confirm-after-completion))
-        (insert ivy-text)
-        (setq ivy-exit 'done))
-    (if ivy--directory
-        (insert (expand-file-name ivy--current ivy--directory))
-      (insert ivy--current))
-    (setq ivy-exit 'done))
+  (cond (ivy--directory
+         (insert
+          (cond ((string= ivy-text "")
+                 (if (equal ivy--current "./")
+                     ivy--directory
+                   ivy--current))
+                ((zerop ivy--length)
+                 (expand-file-name ivy-text ivy--directory))
+                (t
+                 (expand-file-name ivy--current ivy--directory))))
+         (setq ivy-exit 'done))
+        ((zerop ivy--length)
+         (when (memq ivy-require-match
+                     '(nil confirm confirm-after-completion))
+           (insert ivy-text)
+           (setq ivy-exit 'done)))
+        (t
+         (insert ivy--current)
+         (setq ivy-exit 'done)))
   (exit-minibuffer))
 
 (defun ivy-alt-done ()
@@ -167,6 +184,7 @@ When non-nil, it should contain one %d.")
            (ivy-done))
 
           ((and ivy--directory
+                (plusp ivy--length)
                 (file-directory-p
                  (setq dir (expand-file-name
                             ivy--current ivy--directory))))
@@ -186,6 +204,18 @@ When non-nil, it should contain one %d.")
   (interactive)
   (setq ivy--index (1- ivy--length)))
 
+(defun ivy-scroll-up-command ()
+  "Scroll the candidates upward by the minibuffer height."
+  (interactive)
+  (setq ivy--index (min (+ ivy--index ivy-height)
+                        (1- ivy--length))))
+
+(defun ivy-scroll-down-command ()
+  "Scroll the candidates downward by the minibuffer height."
+  (interactive)
+  (setq ivy--index (max (- ivy--index ivy-height)
+                        0)))
+
 (defun ivy-next-line (&optional arg)
   "Move cursor vertically down ARG candidates."
   (interactive "p")
@@ -259,6 +289,21 @@ On error (read-only), call `ivy-on-del-error-function'."
        (when ivy-on-del-error-function
          (funcall ivy-on-del-error-function))))))
 
+(defun ivy-sort-file-function-default (x y)
+  "Compare two files X and Y.
+Prioritize directories."
+  (if (get-text-property 0 'dirp x)
+      (if (get-text-property 0 'dirp y)
+          (string< x y)
+        t)
+    (if (get-text-property 0 'dirp y)
+        nil
+      (string< x y))))
+
+(defvar ivy-sort-file-function 'ivy-sort-file-function-default
+  "The function that compares file names.
+It should take two string arguments and return nil and non-nil.")
+
 (defun ivy--sorted-files (dir)
   "Return the list of files in DIR.
 Directories come first."
@@ -266,16 +311,12 @@ Directories come first."
          (seq (all-completions "" 'read-file-name-internal)))
     (if (equal dir "/")
         seq
-      (setq seq (cl-sort
-                 (delete "./" (delete "../" seq))
-                 (lambda (x y)
-                   (if (file-directory-p x)
-                       (if (file-directory-p y)
-                           (string< x y)
-                         t)
-                     (if (file-directory-p y)
-                         nil
-                       (string< x y))))))
+      (setq seq (delete "./" (delete "../" seq)))
+      (when (eq ivy-sort-file-function 'ivy-sort-file-function-default)
+        (setq seq (mapcar (lambda (x)
+                            (propertize x 'dirp (string-match-p "/$" x)))
+                          (delete "./" (delete "../" seq)))))
+      (setq seq (cl-sort seq ivy-sort-file-function))
       (dolist (dir ivy-extra-directories)
         (push dir seq))
       seq)))
@@ -417,10 +458,11 @@ Turning on Ivy mode will set `completing-read-function' to
            (lambda (x)
              (string-match initial-input x))
            candidates)))
-  (cl-position-if
-   (lambda (x)
-     (string-match preselect x))
-   candidates))
+  (or (cl-position preselect candidates :test 'equal)
+      (cl-position-if
+       (lambda (x)
+         (string-match preselect x))
+       candidates)))
 
 ;;* Implementation
 ;;** Regex
@@ -537,13 +579,21 @@ NAME is a string of words separated by spaces that is 
used to
 build a regex.
 CANDIDATES is a list of strings."
   (let* ((re (ivy--regex name))
-         (cands (if (and (equal re ivy--old-re)
-                         ivy--old-cands)
-                    ivy--old-cands
-                  (ignore-errors
-                    (cl-remove-if-not
-                     (lambda (x) (string-match re x))
-                     candidates))))
+         (cands (cond ((and (equal re ivy--old-re)
+                            ivy--old-cands)
+                       ivy--old-cands)
+                      ((and ivy--old-re
+                            (not (equal ivy--old-re ""))
+                            (eq 0 (cl-search ivy--old-re re)))
+                       (ignore-errors
+                         (cl-remove-if-not
+                          (lambda (x) (string-match re x))
+                          ivy--old-cands)))
+                      (t
+                       (ignore-errors
+                         (cl-remove-if-not
+                          (lambda (x) (string-match re x))
+                          candidates)))))
          (tail (nthcdr ivy--index ivy--old-cands))
          (ww (window-width))
          idx)
@@ -566,6 +616,12 @@ CANDIDATES is a list of strings."
              (end (min (+ start (1- ivy-height)) ivy--length))
              (cands (cl-subseq cands start end))
              (index (min ivy--index half-height (1- (length cands)))))
+        (when ivy--directory
+          (setq cands (mapcar (lambda (x)
+                                (if (string-match-p "/$" x)
+                                    (propertize x 'face 'ivy-subdir)
+                                  x))
+                              cands)))
         (setq ivy--current (copy-sequence (nth index cands)))
         (setf (nth index cands)
               (ivy--add-face ivy--current 'ivy-current-match))
diff --git a/packages/swiper/swiper.el b/packages/swiper/swiper.el
index 66a9058..3190d92 100644
--- a/packages/swiper/swiper.el
+++ b/packages/swiper/swiper.el
@@ -4,7 +4,7 @@
 
 ;; Author: Oleh Krehel <address@hidden>
 ;; URL: https://github.com/abo-abo/swiper
-;; Version: 0.2.1
+;; Version: 0.3.0
 ;; Package-Requires: ((emacs "24.1"))
 ;; Keywords: matching
 
@@ -240,10 +240,15 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
         (overlay-put ov 'face 'swiper-line-face)
         (overlay-put ov 'window swiper--window)
         (push ov swiper--overlays))
-      (swiper--add-overlays
-       re
-       (window-start swiper--window)
-       (window-end swiper--window t)))))
+      (let ((wh (window-height)))
+        (swiper--add-overlays
+         re
+         (save-excursion
+           (forward-line (- wh))
+           (point))
+         (save-excursion
+           (forward-line wh)
+           (point)))))))
 
 (defun swiper--add-overlays (re beg end)
   "Add overlays for RE regexp in current buffer between BEG and END."



reply via email to

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