From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: The definition of orig-fn. Date: Tue, 05 Oct 2021 12:25:10 +0200 Message-ID: <875yub22gp.fsf@zoho.eu> References: <87czolhud6.fsf@gnu.org> <878rz9ht1m.fsf@gnu.org> <87sfxgfy19.fsf@gnu.org> <878rz8t68a.fsf@gnu.org> <874k9vud3t.fsf@gnu.org> <87v92bsup1.fsf@gnu.org> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26165"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:MvW9bjVz9Si+Hn2eIJ5WtpI4TWQ= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 05 12:26:35 2021 Return-path: Envelope-to: geh-help-gnu-emacs@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 1mXhed-0006d9-18 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 05 Oct 2021 12:26:35 +0200 Original-Received: from localhost ([::1]:42414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXhea-00056R-If for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 05 Oct 2021 06:26:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXhdS-00055y-8P for help-gnu-emacs@gnu.org; Tue, 05 Oct 2021 06:25:23 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:34466) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXhdP-0007kY-2u for help-gnu-emacs@gnu.org; Tue, 05 Oct 2021 06:25:20 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mXhdN-0004yK-FK for help-gnu-emacs@gnu.org; Tue, 05 Oct 2021 12:25:17 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133565 Archived-At: Hongyi Zhao wrote: > Without further keyboard remapping, this scheme will require > at least two keystrokes to complete a candidate insertion. > I think abo-abo's customized function is just for solving > this type of problem: One keystroke for one > candidate insertion. I don't know if/how related this is, but take a look at this [code last - yes, I see I should fix the initial comments ...] Anyway it works like this, it presents you with shortcuts to shown alternatives - the shortcuts are ?\r ?\s ?\t ... and so on. But if you don't hit a shortcut but instead hit, say, the letter "l", that letter will be inserted instead. So if you, for example, have the man page ls(1) open you will be presented with [ RET:ls ] You can then hit RET to go to the ls man page buffer. But you can also type "ls" just as you would with M-x ls RET and it doesn't require more keystrokes than that. Very clever if I may, only bummer was I could never find another use case but the man pages. A good one by all means but nonetheless ... ;;; buc.el --- move between buffers based on category -*- lexical-binding: t ;;; ;;; Author: Emanuel Berg (incal) ;;; Created: 2021-05-23 ;;; Keywords: docs, files ;;; License: GPL3+ ;;; Package-Requires: ((cl-lib "1.0")) ;;; URL: https://dataswamp.org/~incal/emacs-init/buc.el ;;; Version: 1.0.4 ;;; ;;; Commentary: ;;; ;;; This package enables you to move between similar buffers. ;;; So far I have only found one use case for it, namely ;;; accessing man pages - try `man-buc' below. ;;; ;;; The general idea behind the interface is to present ;;; alternatives based on your recent answers to the same ;;; questions. The alternatives are sorted to present you with ;;; the most relevant one first. You pick an alternative by ;;; hitting a single key. If your desired choice is not among ;;; the alternatives, start typing, that will bypass the ;;; interface and the default interface will be used as ;;; a fallback. (But technically it is not a fallback, rather ;;; the interfaces are cooperating covering different parts of ;;; one problem.) ;;; ;;; Note that If you count the number of keypresses you see ;;; the advantage with this package. When the buc interface is ;;; used, the count is much lower, since making a choice ;;; involves hitting a single key or combination. But even ;;; when it is not used, the count still is not higher than ;;; what you would use anyway, since the default interface ;;; immediately comes to life and utilizes the first keydown ;;; as its first input char. Again, try `man-buc' to see how ;;; it works first hand. ;;; ;;; Or take a look at this screenshot: ;;; ;;; https://dataswamp.org/~incal/dumps/buc.png ;;; ;;; The principle behind the interface is similar to that of ;;; a computer hardware memory cache: proximity in space and ;;; time, with updates on every single access. ;;; ;;; The interface is an hybrid between the GUI and CLI style, ;;; only the GUI "icons" are here words! Some say icons are ;;; more intuitive than words. Well, that is were we agree to ;;; disagree - perhaps that holds for infants but not to ;;; adults who have spent a HUGE part of their life reading ;;; and writing. ;;; ;;; Because we believe intuition is an acquired skill - just ;;; like everything else. ;;; ;;; Code: (require 'cl-lib) (defvar nav-keys nil "The keys used to select buffers.") (defvar nav-keys-str nil "Descriptions of the buffer-select keys.") (setq nav-keys '(?\r ?\s ?\t ?\d ?\C-j ?\C-k ?\C-l ?\C-u ?\C-o ?\C-p)) (setq nav-keys-str (split-string (key-description nav-keys))) (defun buffer-names () "Get the names of all open buffers, as strings." (mapcar #'buffer-name (buffer-list)) ) (defun extract-strings (strings match) "From STRINGS, get a list with the parts that MATCH." (remove nil (mapcar (lambda (s) (when (string-match match s) (match-string 1 s) )) strings) )) (defun get-ps (names) "Make the prompt-string, with NAMES." (let ((k -1) (s " [") ) (dolist (e names (concat s "] ")) (setq s (format "%s %s:%s " s (nth (cl-incf k) nav-keys-str) e) )))) (defun navigate-buffer-category (prefix &optional bad-key &rest args) "Display all buffers that start with PREFIX. If none of the offered buffers are chosen by the user's keystroke, evaluate (BAD-KEY ARGS)." (let ((pages (extract-strings (buffer-names) (format "%s%s" prefix "\\(.*\\)\\*") ))) (if pages (let*((ps (get-ps pages)) (key (read-key ps)) (page-index (cl-position key nav-keys)) (page (when page-index (nth page-index pages)) )) (if (= key 7) (message "quit") (if page (switch-to-buffer (format "%s%s*" prefix page)) (when bad-key (apply bad-key `(,@args ,key)) )))) (if bad-key (apply bad-key args) (error "Empty category and no fallback function") )))) (defun switch-to-type (ps fun &optional key) "Ask for a string with the prompt-string PS. Use the string as input to FUN. If KEY, it'll be the first KEY of the string, auto-inserted." (apply fun (list (read-string ps (when key (char-to-string key)) nil) ))) (defun man-buc () "Show man pages. If you start typing, you get the common prompt." (interactive) (navigate-buffer-category "*Man " #'switch-to-type "[buc] man page: " 'man) ) (provide 'buc) ;;; buc.el ends here -- underground experts united https://dataswamp.org/~incal