unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Incorporating new things into completions
@ 2024-02-02  5:57 Psionic K
  2024-02-02  6:48 ` Emanuel Berg
  2024-02-04 10:51 ` Philip Kaludercic
  0 siblings, 2 replies; 3+ messages in thread
From: Psionic K @ 2024-02-02  5:57 UTC (permalink / raw)
  To: help-gnu-emacs

I want to augment `switch-to-buffer' candidates to contain a list of
exotic fruits.  Presumably the downstream handler for buffers has no
idea what to do with fruits, so I need to provide some alternative
handler.

Has this infrastructure been built into Emacs or is it exclusive to
completion packages at this time?   If Emacs provides facilities for
this kind of thing, what vocabulary should I become familiar with?



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Incorporating new things into completions
  2024-02-02  5:57 Incorporating new things into completions Psionic K
@ 2024-02-02  6:48 ` Emanuel Berg
  2024-02-04 10:51 ` Philip Kaludercic
  1 sibling, 0 replies; 3+ messages in thread
From: Emanuel Berg @ 2024-02-02  6:48 UTC (permalink / raw)
  To: help-gnu-emacs

Psionic K wrote:

> I want to augment `switch-to-buffer' candidates to contain
> a list of exotic fruits. Presumably the downstream handler
> for buffers has no idea what to do with fruits, so I need to
> provide some alternative handler.
>
> Has this infrastructure been built into Emacs or is it
> exclusive to completion packages at this time? If Emacs
> provides facilities for this kind of thing, what vocabulary
> should I become familiar with?

I have something to that extent, but instead of a list, it
matches a regexp. Don't know if this is already available
somewhere else but that wouldn't come as a surprise.

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/switch-to-buffer-regexp.el

(require 'cl-lib)
(require 'buc)

(defun switch-to-buffer-regexp (buf-re)
  (let*((ori-buf (buffer-name (current-buffer)))
        (hits    (cl-remove-if-not
                   (lambda (b) (string-match buf-re b)) (buffer-names)) ))
    (when hits
      (let ((new-hits (cl-remove ori-buf hits)))
        (when new-hits
          (when (string-match buf-re ori-buf)
            (bury-buffer ori-buf) )
          (switch-to-buffer (car new-hits)) )))))

;; try it!
;; (require 'gnus)
;; (dotimes (i 4) (gnus-post-news 'post "")) ; create 4 posts

(global-set-key "\C-cu" (lambda () (interactive) (switch-to-buffer-regexp "\*unsent posting\*.*")))
;; hit again to iterate

(provide 'switch-to-buffer-regexp)

Some more example use cases, some of which I use every day:

  https://dataswamp.org/~incal/emacs-init/switch-to-buffer.el

Ugh, for it to work this is needed as well from yet another file

(defun buffer-names ()
  "Get the names of all open buffers, as strings."
  (mapcar #'buffer-name (buffer-list)) )

https://dataswamp.org/~incal/emacs-init/buc.el

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Incorporating new things into completions
  2024-02-02  5:57 Incorporating new things into completions Psionic K
  2024-02-02  6:48 ` Emanuel Berg
@ 2024-02-04 10:51 ` Philip Kaludercic
  1 sibling, 0 replies; 3+ messages in thread
From: Philip Kaludercic @ 2024-02-04 10:51 UTC (permalink / raw)
  To: Psionic K; +Cc: help-gnu-emacs

Psionic K <psionik@positron.solutions> writes:

> I want to augment `switch-to-buffer' candidates to contain a list of
> exotic fruits.  Presumably the downstream handler for buffers has no
> idea what to do with fruits, so I need to provide some alternative
> handler.

Is "exotic fruits" a metaphor, or do you really mean that you want
the `read-buffer-to-switch' function to extend the completions with a
literal list of exotic fruit names?  What should `switch-to-buffer' do
in that case?

> Has this infrastructure been built into Emacs or is it exclusive to
> completion packages at this time?   If Emacs provides facilities for
> this kind of thing, what vocabulary should I become familiar with?

It would be helpful to clarify what infrastructure or functionality you
are talking about here, perhaps with an illustrative example.

-- 
Philip Kaludercic



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-04 10:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02  5:57 Incorporating new things into completions Psionic K
2024-02-02  6:48 ` Emanuel Berg
2024-02-04 10:51 ` Philip Kaludercic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).