From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: pinmacs Newsgroups: gmane.emacs.devel Subject: Re: yank-media: allow users to limit image types that can be inserted Date: Mon, 23 Sep 2024 18:08:58 -0300 Message-ID: References: <79fc91f3-c2c3-44db-9817-595808917f26@cas.cat> <86ed5ahb08.fsf@gnu.org> <87zfnywki8.fsf@gmail.com> <86setqfnmq.fsf@gnu.org> <87frpqflv4.fsf@gmail.com> <86ikumfjri.fsf@gnu.org> <877cb2fj0c.fsf@gmail.com> <86cykufhw7.fsf@gnu.org> <3a015d0f-549a-401f-be1c-651c9dbd5d9a@cas.cat> <8634lqfcaf.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37230"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rpluim@gmail.com, visuweshm@gmail.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 23 23:09:56 2024 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 1ssqJg-0009XY-Af for ged-emacs-devel@m.gmane-mx.org; Mon, 23 Sep 2024 23:09:56 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ssqIw-0004Rf-Rg; Mon, 23 Sep 2024 17:09:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ssqIt-0004RS-FQ for emacs-devel@gnu.org; Mon, 23 Sep 2024 17:09:08 -0400 Original-Received: from cas.cat ([45.150.187.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ssqIr-0003oZ-DV; Mon, 23 Sep 2024 17:09:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cas.cat; s=2023; t=1727125742; bh=MB9BM9kV5Bg0uyR8aan01I9j67Ulx0uHoOn+Soj/Q2Q=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=mU3h3abgd8H72QBhTc5FXM0c1Un+VRUUU93Xkp1fsp9/FOnk5EEESn+jQI648aylA F7fZXYJkFyV/r990DxctIc3T3asyFaJ+FGdYoTWkx4Ab0OwbvHGG9qExws3OxQmIQY XGVFsdkTI24HgUI1hqXswDGlRMuy0UamUpi882UyLE8BEDRYiCmGJvlnAI13/oMmC0 FbHV3g2fqqzHNcwvQ7wGcfR8oTrJomyKt0Ry9OuYY8kxeGyJCj0t4QATpEJOr2UXuU dsQ6//USi9mhTqR0+omRieNQFcjrRXLLtIRgw3SzQsFJil0wZ02P3C+JjDdSdFHxTL XLWa1qMF3NR+A== Content-Language: en-US In-Reply-To: <8634lqfcaf.fsf@gnu.org> Received-SPF: pass client-ip=45.150.187.15; envelope-from=pinmacs@cas.cat; helo=cas.cat 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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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.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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:324000 Archived-At: Eli, I think we can solve the three situations described with following algorithm/idea/inspiration [1]: through a configurable variable (yank-media-image-types ?). That would allow you to be able to select among all options (that for certain cases could be interesting, say "expert mode", I know what I am doing, verbose mode, etc.), and also, a way to filter out certain candidates based on what you need. Making that variable equal to nil would be as it is now, and configuring it to "image/png", would only select one. I think others were thinking about a regex. As you wish, I only need some sort of filter, and I don't care too much on the detail of how it is configured. [1] #+begin_src emacs-lisp (defun my/filter (lst allowed)   "Filter elements from LST based on ALLOWED. If no match is found, return LST."   (if (null allowed)       lst     (let ((filtered            (delq nil (mapcar                       (lambda (x)                         (when                             (member x allowed) x)) lst))))       (if (null filtered) lst filtered)))) (defun my/select (lst allowed)   (if (equal (length allowed) 1)       allowed     (completing-read      "Several types available, choose one:"      (my/filter lst allowed)))) (setq my/candidates '("image/png"                       "image/pbm"                       "image/xbm"                       "image/xpm"                       "image/jpeg"                       "image/tiff"                       "image/webp")) ;; 1. I only want png (my/select my/candidates '("image/png")) ;; 2. I only want to select between png and/or jpeg (my/select my/candidates '("image/png" "image/jpeg")) ;; 3. expert mode (just like it is now) (my/select my/candidates nil) ;; example of how you would customize the variable (setq yank-media-image-types '("image/png")) #+end_src