From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gregory Heytings via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: A solution to display completion candidates after point in a minibuffer Date: Fri, 02 Oct 2020 21:30:15 +0000 Message-ID: References: Reply-To: Gregory Heytings Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16920"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Alpine 2.22 (NEB 394 2020-01-19) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Oct 02 23:31:17 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 1kOSe4-0004K5-S8 for ged-emacs-devel@m.gmane-mx.org; Fri, 02 Oct 2020 23:31:16 +0200 Original-Received: from localhost ([::1]:40966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kOSe3-00049J-TV for ged-emacs-devel@m.gmane-mx.org; Fri, 02 Oct 2020 17:31:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOSdH-0003Zq-JA for emacs-devel@gnu.org; Fri, 02 Oct 2020 17:30:28 -0400 Original-Received: from mx.sdf.org ([205.166.94.24]:63723) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOSdE-0004HC-DW for emacs-devel@gnu.org; Fri, 02 Oct 2020 17:30:26 -0400 Original-Received: from sdf.org (IDENT:ghe@otaku.sdf.org [205.166.94.8]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 092LUHSx026343 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Fri, 2 Oct 2020 21:30:18 GMT Original-Received: (from ghe@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 092LUSa8019883; Fri, 2 Oct 2020 21:30:28 GMT In-Reply-To: Received-SPF: pass client-ip=205.166.94.24; envelope-from=ghe@sdf.org; helo=mx.sdf.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/02 15:39:34 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-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:256974 Archived-At: Hi Stefan, Thanks again for your comments. > > Thanks. Indeed, this recipe shows a problem where the prompt is not > displayed at all right at the beginning of the interaction, so the > unwary user won't get to see what the prompt says without extra effort. > At the same time, the text that is displayed (i.e. without the prompt > but with one more line of candidates) is arguably a better choice when > the user knows what the prompt says (as would be the case for me when I > call `insert-file`). > Completion candidates are a mere help for the user, they are not essential for them to know what to do. The prompt (minibuffer-prompt) and their input are essential for them to know what to do. Why would one more completion candidate on the last line of the minibuffer be more important, from the point of view of user-friendliness, than the minibuffer prompt and their input? > > So while I would tend to agree that showing the first line would > probably be better it's debatable. At least, I don't think this minor > difference warrants the kind of code you're proposing. > It's what icomplete-vertical, ido-vertical and others try hard to do, so IMO that's a clear sign that this should not be debated. See the ongoing discussion on making Emacs popular/accessible/user-friendly/... That you or me, as experienced users, know that after hitting C-x i we are asking Emacs to insert a file does not mean that a beginner who would start Emacs in a too deep directory knows this or would be able to figure out what is happening. >>> Also this has some problematic aspects: - it focuses all its energy on >>> showing the text before point, which is often the right choice, but >>> not always. >> >> Indeed, that's not always the right choice, which is why this solution >> does this if, and only if, the buffer-local variable >> start-display-at-beginning-of-minibuffer has been set, in >> minibuffer-setup-hook. > > But it depends on other factors than "displaying the minibuffer". It can > vary over the lifetime of the very same minibuffer. > Here I admit I have no idea what you mean. AFAIU, each time the minibuffer is entered, a new "*Minibuf-N* buffer is created, so setting that variable would only have an effect on that specific minibuffer, while the user is completing a command or file name or ... in that specific minibuffer. >>> - There's of course a risk of inf-loop if (set-window-start nil (1- >>> end)) leads to (pos-visible-in-window-p end nil t) returning nil. >>> How/when could this happen, I'm not completely sure, but it doesn't >>> seem impossible. >> >> In practice it's not possible, unless the width of the Emacs frame is >> so small that setting window-start near point (at point-1) would still >> leave point invisible. > > It doesn't seem impossible even with a wide window. I think risky > situations would include cases where point is right after a newline, > and/or where tall glyphs are involved (either via face settings, or > images, ...). > If you think that's a real risk, it's easy to avoid this by enclosing the body of set-window-start-at-begin in a "(when (< (+ beg N) end)", with a suitable N; 1 or 2 should be okay. >> This I cannot do, alas, I'm not an expert. I tried this solution >> extensively, on different Emacs versions. Perhaps there are cases >> where it does not work, but I doubt it. > > I'd be uneasy using such code without some vague understanding about > *why* it works. > The code of xdisp.c is rather intricate (to say the least), but if a vague understanding is enough, I can explain what I understood. After resize_mini_window(), redisplay_window() is called, and its force_start part is executed, where run_window_scroll_functions() is called, which updates startp and therefore w->start. This gives the user the possibility (and as far as I can see it is the only possibility for the user, with Lisp functions) to update window-start between resize_mini_window() and redisplay. So set-window-start works, while other operations (such as an explicit scroll-up or scroll-down) might not. >>> I don't understand why the kind of face in use would make a difference >>> w.r.t needing to use `post-command-hook`. >> >> I don't understand it either, alas. An example, which does not work >> without start-display-at-beginning-of-minibuffer in post-command-hook >> with Emacs 26.3 (but works without it with Emacs 27.1): > > Thanks for the example. I think this highlights the need to better > understand how/why this works. > In fact I think this example demonstrates a (minor) bug in Emacs, given that the exact same code gives a different behavior with different versions of Emacs. I could only reproduce this bug with variable width faces, with which I guess that some rounding approximations happen here and there.