From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: [GNU ELPA] New package proposal: aggressive-completion.el Date: Sat, 03 Apr 2021 12:03:43 +0200 Message-ID: <8735w7y98k.fsf@gnu.org> References: <87o8evok58.fsf@gnu.org> 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="36381"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.5.11; emacs 28.0.50 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Apr 03 12:05:35 2021 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 1lSd9p-0009Kv-IW for ged-emacs-devel@m.gmane-mx.org; Sat, 03 Apr 2021 12:05:33 +0200 Original-Received: from localhost ([::1]:33010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSd9o-0007L7-9s for ged-emacs-devel@m.gmane-mx.org; Sat, 03 Apr 2021 06:05:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSd94-0006v8-M4 for emacs-devel@gnu.org; Sat, 03 Apr 2021 06:04:46 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:51116) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSd94-00029e-FT for emacs-devel@gnu.org; Sat, 03 Apr 2021 06:04:46 -0400 Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:40043) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1lSd93-0002FY-Uz for emacs-devel@gnu.org; Sat, 03 Apr 2021 06:04:46 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id 86FAF27C0054 for ; Sat, 3 Apr 2021 06:04:45 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 03 Apr 2021 06:04:45 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudeikedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpehffgfhvffuffgjkfggtgesmhdtre ertdertdenucfhrhhomhepvfgrshhsihhlohcujfhorhhnuceothhsughhsehgnhhurdho rhhgqeenucggtffrrghtthgvrhhnpeevfeevhfejkeeikeeuleejveejgffhffdtffdutd evtddtueefveffvdefudfhheenucfkphepkeejrdduieefrdefuddrudehgeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhorhhnodhmvg hsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdekieejfeekjeekgedqieefhedvleek qdhtshguhheppehgnhhurdhorhhgsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Original-Received: from thinkpad-t440p (p57a31f9a.dip0.t-ipconnect.de [87.163.31.154]) by mail.messagingengine.com (Postfix) with ESMTPA id CEE04240057 for ; Sat, 3 Apr 2021 06:04:44 -0400 (EDT) In-reply-to: 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:267327 Archived-At: --=-=-= Content-Type: text/plain Jean Louis writes: Hi Jean, > I wish to try it out. I recommend that you first do: Indeed, see the attached updated version: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=aggressive-completion.el ;;; aggressive-completion.el --- Automatic minibuffer completion -*- lexical-binding: t -*- ;; Copyright (C) 2021 Free Software Foundation, Inc. ;; Author: Tassilo Horn ;; Maintainer: Tassilo Horn ;; Keywords: minibuffer completion ;; Package-Requires: ((emacs "27.1")) ;; Version: 1.0 ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; ;; Aggressive completion mode (`aggressive-completion-mode') is a minor mode ;; which automatically completes for you after a short delay ;; (`aggressive-completion-delay') and always shows all possible completions ;; using the standard completion help (unless the number of possible ;; completions exceeds `aggressive-completion-max-shown-completions'). ;; ;; Automatic completion is temporarily disabled after all commands in ;; `aggressive-completion-no-complete-commands'. Basically all deletion/kill ;; commands are listed here in order not to complete back to the thing you just ;; deleted. ;; ;; Aggressive completion can be toggled using ;; `aggressive-completion-toggle-auto-complete' (bound to `M-t' by default) ;; which is especially useful when trying to find a not yet existing file or ;; switch to a new buffer. ;; ;; You can switch from minibuffer to *Completions* buffer and back again using ;; `aggressive-completion-switch-to-completions' (bound to `M-c' by default). ;; All keys bound to this command in `aggressive-completion-minibuffer-map' ;; will be bound to `other-window' in `completion-list-mode-map' so that those ;; keys act as switch-back-and-forth commands. ;;; Code: (eval-when-compile ;; For `when-let'. (require 'subr-x)) (defgroup aggressive-completion nil "Aggressive completion completes for you." :group 'completion) (defcustom aggressive-completion-delay 0.3 "Delay in seconds before aggressive completion kicks in." :type 'number) (defcustom aggressive-completion-auto-complete t "Complete automatically if non-nil. If nil, only show the completion help." :type 'boolean) (defcustom aggressive-completion-max-shown-completions 1000 "Maximum number of possible completions for showing completion help." :type 'integer) (defcustom aggressive-completion-no-complete-commands '( left-char icomplete-fido-backward-updir minibuffer-complete right-char delete-backward-char backward-kill-word backward-kill-paragraph backward-kill-sentence backward-kill-sexp delete-char kill-word kill-line completion-at-point) "Commands after which automatic completion is not performed." :type '(repeat command)) (defvar aggressive-completion--timer nil) (defun aggressive-completion--do () "Perform aggressive completion." (when (window-minibuffer-p) (let* ((completions (completion-all-sorted-completions)) ;; Don't ding if there are no completions, etc. (visible-bell nil) (ring-bell-function #'ignore) ;; Automatic completion should not cycle. (completion-cycle-threshold nil) (completion-cycling nil)) (let ((i 0)) (while (and (<= i aggressive-completion-max-shown-completions) (consp completions)) (setq completions (cdr completions)) (cl-incf i)) (if (and (> i 0) (< i aggressive-completion-max-shown-completions)) (if (or (null aggressive-completion-auto-complete) (memq last-command aggressive-completion-no-complete-commands)) ;; This ensures we still can repeatedly hit TAB to scroll ;; through the list of completions. (unless (and (= last-command-event ?\t) (window-live-p (get-buffer-window "*Completions*")) (with-current-buffer "*Completions*" (> (point) (point-min)))) (minibuffer-completion-help)) (minibuffer-complete) (unless (window-live-p (get-buffer-window "*Completions*")) (minibuffer-completion-help))) ;; Close the *Completions* buffer if there are too many ;; or zero completions. (when-let ((win (get-buffer-window "*Completions*"))) (when (and (window-live-p win) (not (memq last-command '(minibuffer-completion-help minibuffer-complete completion-at-point)))) (quit-window nil win)))))))) (defun aggressive-completion--timer-restart () "Restart `aggressive-completion--timer'." (when aggressive-completion--timer (cancel-timer aggressive-completion--timer)) (setq aggressive-completion--timer (run-with-idle-timer aggressive-completion-delay nil #'aggressive-completion--do))) (defun aggressive-completion-toggle-auto-complete () "Toggle automatic completion." (interactive) (setq aggressive-completion-auto-complete (not aggressive-completion-auto-complete))) ;; Add an alias so that we can find out the bound key using ;; `where-is-internal'. (defalias 'aggressive-completion-switch-to-completions #'switch-to-completions) (defvar aggressive-completion-minibuffer-map (let ((map (make-sparse-keymap))) (require 'icomplete) (define-key map (kbd "DEL") #'icomplete-fido-backward-updir) (define-key map (kbd "M-t") #'aggressive-completion-toggle-auto-complete) (define-key map (kbd "M-c") #'aggressive-completion-switch-to-completions) map) "The local minibuffer keymap when `aggressive-completion-mode' is enabled.") (defun aggressive-completion--setup () "Setup aggressive completion." (when (and (not executing-kbd-macro) (window-minibuffer-p) minibuffer-completion-table) (set-keymap-parent aggressive-completion-minibuffer-map (current-local-map)) (use-local-map aggressive-completion-minibuffer-map) ;; If `aggressive-completion-switch-to-completions' is bound to keys, bind ;; the same keys in `completion-list-mode-map' to `other-window' so that ;; one can conveniently switch back and forth using the same key. (dolist (key (where-is-internal #'aggressive-completion-switch-to-completions)) (define-key completion-list-mode-map key #'other-window)) (add-hook 'post-command-hook #'aggressive-completion--timer-restart nil t))) (define-minor-mode aggressive-completion-mode "Perform aggressive minibuffer completion." :lighter " ACmp" :global t (if aggressive-completion-mode (add-hook 'minibuffer-setup-hook #'aggressive-completion--setup) (remove-hook 'minibuffer-setup-hook #'aggressive-completion--setup))) (provide 'aggressive-completion) ;;; aggressive-completion.el ends here --=-=-=--