[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Instead of pcase
|
From: |
Richard Stallman |
|
Subject: |
Re: Instead of pcase |
|
Date: |
Mon, 27 Nov 2023 21:46:09 -0500 |
[[[ 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)
- Re: Instead of pcase, (continued)
- Re: Instead of pcase, Richard Stallman, 2023/11/27
- Re: Instead of pcase, Dmitry Gutov, 2023/11/28
- Re: Instead of pcase, Richard Stallman, 2023/11/29
- Re: Instead of pcase, Michael Heerdegen, 2023/11/24
- Re: Instead of pcase, Dmitry Gutov, 2023/11/24
- Re: Instead of pcase, Richard Stallman, 2023/11/26
- Re: Instead of pcase,
Richard Stallman <=
- Re: Instead of pcase, Nikita Domnitskii, 2023/11/28
- Re: Instead of pcase, Richard Stallman, 2023/11/29
- Re: Instead of pcase, Dmitry Gutov, 2023/11/19
- Re: Instead of pcase, Richard Stallman, 2023/11/20
- Re: Instead of pcase, Jim Porter, 2023/11/21
- Re: Instead of pcase, Yuri Khan, 2023/11/21
- Re: Instead of pcase, Dmitry Gutov, 2023/11/21
- Re: Instead of pcase, Michael Heerdegen, 2023/11/21
- Re: Instead of pcase, Richard Stallman, 2023/11/22
- Re: Instead of pcase, Richard Stallman, 2023/11/23