[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 426cfcb 028/272: ivy.el (ivy-completion-in-region): Fix a
From: |
Oleh Krehel |
Subject: |
[elpa] master 426cfcb 028/272: ivy.el (ivy-completion-in-region): Fix a few bugs |
Date: |
Mon, 25 Apr 2016 10:13:14 +0000 |
branch: master
commit 426cfcba2b75d27bd98a0bad98e100518021f481
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy-completion-in-region): Fix a few bugs
* ivy.el (ivy-completion-common-length): New defun.
`all-completions' doesn't always return candidates that can replace the
whole region between BEG and END. That's why
`completion-all-completions' should be used, which marks the common part
with 'completions-common-part face. Then the new region to replace is
((- END common-length) . END).
Note also that `text-property-any' doesn't always work in
`ivy-completion-common-length', since the 'face property can be a list.
(ivy-completion-in-region): Set `enable-recursive-minibuffers'.
Fixes #341
---
ivy.el | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/ivy.el b/ivy.el
index b91ad4c..e2c5abc 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1379,18 +1379,37 @@ The previous string is between `ivy-completion-beg' and
`ivy-completion-end'."
(setq ivy-completion-end
(move-marker (make-marker) (point))))))
+(defun ivy-completion-common-length (str)
+ "Return the length of the first 'completions-common-part face in STR."
+ (let ((pos 0)
+ (len (length str)))
+ (while (and (<= pos len)
+ (let ((prop (get-text-property pos 'face str)))
+ (not (eq 'completions-common-part
+ (if (listp prop) (car prop) prop)))))
+ (setq pos (1+ pos)))
+ (if (< pos len)
+ (or (next-single-property-change pos 'face str) len)
+ 0)))
+
(defun ivy-completion-in-region (start end collection &optional predicate)
"An Ivy function suitable for `completion-in-region-function'."
- (let* ((str (buffer-substring-no-properties start end))
- (comps (all-completions str collection predicate)))
+ (let* ((enable-recursive-minibuffers t)
+ (str (buffer-substring-no-properties start end))
+ (comps
+ (completion-all-completions str collection predicate (- end start))))
(if (null comps)
(message "No matches")
+ (nconc comps nil)
(let* ((w (1+ (floor (log (length comps) 10))))
- (ivy-count-format (format "%%-%dd " w)))
- (setq ivy-completion-beg start)
+ (ivy-count-format (and ivy-count-format
+ (format "%%-%dd " w))))
+ (setq ivy-completion-beg (- end (ivy-completion-common-length (car
comps))))
(setq ivy-completion-end end)
(and
- (ivy-read (format "(%s): " str) comps
+ (ivy-read (format "(%s): " str)
+ ;; remove 'completions-first-difference face
+ (mapcar #'substring-no-properties comps)
:predicate predicate
:action #'ivy-completion-in-region-action
:require-match t)
- [elpa] master 89ed4d6 024/272: Improve flx highlighting, (continued)
- [elpa] master 89ed4d6 024/272: Improve flx highlighting, Oleh Krehel, 2016/04/25
- [elpa] master 09cb5c9 025/272: ivy: fix ivy--resize-minibuffer-to-fit for small delta, Oleh Krehel, 2016/04/25
- [elpa] master 6051225 020/272: Call ivy-set-actions with t to affect all commands, Oleh Krehel, 2016/04/25
- [elpa] master 12523d0 023/272: Use flx for highlighting fuzzy matches, Oleh Krehel, 2016/04/25
- [elpa] master 1cd501a 029/272: ivy.el (ivy-completion-in-region): Optimize for 1 cand, Oleh Krehel, 2016/04/25
- [elpa] master 0c844c1 030/272: ivy.el (ivy-completion-in-region): Fix for 1 cand, Oleh Krehel, 2016/04/25
- [elpa] master b5dc239 032/272: counsel.el (counsel--async-sentinel): Fix issue with ivy--regex-ignore-order, Oleh Krehel, 2016/04/25
- [elpa] master b3cd0d5 016/272: ivy.el (ivy-mode): Set completing-read-function, Oleh Krehel, 2016/04/25
- [elpa] master 89ed19e 035/272: ivy.el (ivy--regex-plus): Prettify a bit, Oleh Krehel, 2016/04/25
- [elpa] master 2135752 040/272: counsel.el (counsel--async-filter): Fix up, Oleh Krehel, 2016/04/25
- [elpa] master 426cfcb 028/272: ivy.el (ivy-completion-in-region): Fix a few bugs,
Oleh Krehel <=
- [elpa] master a526e86 041/272: Refactor swiper-font-lock-ensure, Oleh Krehel, 2016/04/25
- [elpa] master 0d410d3 047/272: ivy.el (ivy-flx-limit): Configure when flx is used, Oleh Krehel, 2016/04/25
- [elpa] master c210bf6 050/272: counsel.el (counsel-tmm): Fix tmm free variable, Oleh Krehel, 2016/04/25
- [elpa] master bcb81dd 049/272: Fix swiper "backward" search, Oleh Krehel, 2016/04/25
- [elpa] master a1e0063 018/272: ivy.el (ivy--reset-state): Don't null initial-input, Oleh Krehel, 2016/04/25
- [elpa] master fdb21f6 033/272: counsel.el (counsel--async-sentinel): Re-display when no cands, Oleh Krehel, 2016/04/25
- [elpa] master 1365b2b 031/272: Change tramp prompt from "Find File: " to "address@hidden: ", Oleh Krehel, 2016/04/25
- [elpa] master d1216eb 036/272: Add the '!' behavior into `ivy--regex-ignore-order', Oleh Krehel, 2016/04/25
- [elpa] master 66e00ed 034/272: counsel: Add counsel-up-directory to find-file-map, Oleh Krehel, 2016/04/25
- [elpa] master e23c175 039/272: Insert intermediate candidates during async completions, Oleh Krehel, 2016/04/25