;; re-building it into a regex.
;; So "for example" is transformed into "\\(for\\).*\\(example\\)".
+(require 'cl-lib)
+
;;; Code:
;;* Customization
(defgroup ivy nil
This is usually meant as a quick exit out of the minibuffer."
:type 'function)
+ (defcustom ivy-extra-directories '("../" "./")
+ "Add this to the front of the list when completing file names.
+ Only \"./\" and \"../\" apply here. They appear in reverse order."
+ :type 'list)
+
;;* User Visible
;;** Keymap
(require 'delsel)
(defvar ivy--directory nil
"Current directory when completing file names.")
+ (defvar ivy--length 0
+ "Store the amount of viable candidates.")
+
+ (defvar ivy-text ""
+ "Store the user's string as it is typed in.")
+
+ (defvar ivy--current ""
+ "Current candidate.")
+
+ (defvar ivy--index 0
+ "Store the index of the current candidate.")
+
+ (defvar ivy-exit nil
+ "Store 'done if the completion was successfully selected.
+ Otherwise, store nil.")
+
+ (defvar ivy--action nil
+ "Store a function to call at the end of `ivy--read'.")
+
+ (defvar ivy--all-candidates nil
+ "Store the candidates passed to `ivy-read'.")
+
+ (defvar ivy--default nil
+ "Default initial input.")
+
+ (defvar ivy--update-fn nil
+ "Current function to call when current candidate(s) update.")
+
+ (defvar ivy--prompt nil
+ "Store the format-style prompt.
+ When non-nil, it should contain one %d.")
+
+ (defvar ivy--old-re nil
+ "Store the old regexp.")
+
+ (defvar ivy--old-cands nil
+ "Store the candidates matched by `ivy--old-re'.")
+
;;** Commands
(defun ivy-done ()
"Exit the minibuffer with the selected candidate."
(seq (all-completions "" 'read-file-name-internal)))
(if (equal dir "/")
seq
- (cons "./" (cons "../"
- (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 (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))))))
+ (dolist (dir ivy-extra-directories)
+ (push dir seq))
+ seq)))
;;** Entry Point
(defun ivy-read (prompt collection
"Toggle Ivy mode on or off.
With ARG, turn Ivy mode on if arg is positive, off otherwise.
Turning on Ivy mode will set `completing-read-function' to
- `ivy-completing-read'."
+ `ivy-completing-read'.
+
+ \\{ivy-minibuffer-map}"
:group 'ivy
:global t
:lighter " ivy"
(setq completing-read-function 'ivy-completing-read)
(setq completing-read-function 'completing-read-default)))
- (defvar ivy--action nil
- "Store a function to call at the end of `ivy--read'.")
-
(defun ivy--preselect-index (candidates initial-input preselect)
"Return the index in CANDIDATES filtered by INITIAL-INPUT for PRESELECT."
(when initial-input
(string-match preselect x))
candidates))
- (defvar ivy-text ""
- "Stores the user's string as it is typed in.")
-
- (defvar ivy-exit nil
- "Store 'done if the completion was successfully selected.
- Otherwise, store nil.")
-
;;* Implementation
;;** Regex
(defvar ivy--subexps 0
;; show completions with empty input
(ivy--exhibit))
- (defvar ivy--all-candidates nil
- "Store the candidates passed to `ivy-read'.")
-
- (defvar ivy--index 0
- "Store the index of the current candidate.")
-
- (defvar ivy--length 0
- "Store the amount of viable candidates.")
-
- (defvar ivy--current ""
- "Current candidate.")
-
- (defvar ivy--default nil
- "Default initial input.")
-
- (defvar ivy--update-fn nil
- "Current function to call when current candidate(s) update.")
-
(defun ivy--input ()
"Return the current minibuffer input."
;; assume one-line minibuffer input
(goto-char (minibuffer-prompt-end))
(delete-region (line-end-position) (point-max))))
- (defvar ivy--prompt nil
- "Store the format-style prompt.
- When non-nil, it should contain one %d.")
-
(defun ivy--insert-prompt ()
"Update the prompt according to `ivy--prompt'."
(when ivy--prompt
(forward-line 1)
(insert text)))))
- (defvar ivy--old-re nil
- "Store the old regexp.")
-
- (defvar ivy--old-cands nil
- "Store the candidates matched by `ivy--old-re'.")
-
(defun ivy--add-face (str face)
"Propertize STR with FACE.
`font-lock-append-text-property' is used, since it's better than