From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: Instead of pcase Date: Mon, 27 Nov 2023 21:46:09 -0500 Message-ID: References: <87fs169mjj.fsf@posteo.net> <093f11a1-57c2-5e56-d39b-26fef1c67cbb@gutov.dev> <25942.25061.217864.329049@retriever.mtv.corp.google.com> <87zfzdcz6z.fsf@posteo.net> <87zfza2aq2.fsf@web.de> <7nmsv9zq6u.fsf@ecube.ecubist.org> <7nv89x5tsi.fsf@ecube.ecubist.org> <87o7focuf5.fsf@web.de> <875y1r10jr.fsf@web.de> Reply-To: rms@gnu.org Content-Type: text/plain; charset=Utf-8 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32329"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: michael_heerdegen@web.de Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 28 03:46:25 2023 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 1r7o7F-0008EV-KP for ged-emacs-devel@m.gmane-mx.org; Tue, 28 Nov 2023 03:46:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7o73-0004Go-AW; Mon, 27 Nov 2023 21:46:13 -0500 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 1r7o6z-0004DC-Uc for emacs-devel@gnu.org; Mon, 27 Nov 2023 21:46:11 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7o6z-0007PD-Le; Mon, 27 Nov 2023 21:46:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=Date:References:Subject:In-Reply-To:to:From: mime-version; bh=siRjMZd2QqC5LdmpntcFawqrW4D7fYnaMQgCFRblTw0=; b=eTgFgnmQxKRs rEJ85zGr4E8aktdnE90Vv0YfWNNEKyLFk2G9lYRCDzRTqDAAuM3sl2EsK4hE1Xh+93jl0fAF2EI+e 1iWJC5Pu4sDKie77AbVRVINiEqjoVj91gd7YI9FdWpsABN/nGrTYAdnVpSt/4qY07dACXe9fIuCil COBPVcrjdJ5e6zSddNIAix98p6EvT0JcH3t7r46YN47Mq2GgWu4lDfDTEruL7V2nDNt821vpN+jyh tqYYemtyg3N0Moniwn/ipoIkFfESO6FI3WGX+1J78EyYQ0E4BuB0x7IOxt5bFv8YgOrnSgep5fG39 ceq8fCahp+X9tmuBhHg8Eg==; Original-Received: from rms by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1r7o6z-0001Hv-6s; Mon, 27 Nov 2023 21:46:09 -0500 In-Reply-To: (message from Richard Stallman on Sun, 26 Nov 2023 22:14:43 -0500) 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:313308 Archived-At: [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] (defun ffap-other-window (filename) "Like `ffap', but put buffer in another window. Only intended for interactive use." (interactive (list (ffap-prompter nil " other window"))) (pcase (save-window-excursion (find-file-at-point filename)) ((or (and (pred bufferp) b) `(,(and (pred bufferp) b) . ,_)) (switch-to-buffer-other-window b)))) I had to struggle to understand that use of pcase. Once I understood it, I found these ways to rewrite it. (cond* (:bind b1 (b (save-window-excursion (find-file-at-point filename)))) ((bufferp b) (setq b1 b)) ((bufferp (car-safe b)) (setq b1 (car-safe b)))) (if b1 (switch-to-buffer-other-window b))) (cond* (:bind b1 (b (save-window-excursion (find-file-at-point filename)))) ((bufferp b) (switch-to-buffer-other-window b)) ((bufferp (car-safe b)) (switch-to-buffer-other-window (car-safe b))))) I concluded it was essirable to give the macro `match-set' an optional third argument, which is an expression that does the job of what pcase calls a "guard". It is an ordinary Lisp expression. Also, to make `match-set' return t if it succeeded in matching. Thus I came up with this. (let ((b (save-window-excursion (find-file-at-point filename))) b1) (if (or (match-set b1 b (bufferp b1)) (match-set b1 (car-safe b) (bufferp b1))) (switch-to-buffer-other-window b1))) -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org)