[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 8c2f213 059/272: counsel.el (counsel-yank-pop): Truncate d
From: |
Oleh Krehel |
Subject: |
[elpa] master 8c2f213 059/272: counsel.el (counsel-yank-pop): Truncate during display |
Date: |
Mon, 25 Apr 2016 10:13:16 +0000 |
branch: master
commit 8c2f213d911bb10c01a794eaaf0121ccb25d40ff
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el (counsel-yank-pop): Truncate during display
* counsel.el (counsel-yank-pop-truncate): Remove defcustom.
(counsel-yank-pop-truncate-radius): New defcustom.
(counsel--yank-pop-truncate): New defun.
(counsel--yank-pop-format-function): New defun.
During the completion, only the context around the match will be shown.
By default, the context is +2 lines above and +2 lines below the match.
It can be adjusted with `counsel-yank-pop-truncate-radius'.
Additionally, `ivy-height' is temporarily bound to 5 during completion.
This way, the maximum minibuffer height should be 1+4*5=21 lines.
Fixes #315
---
counsel.el | 61 ++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 43 insertions(+), 18 deletions(-)
diff --git a/counsel.el b/counsel.el
index 8ace5ba..75ee2c6 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1321,10 +1321,48 @@ INITIAL-INPUT can be given as the initial minibuffer
input."
(setq tmm-table-undef nil)
(counsel-tmm-prompt (tmm-get-keybind [menu-bar])))
-(defcustom counsel-yank-pop-truncate nil
+(defcustom counsel-yank-pop-truncate-radius 2
"When non-nil, truncate the display of long strings."
+ :type 'integer
:group 'ivy)
+(defun counsel--yank-pop-truncate (str)
+ (condition-case nil
+ (let* ((lines (split-string str "\n" t))
+ (n (length lines))
+ (first-match (cl-position-if
+ (lambda (s) (string-match ivy--old-re s))
+ lines))
+ (beg (max 0 (- first-match
+ counsel-yank-pop-truncate-radius)))
+ (end (min n (+ first-match
+ counsel-yank-pop-truncate-radius
+ 1)))
+ (seq (cl-subseq lines beg end)))
+ (if (null first-match)
+ (error "Could not match %s" str)
+ (when (> beg 0)
+ (setcar seq (concat "[...] " (car seq))))
+ (when (< end n)
+ (setcar (last seq)
+ (concat (car (last seq)) " [...]")))
+ (mapconcat #'identity seq "\n")))
+ (error str)))
+
+(defun counsel--yank-pop-format-function (cand-pairs)
+ (ivy--format-function-generic
+ (lambda (str _extra)
+ (mapconcat
+ (lambda (s)
+ (ivy--add-face s 'ivy-current-match))
+ (split-string
+ (counsel--yank-pop-truncate str) "\n" t)
+ "\n"))
+ (lambda (str _extra)
+ (counsel--yank-pop-truncate str))
+ cand-pairs
+ "\n"))
+
;;;###autoload
(defun counsel-yank-pop ()
"Ivy replacement for `yank-pop'."
@@ -1343,23 +1381,10 @@ INITIAL-INPUT can be given as the initial minibuffer
input."
(or (< (length s) 3)
(string-match "\\`[\n[:blank:]]+\\'" s)))
(delete-dups kill-ring))))
- (when counsel-yank-pop-truncate
- (setq candidates
- (mapcar (lambda (s)
- (if (string-match "\\`\\(.*\n.*\n.*\n.*\\)\n" s)
- (progn
- (let ((s (copy-sequence s)))
- (put-text-property
- (match-end 1)
- (length s)
- 'display
- " [...]"
- s)
- s))
- s))
- candidates)))
- (ivy-read "kill-ring: " candidates
- :action 'counsel-yank-pop-action)))
+ (let ((ivy-format-function #'counsel--yank-pop-format-function)
+ (ivy-height 5))
+ (ivy-read "kill-ring: " candidates
+ :action 'counsel-yank-pop-action))))
(defun counsel-yank-pop-action (s)
"Insert S into the buffer, overwriting the previous yank."
- [elpa] master ab3ad4e 085/272: doc/ivy.org: Add more CUSTOM_ID, (continued)
- [elpa] master ab3ad4e 085/272: doc/ivy.org: Add more CUSTOM_ID, Oleh Krehel, 2016/04/25
- [elpa] master 725e19a 170/272: counsel.el (counsel-ag-occur): Add, Oleh Krehel, 2016/04/25
- [elpa] master ccbf9ef 204/272: Improve counsel-async initial anchoring, Oleh Krehel, 2016/04/25
- [elpa] master 2fb8d86 260/272: ivy.el (ivy-done): Allow ivy-dispatching-done to exit with no cands, Oleh Krehel, 2016/04/25
- [elpa] master 1c68495 145/272: ivy.el (ivy-expand-file-if-directory): New defun, Oleh Krehel, 2016/04/25
- [elpa] master d4fc54b 110/272: ivy-test.el (counsel-unquote-regex-parens): Add test, Oleh Krehel, 2016/04/25
- [elpa] master 5f0d175 172/272: counsel.el (counsel-prompt-function-dir): Make portable, Oleh Krehel, 2016/04/25
- [elpa] master 5765208 185/272: counsel.el (counsel-pt-base-command): Add regex flag, Oleh Krehel, 2016/04/25
- [elpa] master 67ac850 211/272: counsel.el (counsel-M-x): Add help action, Oleh Krehel, 2016/04/25
- [elpa] master 189c093 207/272: counsel.el (counsel-ace-link): New command, Oleh Krehel, 2016/04/25
- [elpa] master 8c2f213 059/272: counsel.el (counsel-yank-pop): Truncate during display,
Oleh Krehel <=
- [elpa] master 5c2c1df 166/272: counsel.el (counsel-git-grep-map): Bind "C-c C-m" to counsel-git-grep-switch-cmd, Oleh Krehel, 2016/04/25
- [elpa] master e6f92fd 191/272: ivy.el (ivy-occur-press): Add counsel-describe-function, Oleh Krehel, 2016/04/25
- [elpa] master 871f78c 168/272: Add optional exit-code table to counsel--async-cmd, Oleh Krehel, 2016/04/25
- [elpa] master 668aaf3 155/272: counsel.el: add outline for `counsel-mode', Oleh Krehel, 2016/04/25
- [elpa] master 2a13932 252/272: counsel.el (counsel-grep-or-swiper): New command, Oleh Krehel, 2016/04/25
- [elpa] master 0b51e8e 231/272: ivy.el (ivy-minibuffer-map): Fix "DEL", Oleh Krehel, 2016/04/25
- [elpa] master cf78d42 212/272: counsel.el (counsel-find-file): Add :caller, Oleh Krehel, 2016/04/25
- [elpa] master a25e174 248/272: ivy.el (ivy--format-minibuffer-line): Add ignore-errors, Oleh Krehel, 2016/04/25
- [elpa] master ebd3fb9 254/272: Fix read-file-name with specified dir, Oleh Krehel, 2016/04/25
- [elpa] master 7dc86b3 084/272: Add a lot of sections to the documentation, Oleh Krehel, 2016/04/25