[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 94fad10 06/31: Improve the match confirm while completing
From: |
Oleh Krehel |
Subject: |
[elpa] master 94fad10 06/31: Improve the match confirm while completing files |
Date: |
Fri, 01 May 2015 14:28:43 +0000 |
branch: master
commit 94fad10cb9df72367e933ec23dbd4f6b4a7c049e
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Improve the match confirm while completing files
* ivy.el (ivy-confirm-face): New face.
(ivy-match-required-face): New face.
(ivy--prompt-extra): New defvar, the prompt is concatenaded with this.
(ivy--extend-prompt): Remove.
(ivy-done): Update.
(ivy--insert-prompt): Use `ivy--prompt-extra'. Reset it unless the
`this-command' is appropriate.
(ivy--set-match-props): New defun.
Fixes #60
---
ivy.el | 90 +++++++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 58 insertions(+), 32 deletions(-)
diff --git a/ivy.el b/ivy.el
index 8b95c9f..feba7a2 100644
--- a/ivy.el
+++ b/ivy.el
@@ -48,6 +48,14 @@
'((t (:inherit highlight)))
"Face used by Ivy for highlighting first match.")
+(defface ivy-confirm-face
+ '((t :foreground "ForestGreen"))
+ "Face used by Ivy to issue a confirmation prompt.")
+
+(defface ivy-match-required-face
+ '((t :foreground "red"))
+ "Face used by Ivy to issue a match required prompt.")
+
(defface ivy-subdir
'((t (:weight bold)))
"Face used by Ivy for highlighting subdirs in the alternatives.")
@@ -159,6 +167,9 @@ Otherwise, store nil.")
"Store the format-style prompt.
When non-nil, it should contain one %d.")
+(defvar ivy--prompt-extra ""
+ "Temporary modifications to the prompt")
+
(defvar ivy--old-re nil
"Store the old regexp.")
@@ -170,16 +181,6 @@ When non-nil, it should contain one %d.")
(defvar Info-current-file)
-(defun ivy--extend-prompt (str)
- "Extend the current prompt with STR."
- (unless (string-match str ivy--prompt)
- (setq ivy--prompt
- (if (string-match ": $" ivy--prompt)
- (concat
- (substring ivy--prompt 0 -2)
- " " str ": ")
- (concat ivy--prompt str " ")))))
-
;;** Commands
(defun ivy-done ()
"Exit the minibuffer with the selected candidate."
@@ -188,12 +189,12 @@ When non-nil, it should contain one %d.")
(when (cond (ivy--directory
(if (zerop ivy--length)
(if (or (not (eq confirm-nonexistent-file-or-buffer t))
- (string-match "confirm" ivy--prompt))
+ (equal " (confirm)" ivy--prompt-extra))
(progn
(insert
(expand-file-name ivy-text ivy--directory))
(setq ivy-exit 'done))
- (ivy--extend-prompt "confirm")
+ (setq ivy--prompt-extra " (confirm)")
(insert ivy-text)
(ivy--exhibit)
nil)
@@ -207,7 +208,7 @@ When non-nil, it should contain one %d.")
(progn
(insert ivy-text)
(setq ivy-exit 'done))
- (ivy--extend-prompt "(match required)")
+ (setq ivy--prompt-extra " (match required)")
(insert ivy-text)
(ivy--exhibit)
nil))
@@ -678,25 +679,50 @@ When GREEDY is non-nil, join words in a greedy way."
(defun ivy--insert-prompt ()
"Update the prompt according to `ivy--prompt'."
(when ivy--prompt
- (let ((inhibit-read-only t)
- (n-str
- (format
- (if ivy--directory
- (concat ivy--prompt (abbreviate-file-name ivy--directory))
- ivy--prompt)
- (or (and ivy--dynamic-function
- ivy--full-length)
- ivy--length))))
- (save-excursion
- (goto-char (point-min))
- (delete-region (point-min) (minibuffer-prompt-end))
- (set-text-properties
- 0 (length n-str)
- '(front-sticky t rear-nonsticky t field t read-only t face
minibuffer-prompt)
- n-str)
- (insert n-str))
- ;; get out of the prompt area
- (constrain-to-field nil (point-max)))))
+ (unless (memq this-command '(ivy-done ivy-alt-done))
+ (setq ivy--prompt-extra ""))
+ (let (head tail)
+ (if (string-match "\\(.*\\): $" ivy--prompt)
+ (progn
+ (setq head (match-string 1 ivy--prompt))
+ (setq tail ": "))
+ (setq head (substring ivy--prompt 0 -1))
+ (setq tail " "))
+ (let ((inhibit-read-only t)
+ (std-props '(front-sticky t rear-nonsticky t field t read-only t))
+ (n-str
+ (format
+ (concat head
+ ivy--prompt-extra
+ tail
+ (if ivy--directory
+ (abbreviate-file-name ivy--directory)
+ ""))
+ (or (and ivy--dynamic-function
+ ivy--full-length)
+ ivy--length))))
+ (save-excursion
+ (goto-char (point-min))
+ (delete-region (point-min) (minibuffer-prompt-end))
+ (set-text-properties 0 (length n-str)
+ `(face minibuffer-prompt ,@std-props)
+ n-str)
+ (ivy--set-match-props n-str "confirm"
+ `(face ivy-confirm-face ,@std-props))
+ (ivy--set-match-props n-str "match required"
+ `(face ivy-match-required-face ,@std-props))
+ (insert n-str))
+ ;; get out of the prompt area
+ (constrain-to-field nil (point-max))))))
+
+(defun ivy--set-match-props (str match props)
+ "Set STR text proprties that match MATCH to PROPS."
+ (when (string-match match str)
+ (set-text-properties
+ (match-beginning 0)
+ (match-end 0)
+ props
+ str)))
(defvar inhibit-message)
- [elpa] master updated (fddedd2 -> 4137447), Oleh Krehel, 2015/05/01
- [elpa] master 455bea4 01/31: ivy.el (ivy--cd): Reset `ivy--old-re', Oleh Krehel, 2015/05/01
- [elpa] master 691b12c 02/31: ivy.el (ivy-read): Fixup preselect addition, Oleh Krehel, 2015/05/01
- [elpa] master 3953b16 03/31: Respect `confirm-nonexistent-file-or-buffer', Oleh Krehel, 2015/05/01
- [elpa] master 948620f 04/31: Propertize remote buffers with ivy-remote face, Oleh Krehel, 2015/05/01
- [elpa] master e356df9 05/31: Reset to the first candidate when switching directories, Oleh Krehel, 2015/05/01
- [elpa] master 94fad10 06/31: Improve the match confirm while completing files,
Oleh Krehel <=
- [elpa] master c816430 07/31: Minibuffer faces should inherit minibuffer-prompt, Oleh Krehel, 2015/05/01
- [elpa] master b2c9a20 09/31: Store the preselect and use it for empty ivy-text, Oleh Krehel, 2015/05/01
- [elpa] master 988b78f 08/31: Improve completion history using the propertize trick, Oleh Krehel, 2015/05/01
- [elpa] master eb43e4a 10/31: ivy.el (ivy-alt-done): Treat `ivy-text' with ":" verbatim, Oleh Krehel, 2015/05/01
- [elpa] master 00810d6 11/31: ivy.el (ivy--filter): Fixup, Oleh Krehel, 2015/05/01
- [elpa] master 7f04019 12/31: swiper.el (swiper-font-lock-ensure): Exclude `elfeed-search-mode', Oleh Krehel, 2015/05/01
- [elpa] master 278870e 13/31: Use alpha compositing to add ivy-current-match face, Oleh Krehel, 2015/05/01
- [elpa] master 57de44c 14/31: Makefile: Update, Oleh Krehel, 2015/05/01
- [elpa] master 56d7802 15/31: Add an option for multi-tier regex matching, Oleh Krehel, 2015/05/01
- [elpa] master 7299950 16/31: ivy.el: Fixup docstrings, Oleh Krehel, 2015/05/01