psearch: 基于 pcase 的 elisp 代码搜索工具

这是包里带的例子,用 psearch-replace 把 nil 变成 t 成功了。

但如果反过来把 t 变成 nil,就会失败。不知道是不是我使用得不对?

(psearch-with-function-patch test-patch
  (psearch-replace '`(if nil ,body)
                   '`(if t ,body)))
;; (defun test-patch ()         =>    (defun test-patch ()
;;   (list '(1 2 3)                     (list '(1 2 3)
;;         (if nil '(4 5 6))                  (if t '(4 5 6))
;;         '(7 8 9)))                         '(7 8 9)))

测试过程:

  1. 对象函数:
(defun test-patch ()
  (list '(1 2 3)
        (if t '(4 5 6))
        '(7 8 9)))
  1. 执行替换
(psearch-replace '`(if t ,body) '`(if nil ,body))
  1. 替换结果及光标位置:

image


环境:emacs-plus@30, 昨天编译; macOS BigSur 11.6。


更新:刚找到个workaround, 用 (null t) 替换 nil 可行。