From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus Newsgroups: gmane.emacs.devel Subject: Propose simple package to elpa or vanilla. Date: Mon, 7 Mar 2022 20:30:17 +0100 Message-ID: <20220307193017.sokhduttloymvpya@Ergus> References: <20220307193017.sokhduttloymvpya.ref@Ergus> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="qu6muaxojzxym4cl" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18627"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Juri Linkov To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Mar 07 20:38:16 2022 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 1nRJBP-0004g7-DJ for ged-emacs-devel@m.gmane-mx.org; Mon, 07 Mar 2022 20:38:15 +0100 Original-Received: from localhost ([::1]:41536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRJBN-0007ys-Rl for ged-emacs-devel@m.gmane-mx.org; Mon, 07 Mar 2022 14:38:13 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRJ4U-0000s8-Tp for emacs-devel@gnu.org; Mon, 07 Mar 2022 14:31:08 -0500 Original-Received: from sonic317-26.consmr.mail.bf2.yahoo.com ([74.6.129.81]:46776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nRJ4Q-0008Dy-8d for emacs-devel@gnu.org; Mon, 07 Mar 2022 14:31:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1646681459; bh=tLo/Bi6RcXXkrK8G9LgKLoZ/U9Wslqh1ruclM4blvJc=; h=Date:From:To:Cc:Subject:References:From:Subject:Reply-To; b=WXH5YWbym5ei4dsQ1tuhVLmQUrO0qjWwo3ByGCBW80X+qV6qnR4M3gax0HCMf1iM6r4VbDh+Xa6R7AaaoxIKwIyVRKj5VsCR/UBtxj5vN6bbDZh1GuFQqlM8bm8Yyxirb0pJVl6muhS/oeFNZ61+L7YH47JBUNRVMXbC7uWbKDaQYJEzbAYzD+IzRU79R4CCxLN9wMal3tACZVh7yFBIt9jMu//8RizLBjT6DhiHrkZalI4J8PGfANo/fkBwYrCOCdK46YhZH5UtQaXj7qcRMDuyiI9kwVIAngRFUREkAjQM0izdMq9ZIHl8AnPDDKfDHZhWyF3YfDpy0hPjB4+3Hw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1646681459; bh=D34iHW2ZtoK3vhgSONTUjIVDdy+9VctLskO9RVOzB/w=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=BL9Nz2aSf3IC6HKHAyzAyxgvGwzX/cE3k95RT0NjHJGz7s/+YLv7PUPN4pwirwgfwqsmKJr2FBiawsFOYMbIo7U7J+apfNmfyyX6G/ryxmlZy3A3+CGetuJ2mDY3DLMsk8VebMiklW38BA4bWGON8OpCrVOaEwz7DfnbgRY5xVtW95idbTex7+JRy22gjdl/77aR7sAq4oy5KS0VXB7Lixjv1CitAZ/g2sSIbM1EzzDSNxGzE5uW+FYVRtuFQsU2H5byC+7lskSlbPobyToYcJVvqraa6dQIC5tEgQfSlg+bYCW3KuKPk/Ol3gi2498RBggrZzEgG+gxB2L5zOxFKQ== X-YMail-OSG: QLBafyYVM1nHVy0kEX08K3konyU.mvFV2cQjFGLz2Rrp4Z0c6n2poGM4pojRsEJ kXx.ko8EXuM7tckiPzAjBJpnFzRwvBqNB0VKKGb24wCmgnwtPEKSM3gzQlmL_A6giqktToIxA9Md hCe5LT.J8LpShrSFbSKAeNU5ZqBB8dWVMILiU0V1sW7AxupYM0EdrKqWnaUHBqDYv5Zsee2aeVVT 02XiY9aep1wYJ4RNVC70FewGLOWUCaEKDaVfcXbGPE.CxKJQr7Z9E9qNkWs9SybLqtQ.OnIb744q OgSWBV6UOjW5_9x3BN0B0udtIQQTXcL_7LJ.lcHx2yw9M8iivizF6SX_uBGQmmins0wP7j.Q6Imm vzScfMy4Yc2N7u14Og0bLEEhnYOvFVAedzkf.RwDRxNpoXEkmR8JS5VBMPRp1O0bWVK7BuPN8prQ q0cIsVc_sk5Xxk0BZ5EFegbQ8.EoivOErAqlbtV2iwErMuCaiOiv228i3IJUNcSibnOzqoVi6ehF F_Tuw_RGzdfroYth6Mrx3YzvZ0PKgvHEpAYVroZjqjKFK.gXDTRYbqfR7UXLI_HC3XdEW1ntFJOr oWqeSvJVKoOLPFtt9dgvTcZfHYm3uL6zPcZu0RNHILnKHI4Eunow5FUw4SxQVpw25EXhXc.7ZexB pB4pmgXwnGcFPB.qg0dcjwpM.TIijUWVOaLr81FPm4sOJz2_B2Cl4wI2Q_2E0C3buseyYWsp5FPN uzCmMOUCPAGEYHUuny1eR3lWtlE5KT0pwB7S1yZVj0df1AWUGKAcDChP7YDXtsGB0Z1rgUYEm1P9 VzUkm7Xna.x85ywZGVJA44iN2rrLtnfp1X0wNxFECx X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.bf2.yahoo.com with HTTP; Mon, 7 Mar 2022 19:30:59 +0000 Original-Received: by kubenode502.mail-prod1.omega.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 2ad4f989d472748157ae89efb37341df; Mon, 07 Mar 2022 19:30:57 +0000 (UTC) Content-Disposition: inline X-Mailer: WebService/1.1.19797 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol Received-SPF: pass client-ip=74.6.129.81; envelope-from=spacibba@aol.com; helo=sonic317-26.consmr.mail.bf2.yahoo.com 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, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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:286901 Archived-At: --qu6muaxojzxym4cl Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Hi: Some time ago I was playing with a zsh-like completion. I had 2 approaches before that got a little bit complex with no reason, so I re-thought everything and I would like to know if something like this (attached) could finally be added to vanilla. It is just 110 lines of real code and IMHO it improves the interaction with the *Completions* buffer without complexity. If you think it shouldn't be added to vanilla for whatever reason, I would be fine to add it to elpa. But maybe I will insist at least once ;) The file adds 2 different functionalities (because maybe you think that only one of them worth it.) 1) Highlight the current candidate in *Completions* (zcomplete-highlight-mode) 2) Modify the map in Completions to auto jump to the minibuffer when trying to modify it (zcomplete-mode). They are completely independent. The code is attached and as before, any suggestion is very welcome. I just want to have something like this in vanilla, even if somebody else implements something better. Best, Ergus. --qu6muaxojzxym4cl Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="zcomplete.el" ;;; zcomplete.el --- highlight and natural move throw *Completions* buffer -*- lexical-binding: t -*- ;; Copyright (C) 2020 Free Software Foundation, Inc. ;; Author: Jimmy Aguilar Mena ;; Created: Aug 2020 Jimmy Aguilar Mena spacibba@aol.com ;; Keywords: help, abbrev ;; 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: ;; This package has 2 different functionalities: ;; 1) zcomplete-mode: To auto-skip the completion buffers more often ;; 1) zcomplete-highlight-mode: To highlight current candidate ;;; Code: (require 'simple) (require 'minibuffer) ;; zcomplete-highlight-mode ========================================== (defgroup zcomplete nil "Highlight candidates in completions buffer." :version "28.1" :group 'completion) (defface zcomplete-highlight '((t :inherit highlight :extend t)) "Default face for highlighting the current line in Hl-Line mode." :version "28.1" :group 'zcomplete) (defvar zcomplete--overlay nil "Overlay to use when `zcomplete-highlight-mode' is enabled.") (defun zcomplete-highlight--pre-hook () "Highlight current candidate in *Completions* when ``zcomplete-highlight''." (when (overlayp zcomplete--overlay) (delete-overlay zcomplete--overlay))) (defun zcomplete-highlight--highlight () "Highlight current candidate if point in a candidate." (let* ((point (point)) (hpoint (or (and (get-text-property point 'mouse-face) point) (and (get-text-property (1- point) 'mouse-face) (1- point))))) (when hpoint (move-overlay zcomplete--overlay (previous-single-property-change (1+ hpoint) 'mouse-face nil (point-min)) (next-single-property-change hpoint 'mouse-face nil (point-max)))))) (defun zcomplete-highlight--setup-hook () "Function to call when enabling the `completion-highlight-mode' mode. It is called when showing the *Completions* buffer." (with-current-buffer "*Completions*" (zcomplete-highlight--highlight) (add-hook 'pre-command-hook #'zcomplete-highlight--pre-hook nil t) (add-hook 'post-command-hook #'zcomplete-highlight--highlight nil t))) ;;;###autoload (define-minor-mode zcomplete-highlight-mode "Completion highlight mode to enable candidates highlight in the minibuffer." :global t :group 'minibuffer (cond (zcomplete-highlight-mode (setq zcomplete--overlay (make-overlay 0 0)) (overlay-put zcomplete--overlay 'face 'zcomplete-highlight) (add-hook 'completion-setup-hook #'zcomplete-highlight--setup-hook t)) (t (remove-hook 'completion-setup-hook #'zcomplete-highlight--setup-hook) (delete-overlay zcomplete--overlay)))) ;; zcomplete-mode ==================================================== (defvar-keymap zcomplete-map :doc "Keymap used in *Completions* on ``zcomplete-mode''" :parent completion-list-mode-map "z" nil "n" nil "p" nil "q" nil "g" nil "h" nil "DEL" nil) (defun zcomplete--try-on-minibuffer () "Try to execute the binding on minibuffer." (switch-to-minibuffer) (if-let ((command (lookup-key (current-active-maps) (this-single-command-keys)))) (progn (minibuffer-hide-completions) (call-interactively command) t) (switch-to-completions) nil)) (defun zcomplete--pre-hook () "Try on minibuffer when the command is not in *Completions* map." (when (eq this-command 'undefined) (zcomplete--try-on-minibuffer))) (defun zcomplete--hack (data context signal) "Alternative to command-error-default-function. This will try to execute on minibuffer, else emits the error" (unless (and (string= (buffer-name) "*Completions*") (zcomplete--try-on-minibuffer)) (command-error-default-function data context signal))) (defun zcomplete--setup-hook () "Function to call when enabling the `completion-highlight-mode' mode. It is called when showing the *Completions* buffer." (with-current-buffer "*Completions*" (setq-local command-error-function #'zcomplete--hack mode-line-format nil) (use-local-map zcomplete-map) (add-hook 'pre-command-hook #'zcomplete--pre-hook nil t))) ;;;###autoload (define-minor-mode zcomplete-mode "Completion auto-jump to the minibuffer." :global t :group 'minibuffer (if zcomplete-mode (add-hook 'completion-setup-hook #'zcomplete--setup-hook t) (remove-hook 'completion-setup-hook #'zcomplete--setup-hook))) (provide 'zcomplete) ;;; zcomplete.el ends here --qu6muaxojzxym4cl--