From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrii Kolomoiets Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Support "\n" in icomplete-separator Date: Fri, 06 Nov 2020 12:26:37 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3063"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (darwin) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 06 11:27:21 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kayxj-0000ez-U7 for ged-emacs-devel@m.gmane-mx.org; Fri, 06 Nov 2020 11:27:20 +0100 Original-Received: from localhost ([::1]:42242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kayxi-0000IB-U3 for ged-emacs-devel@m.gmane-mx.org; Fri, 06 Nov 2020 05:27:18 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kayx9-0008IS-If for emacs-devel@gnu.org; Fri, 06 Nov 2020 05:26:43 -0500 Original-Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]:41614) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kayx7-0008WC-Ol for emacs-devel@gnu.org; Fri, 06 Nov 2020 05:26:43 -0500 Original-Received: by mail-lf1-x141.google.com with SMTP id 126so1185895lfi.8 for ; Fri, 06 Nov 2020 02:26:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=mwk91ad7CUSzTqs7+PVWRuO4YHytIYL2oe5Y0hsQH6E=; b=pEHA56DREbgiRfh2m9P8h9WUbfkUgssV3GvxP9GdWZpTcz9/YDmve87VG6ud7Gd8rk ginCLXD5uRbnXaK1HUYfd+RMywKzpiKlQZE0p+CB2jE6NNUaZsuMV6hxIOlZZdx0Del1 0l9/nIOFhBsjCQiDQccb0uJShARXzHYOGXQWBSjH0f0+OFKG69IgldgTZTbp8sOeHMFT D5Tu9W6OBggh2UkcfrXwyPGVyA759YM3te5DWTUz9J2JSAnVrjOy/b0GyHNETwfngpOu YuITsNHCeYlldx4k2AT73///plIv8VhlfNAyxEjCW2/jYpeXU6dBd238zUQTbfAWUuTy FZ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=mwk91ad7CUSzTqs7+PVWRuO4YHytIYL2oe5Y0hsQH6E=; b=BfJzlNj7odHySEZNfmGrtaWuFU+RcM/WP/T48IyGncVG6qKkHNc/WbbIC3Cgvy4PI1 lcCZHDTH6J4xQJVJ+PpBpy3mw9hTk6ow+N9c4FjwfKHVlqkePvCMQC4sLGGa1V6BxjLx QryBhhIuK+MtIPI0u8jPNQJh2l7t8tUx+lie1SmhA2e50e0Ms0EkKB2EjCW6sYQXMmW2 tXHOaBYhEsWyptZ4k2UVa+mn6/vIQYyq+q60u0gc1PItuuW/6zsxhF4wFWJiYeNEb/Ls dfVOGrRLbjNEbI13qwPs+0KQBfoHTmyrpVETJk+75SLP3qkDwdtGYqFHXkaXSDy6kOUm DQsQ== X-Gm-Message-State: AOAM533ccuwMjlGgs3wGhzu4wumxzZZwR+hSy/mLo/NGgqYEJNQb9Is7 XgK6d0qFY1XZ/k3aKRb0PhUvhAICpBo= X-Google-Smtp-Source: ABdhPJybVfq7eYedrUaKd+f/xsbJnn3N1q3FKCknV+NLSd/ZLt/4ckoBWpb/z5liEHYkium8tJrfdA== X-Received: by 2002:a05:6512:3225:: with SMTP id f5mr579846lfe.441.1604658399690; Fri, 06 Nov 2020 02:26:39 -0800 (PST) Original-Received: from muffinmac ([91.206.110.192]) by smtp.gmail.com with ESMTPSA id a14sm111848lfo.116.2020.11.06.02.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 02:26:38 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Thu, 05 Nov 2020 18:29:47 -0500") Received-SPF: pass client-ip=2a00:1450:4864:20::141; envelope-from=andreyk.mad@gmail.com; helo=mail-lf1-x141.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:258795 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: >> I'm a bit late to the icomplete-vertical party, but please let me show >> you my approach at supporting "\n" in 'icomplete-separator'. > > A side-note: I think the use of "..." to indicate that there are more > entries is a bad idea. Better represent it with the absence of > a terminator (e.g. in the normal icomplete-mode, it basically means > replace "...}" with ""). It will make the code simpler, more robust, > and a side benefit is that it will make slightly more efficient use of > the screen real estate. Good point! Removed ellipsis completelly. Or it was intended to remove it only in vertical mode? --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=icomplete-vertical.diff Content-Transfer-Encoding: quoted-printable diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 4e546807b7..2fe740292c 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -687,33 +687,32 @@ icomplete-completions ;; a prefix of most, or something else. (compare (compare-strings name nil nil most nil nil completion-ignore-case)) - (ellipsis (if (char-displayable-p ?=E2=80=A6) "=E2=80=A6" "...")) (determ (unless (or (eq t compare) (eq t most-try) (=3D (setq compare (1- (abs compare))) (length most))) (concat open-bracket - (cond - ((=3D compare (length name)) + ;; Don't bother truncating if it doesn't ga= in + ;; us at least 2 columns. + (if (< compare 2) + most ;; Typical case: name is a prefix. - (substring most compare)) - ;; Don't bother truncating if it doesn't g= ain - ;; us at least 2 columns. - ((< compare (+ 2 (string-width ellipsis))) most) - (t (concat ellipsis (substring most compare)))) + (substring most compare)) close-bracket))) + (vertical (string-match "\n" icomplete-separator)) ;;"-prospects" - more than one candidate - (prospects-len (+ (string-width - (or determ (concat open-bracket close-bracket))) - (string-width icomplete-separator) - (+ 2 (string-width ellipsis)) ;; take {=E2=80=A6} into account - (string-width (buffer-string)))) + (prospects-len (unless vertical + (+ (string-width + (if determ (concat determ "{") open-bracket)) + (string-width (buffer-string))))) (prospects-max - ;; Max total length to use, including the minibuffer content. - (* (+ icomplete-prospects-height - ;; If the minibuffer content already uses up more than - ;; one line, increase the allowable space accordingly. - (/ prospects-len (window-width))) - (window-width))) + (if vertical + icomplete-prospects-height + ;; Max total length to use, including the minibuffer conte= nt. + (* (+ icomplete-prospects-height + ;; If the minibuffer content already uses up more th= an + ;; one line, increase the allowable space accordingl= y. + (/ prospects-len (window-width))) + (window-width)))) ;; Find the common prefix among `comps'. ;; We can't use the optimization below because its assumptions ;; aren't always true, e.g. when completion-cycling (bug#1085= 0): @@ -730,7 +729,9 @@ icomplete-completions ;; is already displayed via `most'. (string-prefix-p prefix most t) (length prefix))) ;;) - prospects comp limit) + (limit (when vertical + (> (length comps) prospects-max))) + prospects comp) (if (or (eq most-try t) (not (consp (cdr comps)))) (setq prospects nil) (when (member name comps) @@ -753,24 +754,38 @@ icomplete-completions ;; completion field. (setq determ (concat open-bracket "" close-bracket))) ;; Compute prospects for display. - (while (and comps (not limit)) - (setq comp - (if prefix-len (substring (car comps) prefix-len) (car comps)) - comps (cdr comps)) - (setq prospects-len - (+ (string-width comp) - (string-width icomplete-separator) - prospects-len)) - (if (< prospects-len prospects-max) - (push comp prospects) - (setq limit t)))) - (setq prospects (nreverse prospects)) - ;; Decorate first of the prospects. - (when prospects - (let ((first (copy-sequence (pop prospects)))) - (put-text-property 0 (length first) - 'face 'icomplete-first-match first) - (push first prospects))) + (if vertical + (while (and comps (> prospects-max 0)) + (setq prospects-max (1- prospects-max)) + (push (if prefix-len + (substring (pop comps) prefix-len) + (pop comps)) + prospects)) + (while (and comps (not limit)) + (setq comp (if prefix-len + (substring (pop comps) prefix-len) + (pop comps))) + (setq prospects-len + (+ (string-width comp) + prospects-len)) + ;; There be the } after last comp. Add 1 to prospects-len i= f last comp. + (if (<=3D (+ (if comps 0 1) prospects-len) prospects-max) + (push comp prospects) + (setq limit t)) + ;; Add separator if there are more comps + (when (and comps (not limit)) + (setq prospects-len + (+ (string-width icomplete-separator) + prospects-len)) + (unless (<=3D prospects-len prospects-max) + (setq limit t))))) + (when prospects + (setq prospects (nreverse prospects)) + ;; Decorate first of the prospects. + (let ((first (copy-sequence (pop prospects)))) + (put-text-property 0 (length first) + 'face 'icomplete-first-match first) + (push first prospects)))) ;; Restore the base-size info, since completion-all-sorted-complet= ions ;; is cached. (if last (setcdr last base-size)) @@ -778,8 +793,7 @@ icomplete-completions (concat determ "{" (mapconcat 'identity prospects icomplete-separator) - (and limit (concat icomplete-separator ellipsis)) - "}") + (unless limit "}")) (concat determ " [Matched]")))))) =20 ;;; Iswitchb compatibility --=-=-=--